From b6f22b2b7bb014e98d4e8844b3e460230f4a81ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Dolej=C5=A1ka?= Date: Fri, 9 Feb 2018 08:28:34 +0100 Subject: [PATCH] Region selection verification --- src/RiotAPI/Definitions/Platform.php | 18 +++++++----------- src/RiotAPI/Definitions/Region.php | 19 ++++++++----------- src/RiotAPI/RiotAPI.php | 14 ++++++++------ 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/RiotAPI/Definitions/Platform.php b/src/RiotAPI/Definitions/Platform.php index 9b00a391..c0bb69b4 100644 --- a/src/RiotAPI/Definitions/Platform.php +++ b/src/RiotAPI/Definitions/Platform.php @@ -29,11 +29,9 @@ */ class Platform implements IPlatform { - /****************************************d*d* - * - * Standard region platforms - * - ********************************************/ + // ==================================================================d=d= + // Standard regional platforms + // ==================================================================d=d= const NORTH_AMERICA = 'na1'; @@ -81,11 +79,9 @@ class Platform implements IPlatform ); - /****************************************d*d* - * - * Control functions - * - ********************************************/ + // ==================================================================d=d= + // Control functions + // ==================================================================d=d= public function getList(): array { @@ -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]; } diff --git a/src/RiotAPI/Definitions/Region.php b/src/RiotAPI/Definitions/Region.php index ed4d99c6..ec1c0c1b 100644 --- a/src/RiotAPI/Definitions/Region.php +++ b/src/RiotAPI/Definitions/Region.php @@ -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'; @@ -75,11 +73,9 @@ class Region implements IRegion ); - /****************************************d*d* - * - * Control functions - * - ********************************************/ + // ==================================================================d=d= + // Control functions + // ==================================================================d=d= public function getList(): array { @@ -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]; } diff --git a/src/RiotAPI/RiotAPI.php b/src/RiotAPI/RiotAPI.php index 69d57db0..d430c131 100644 --- a/src/RiotAPI/RiotAPI.php +++ b/src/RiotAPI/RiotAPI.php @@ -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; @@ -706,6 +704,7 @@ public function setSetting( string $name, $value ): self * @param array $values * * @return RiotAPI + * @throws SettingsException */ public function setSettings( array $values ): self { @@ -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; } @@ -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; } @@ -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 { @@ -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 )