Skip to content

Commit

Permalink
Some tweaks required to get all tests working again.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguest committed Mar 29, 2019
1 parent f4bad5f commit eacca8e
Show file tree
Hide file tree
Showing 24 changed files with 180 additions and 19,067 deletions.
12 changes: 7 additions & 5 deletions Services/OpenStreetMap.php
Expand Up @@ -98,8 +98,10 @@ public function __construct(array $configuration = [])
$transport = new Services_OpenStreetMap_Transport_HTTP();
$transport->setConfig($config);

$this->setTransport($transport);
$config->setTransport($transport);
if ($transport !== null) {
$this->setTransport($transport);
$config->setTransport($transport);
}
$config->setValue($configuration);

$version = $config->getValue('api_version');
Expand Down Expand Up @@ -240,7 +242,7 @@ public function reverseGeocode(
bool $addressdetails = true,
int $zoom = 18,
string $format = 'xml'
): string {
) {
$nominatim = new Services_OpenStreetMap_Nominatim(
$this->getTransport()
);
Expand Down Expand Up @@ -288,7 +290,7 @@ public function loadXml(string $file): void
*
* @return string
*/
public function getXml(): string
public function getXml():? string
{
return $this->xml;
}
Expand Down Expand Up @@ -556,7 +558,7 @@ public function getGpxStatus(): ?string
*/
public function setConfig(
Services_OpenStreetMap_Config $config
): Services_OpenStreetMap_API_V06 {
): Services_OpenStreetMap {
$this->config = $config;
return $this;
}
Expand Down
18 changes: 9 additions & 9 deletions Services/OpenStreetMap/API/V06.php
Expand Up @@ -85,11 +85,11 @@ public function getConfig(): Services_OpenStreetMap_Config
*
* @param Services_OpenStreetMap_Transport $transport Transport instance.
*
* @return Services_OpenStreetMap_Config
* @return Services_OpenStreetMap_API_V06
*/
public function setTransport(
Services_OpenStreetMap_Transport $transport
): Services_OpenStreetMap_Config {
): Services_OpenStreetMap_API_V06 {
$this->transport = $transport;
return $this;
}
Expand Down Expand Up @@ -457,14 +457,14 @@ public function getWays(): Services_OpenStreetMap_Objects
* @return string
* @throws Services_OpenStreetMap_Exception
*/
public function getNode(
string $nodeID,
$version = null
): Services_OpenStreetMap_Object {
public function getNode(string $nodeID, $version = null)
{
$node = $this->getTransport()->getObject('node', $nodeID, $version);
if ($node !== false) {
if ($node !== null) {
$node->setTransport($this->getTransport());
$node->setConfig($this->getConfig());
} else {
$node = false;
}
return $node;
}
Expand All @@ -487,7 +487,7 @@ public function getNode(
*
* @return Services_OpenStreetMap_Nodes
*/
public function getNodes(): Services_OpenStreetMap_Objects
public function getNodes()
{
return $this->getTransport()->getObjects(
'node',
Expand Down Expand Up @@ -531,7 +531,7 @@ public function getNotesByBbox(
if (!is_null($config)) {
$collection->setConfig($config);
}
$collection->setTransport($this);
$collection->setTransport($this->getTransport());
$collection->setXml($sxe);
return $collection;
}
Expand Down
12 changes: 6 additions & 6 deletions Services/OpenStreetMap/Changeset.php
Expand Up @@ -565,9 +565,9 @@ public function getMaxLat(): float
/**
* Get changeset Id.
*
* @return null|float value or null if none set
* @return null|double value or null if none set
*/
public function getId(): ?float
public function getId(): ?string
{
$p_id = parent::getId();
if (is_null($p_id)) {
Expand Down Expand Up @@ -607,13 +607,13 @@ public function updateObjectIds(string $body): void
/**
* Update id of some type of object.
*
* @param string $type Object type
* @param integer $old_id Old id
* @param integer $new_id New id
* @param string $type Object type
* @param string $old_id Old id
* @param string $new_id New id
*
* @return void
*/
public function updateObjectId(string $type, int $old_id, int $new_id): void
public function updateObjectId(string $type, string $old_id, string $new_id): void
{
if ($old_id == $new_id) {
return;
Expand Down
14 changes: 11 additions & 3 deletions Services/OpenStreetMap/Comment.php
Expand Up @@ -40,7 +40,11 @@ class Services_OpenStreetMap_Comment extends Services_OpenStreetMap_Object
*/
public function getAction(): string
{
return $this->obj[0]->action;
if (!is_null($this->obj[0])) {
return $this->obj[0]->action;
} else {
return '';
}
}

/**
Expand All @@ -50,7 +54,11 @@ public function getAction(): string
*/
public function getDate(): int
{
return $this->obj[0]->date;
if (!is_null($this->obj[0])) {
return $this->obj[0]->date;
} else {
return 0;
}
}

/**
Expand Down Expand Up @@ -80,7 +88,7 @@ public function getHtml(): string
*
* @return Services_OpenStreetMap_Comment
*/
public function setXml(SimpleXMLElement $xml): Services_OpenStreetMap_Comment
public function setXml(SimpleXMLElement $xml): Services_OpenStreetMap_Object
{
$this->xml = $xml->saveXml();
$obj = $xml->xpath('//' . $this->getType());
Expand Down
22 changes: 12 additions & 10 deletions Services/OpenStreetMap/Config.php
Expand Up @@ -203,7 +203,7 @@ class Services_OpenStreetMap_Config
* @throws Services_OpenStreetMap_InvalidArgumentException If the parameter
* is unknown
*/
public function getValue(string $name = null): array
public function getValue(string $name = null)
{
if (is_null($name)) {
return $this->config;
Expand Down Expand Up @@ -272,7 +272,9 @@ public function setValue($config, $value = null): Services_OpenStreetMap_Config
}
switch($key) {
case 'passwordfile':
$this->setPasswordfile($value);
if ($value !== null) {
$this->setPasswordfile($value);
}
break;
case 'api_version':
$this->config[$key] = $value;
Expand Down Expand Up @@ -393,7 +395,7 @@ private function _validateLanguageRegex(string $language): bool
* @return Services_OpenStreetMap
* @throws Services_OpenStreetMap_Exception If valid response isn't received.
*/
public function setServer(string $server): Services_OpenStreetMap
public function setServer(string $server): Services_OpenStreetMap_Config
{
try {
$c = $this->getTransport()->getResponse($server . '/api/capabilities');
Expand Down Expand Up @@ -437,15 +439,15 @@ public function setServer(string $server): Services_OpenStreetMap
*
* @param string $file file containing credentials
*
* @return Services_OpenStreetMap
* @return Services_OpenStreetMap_Config
*/
public function setPasswordfile(string $file): Services_OpenStreetMap
public function setPasswordfile(string $file): Services_OpenStreetMap_Config
{
if (is_null($file)) {
return $this;
}
$lines = @file($file);
if (!$lines) {
if ($lines === false) {
throw new Services_OpenStreetMap_Exception(
'Could not read password file'
);
Expand Down Expand Up @@ -719,7 +721,7 @@ public function getMaxElements(): int
*
* @return null|string
*/
public function getDatabaseStatus(): string
public function getDatabaseStatus():? string
{
return $this->databaseStatus;
}
Expand All @@ -729,7 +731,7 @@ public function getDatabaseStatus(): string
*
* @return null|string
*/
public function getApiStatus(): string
public function getApiStatus():? string
{
return $this->apiStatus;
}
Expand All @@ -739,7 +741,7 @@ public function getApiStatus(): string
*
* @return null|string
*/
public function getGpxStatus(): string
public function getGpxStatus():? string
{
return $this->gpxStatus;
}
Expand Down Expand Up @@ -769,7 +771,7 @@ public function getXmlValue(
string $tag,
string $attribute,
$default = null
): string {
):? string {
$obj = $xml->xpath('//' . $tag);
if (empty($obj)) {
return $default;
Expand Down
2 changes: 1 addition & 1 deletion Services/OpenStreetMap/Node.php
Expand Up @@ -126,7 +126,7 @@ public function setLon(float $value): Services_OpenStreetMap_Node
*
* @return array
*/
public function getAddress(): array
public function getAddress():? array
{
$ret = [
'addr_housename' => null,
Expand Down
3 changes: 1 addition & 2 deletions Services/OpenStreetMap/Note.php
Expand Up @@ -195,7 +195,7 @@ public function setLon(float $value): Services_OpenStreetMap_Note
*
* @return Services_OpenStreetMap_Note
*/
public function setXml(SimpleXMLElement $xml): Services_OpenStreetMap_Note
public function setXml(SimpleXMLElement $xml): Services_OpenStreetMap_Object
{
$comments = [];
$this->xml = $xml->saveXml();
Expand Down Expand Up @@ -225,7 +225,6 @@ public function setXml(SimpleXMLElement $xml): Services_OpenStreetMap_Note
$this->obj = $obj;
return $this;
}

}
// vim:set et ts=4 sw=4:
?>
29 changes: 17 additions & 12 deletions Services/OpenStreetMap/Object.php
Expand Up @@ -238,6 +238,7 @@ public function getOsmChangeXml(): string
$xml = $domd->saveXml($n->item(0));
return $this->osmChangeXml("<delete>{$xml}</delete>");
}
return '';
}

/**
Expand All @@ -249,26 +250,27 @@ public function getOsmChangeXml(): string
* @see getOsmChangeXml
* @link http://wiki.openstreetmap.org/wiki/OsmChange
*/
public function osmChangeXml(string $xml): string
public function osmChangeXml(string $xml): ?string
{
return $xml;
}

/**
* Retrieve the id of the object in question.
*
* @return integer id of the object
* @return double id of the object
*/
public function getId(): int
public function getId(): ?string
{
if (!is_null($this->id)) {
return (integer) $this->id;
return $this->id;
}

$attribs = $this->getAttributes();
if (!is_null($attribs)) {
return (integer) $attribs->id;
return $attribs->id;
}
return null;
}

/**
Expand All @@ -295,38 +297,41 @@ public function setId(string $value): Services_OpenStreetMap_Object
*
* @return integer uid of the object
*/
public function getUid(): int
public function getUid():? int
{
$attribs = $this->getAttributes();
if (!is_null($attribs)) {
return (integer) $attribs->uid;
}
return null;
}

/**
* Retrieve the user (creator/editor) of the object in question.
*
* @return string user of the object
*/
public function getUser(): string
public function getUser():? string
{
$attribs = $this->getAttributes();
if (!is_null($attribs)) {
return (string) $attribs->user;
}
return null;
}

/**
* Retrieve the version of the object in question
*
* @return integer version of the object
*/
public function getVersion(): int
public function getVersion():? int
{
$attribs = $this->getAttributes();
if (!is_null($attribs)) {
return (integer) $attribs->version;
}
return null;
}

/**
Expand Down Expand Up @@ -591,11 +596,11 @@ public function isDirty(): bool
*
* @param Services_OpenStreetMap_Config $config Config object
*
* @return Services_OpenStreetMap_Changeset
* @return Services_OpenStreetMap_Object
*/
public function setConfig(
Services_OpenStreetMap_Config $config
): Services_OpenStreetMap_Changeset {
): Services_OpenStreetMap_Object {
$this->config = $config;
return $this;
}
Expand All @@ -615,11 +620,11 @@ public function getConfig(): \Services_OpenStreetMap_Config
*
* @param Services_OpenStreetMap_Transport $transport Transport instance.
*
* @return Services_OpenStreetMap_Config
* @return Services_OpenStreetMap_Object
*/
public function setTransport(
Services_OpenStreetMap_Transport $transport
): Services_OpenStreetMap_Config {
) {
$this->transport = $transport;
return $this;
}
Expand Down

0 comments on commit eacca8e

Please sign in to comment.