Skip to content

Commit

Permalink
Region selection verification
Browse files Browse the repository at this point in the history
  • Loading branch information
dolejska-daniel committed Feb 9, 2018
1 parent a16a6e2 commit b6f22b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
18 changes: 7 additions & 11 deletions src/RiotAPI/Definitions/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
*/
class Platform implements IPlatform
{
/****************************************d*d*
*
* Standard region platforms
*
********************************************/
// ==================================================================d=d=
// Standard regional platforms
// ==================================================================d=d=

const NORTH_AMERICA = 'na1';

Expand Down Expand Up @@ -81,11 +79,9 @@ class Platform implements IPlatform
);


/****************************************d*d*
*
* Control functions
*
********************************************/
// ==================================================================d=d=
// Control functions
// ==================================================================d=d=

public function getList(): array
{
Expand All @@ -95,7 +91,7 @@ public function getList(): array
public function getPlatformName( string $region ): string
{
if (!isset(self::$list[$region]))
throw new GeneralException('Invalid region selected. Can not find requested platform.');
throw new GeneralException('Invalid region provided. Can not find requested platform.');

return self::$list[$region];
}
Expand Down
19 changes: 8 additions & 11 deletions src/RiotAPI/Definitions/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
*/
class Region implements IRegion
{
/****************************************d*d*
*
* Standard game regions
*
********************************************/
// ==================================================================d=d=
// Standard game regions (servers)
// ==================================================================d=d=

const NORTH_AMERICA = 'na';

Expand Down Expand Up @@ -75,11 +73,9 @@ class Region implements IRegion
);


/****************************************d*d*
*
* Control functions
*
********************************************/
// ==================================================================d=d=
// Control functions
// ==================================================================d=d=

public function getList(): array
{
Expand All @@ -88,8 +84,9 @@ public function getList(): array

public function getRegionName( string $region ): string
{
$region = strtolower($region);
if (!isset(self::$list[$region]))
throw new GeneralException('Invalid region selected. Can not find requested region.');
throw new GeneralException('Invalid region provided. Can not find requested region.');

return self::$list[$region];
}
Expand Down
14 changes: 8 additions & 6 deletions src/RiotAPI/RiotAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,8 @@ public function getSetting( string $name, $defaultValue = null )
*/
public function setSetting( string $name, $value ): self
{
/*
if (in_array($name, self::SETTINGS_INIT_ONLY))
throw new SettingsException("Settings option '$name' can only be set on initialization of the library.");
*/

$this->settings[$name] = $value;
return $this;
Expand All @@ -706,6 +704,7 @@ public function setSetting( string $name, $value ): self
* @param array $values
*
* @return RiotAPI
* @throws SettingsException
*/
public function setSettings( array $values ): self
{
Expand Down Expand Up @@ -733,11 +732,11 @@ public function isSettingSet( string $name ): bool
* @param string $region
*
* @return RiotAPI
* @throws SettingsException
*/
public function setRegion( string $region ): self
{
$region = strtolower($region);
$this->setSetting(self::SET_REGION, $region);
$this->setSetting(self::SET_REGION, $this->regions->getRegionName($region));
$this->setSetting(self::SET_PLATFORM, $this->platforms->getPlatformName($region));
return $this;
}
Expand All @@ -748,12 +747,12 @@ public function setRegion( string $region ): self
* @param string $tempRegion
*
* @return RiotAPI
* @throws SettingsException
*/
public function setTemporaryRegion( string $tempRegion ): self
{
$tempRegion = strtolower($tempRegion);
$this->setSetting(self::SET_ORIG_REGION, $this->getSetting(self::SET_REGION));
$this->setSetting(self::SET_REGION, $tempRegion);
$this->setSetting(self::SET_REGION, $this->regions->getRegionName($tempRegion));
$this->setSetting(self::SET_PLATFORM, $this->platforms->getPlatformName($tempRegion));
return $this;
}
Expand All @@ -762,6 +761,7 @@ public function setTemporaryRegion( string $tempRegion ): self
* Unets temporary region and returns original region.
*
* @return RiotAPI
* @throws SettingsException
*/
public function unsetTemporaryRegion(): self
{
Expand Down Expand Up @@ -885,6 +885,8 @@ public function getResult()
* @throws RequestException
* @throws ServerException
* @throws ServerLimitException
* @throws SettingsException
*
* @internal
*/
protected function makeCall( string $overrideRegion = null, string $method = self::METHOD_GET )
Expand Down

0 comments on commit b6f22b2

Please sign in to comment.