Skip to content

Commit

Permalink
Fix ChangeSet usage re reviewRequested, gettings unit tests to pass a…
Browse files Browse the repository at this point in the history
…gain
  • Loading branch information
kenguest committed May 13, 2020
1 parent 26ea0db commit 397a509
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
14 changes: 10 additions & 4 deletions Services/OpenStreetMap/API/V06.php
Expand Up @@ -178,18 +178,24 @@ public function getChangeset(
* <code>
* $config = array('user' => 'fred@example.net', 'password' => 'wilma4eva');
* $osm = new Services_OpenStreetMap($config);
* $changeset = $osm->createChangeset();
* $changeset = $osm->createChangeset(['reviewRequested' => true]);
* </code>
*
* @param boolean $atomic atomic changeset?
* @param array $settings Changeset settings e.g. reviewRequested, message
*
* @return Services_OpenStreetMap_Changeset
* @see setConfig
*/
public function createChangeset(
bool $atomic = true
array $settings = []
): Services_OpenStreetMap_Changeset {
$changeset = new Services_OpenStreetMap_Changeset($atomic);
if (!array_key_exists('atomic', $settings)) {
$settings['atomic'] = true;
}
if (!array_key_exists('reviewRequested', $settings)) {
$settings['reviewRequested'] = false;
}
$changeset = new Services_OpenStreetMap_Changeset($settings);
$changeset->setTransport($this->getTransport());
$changeset->setConfig($this->getConfig());
return $changeset;
Expand Down
10 changes: 5 additions & 5 deletions Services/OpenStreetMap/Config.php
Expand Up @@ -352,7 +352,7 @@ public function setAcceptLanguage(
* @param string $language ISO representation of language to validate
*
* @return void
* @throws Exception If language invalid
* @throws Services_OpenStreetMap_InvalidLanguageException If language invalid
*/
private function _validateLanguage(string $language): void
{
Expand All @@ -362,12 +362,12 @@ private function _validateLanguage(string $language): void
$subparts = explode("-", $lang);
foreach ($subparts as $subpart) {
if (!$this->_validateLanguageRegex($subpart)) {
throw new Exception("Language Invalid: $language");
throw new Services_OpenStreetMap_InvalidLanguageException("Language Invalid: $language");
}
}
} else {
if (!$this->_validateLanguageRegex($lang)) {
throw new Exception("Language Invalid: $language");
throw new Services_OpenStreetMap_InvalidLanguageException("Language Invalid: $language");
}
}
}
Expand Down Expand Up @@ -543,8 +543,8 @@ private function _checkCapabilities($capabilities): bool

$this->minVersion = (float) $this->getXmlValue($xml, 'version', 'minimum');
$this->maxVersion = (float) $this->getXmlValue($xml, 'version', 'maximum');
if (($this->minVersion > $this->api_version
|| $this->api_version > $this->maxVersion)
if ($this->minVersion > $this->api_version
|| $this->api_version > $this->maxVersion
) {
throw new Services_OpenStreetMap_Exception(
'Specified API Version ' . $this->api_version . ' not supported.'
Expand Down
28 changes: 28 additions & 0 deletions Services/OpenStreetMap/InvalidLanguageException.php
@@ -0,0 +1,28 @@
<?php
/**
* Exception thrown by Services_OpenStreetMap
*
* PHP Version 7
*
* @category Services
* @package Services_OpenStreetMap
* @author Ken Guest <kguest@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version Release: @package_version@
* @link http://pear.php.net/package/Services_OpenStreetMap
*/

/**
* Exception thrown by Services_OpenStreetMap
*
* @category Services
* @package Services_OpenStreetMap
* @author Ken Guest <kguest@php.net>
* @copyright 2010-2019 Ken Guest
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version Release: @package_version@
* @link http://pear.php.net/package/Services_OpenStreetMap
*/
class Services_OpenStreetMap_InvalidLanguageException extends Services_OpenStreetMap_Exception
{
}

0 comments on commit 397a509

Please sign in to comment.