diff --git a/src/RiotAPI/Extensions/ChampionListDtoExtension.php b/src/RiotAPI/Extensions/ChampionListDtoExtension.php deleted file mode 100644 index bd6aa17b..00000000 --- a/src/RiotAPI/Extensions/ChampionListDtoExtension.php +++ /dev/null @@ -1,89 +0,0 @@ -. - */ - -namespace RiotAPI\Extensions; - -use RiotAPI\Objects\ChampionDto; -use RiotAPI\Objects\ChampionListDto; -use RiotAPI\Objects\IApiObject; -use RiotAPI\Objects\IApiObjectExtension; -use RiotAPI\RiotAPI; - - -/** - * Class GeneralException - * - * @package RiotAPI\Exception - */ -class ChampionListDtoExtension implements IApiObjectExtension -{ - /** @var ChampionListDto $object */ - protected $object; - - /** - * MasteryPagesDtoExtension constructor. - * - * @param IApiObject|ChampionListDto $apiObject - * @param RiotAPI $api - */ - public function __construct( IApiObject &$apiObject, RiotAPI &$api ) - { - $this->object = $apiObject; - } - - public function getById( int $champion_id ) - { - /** @var ChampionDto $page */ - foreach ($this->object->champions as $champion) - if ($champion->id == $champion_id) - return $champion; - - return null; - } - - public function isActive( int $champion_id ) - { - /** @var ChampionDto $page */ - foreach ($this->object->champions as $champion) - if ($champion->id == $champion_id) - return $champion->active; - - return null; - } - - public function isFreeToPlay( int $champion_id ) - { - /** @var ChampionDto $page */ - foreach ($this->object->champions as $champion) - if ($champion->id == $champion_id) - return $champion->freeToPlay; - - return null; - } - - public function isRankedEnabled( int $champion_id ) - { - /** @var ChampionDto $page */ - foreach ($this->object->champions as $champion) - if ($champion->id == $champion_id) - return $champion->rankedPlayEnabled; - - return null; - } -} \ No newline at end of file diff --git a/src/RiotAPI/Extensions/StaticReforgedRunePathListExtension.php b/src/RiotAPI/Extensions/StaticReforgedRunePathListExtension.php new file mode 100644 index 00000000..4e635430 --- /dev/null +++ b/src/RiotAPI/Extensions/StaticReforgedRunePathListExtension.php @@ -0,0 +1,73 @@ +. + */ + +namespace RiotAPI\Extensions; + +use RiotAPI\Objects\IApiObject; +use RiotAPI\Objects\IApiObjectExtension; +use RiotAPI\Objects\StaticData\StaticReforgedRuneDto; +use RiotAPI\Objects\StaticData\StaticReforgedRunePathDto; +use RiotAPI\Objects\StaticData\StaticReforgedRunePathList; +use RiotAPI\Objects\StaticData\StaticReforgedRuneSlotDto; +use RiotAPI\RiotAPI; + + +/** + * Class StaticReforgedRunePathListExtension + * + * @package RiotAPI\Extensions + */ +class StaticReforgedRunePathListExtension implements IApiObjectExtension +{ + /** @var StaticReforgedRunePathList $object */ + protected $object; + + /** @var array $rune_list */ + protected $rune_list = []; + + /** + * StaticReforgedRunePathListExtension constructor. + * + * @param IApiObject|StaticReforgedRunePathList $apiObject + * @param RiotAPI $api + */ + public function __construct( IApiObject &$apiObject, RiotAPI &$api ) + { + $this->object = $apiObject; + + /** @var StaticReforgedRunePathDto $path */ + foreach ($this->object as $path) + { + /** @var StaticReforgedRuneSlotDto $slot */ + foreach ($path as $slot) + { + /** @var StaticReforgedRuneDto $rune */ + foreach ($slot as $rune) + { + $this->rune_list[$rune->id] = $rune; + } + } + } + } + + public function getRuneById( int $rune_id ) + { + return @$this->rune_list[$rune_id]; + } +} \ No newline at end of file diff --git a/src/RiotAPI/Objects/StaticData/StaticReforgedRuneList.php b/src/RiotAPI/Objects/StaticData/StaticReforgedRuneList.php new file mode 100644 index 00000000..555558ec --- /dev/null +++ b/src/RiotAPI/Objects/StaticData/StaticReforgedRuneList.php @@ -0,0 +1,37 @@ +. + */ + +namespace RiotAPI\Objects\StaticData; + +use RiotAPI\Objects\ApiObjectIterable; + + +/** + * Class StaticReforgedRuneList + * This object contains collection of all reforged runes. + * + * @iterable $runes + * + * @package RiotAPI\Objects\StaticData + */ +class StaticReforgedRuneList extends ApiObjectIterable +{ + /** @var StaticReforgedRuneDto[] $runes */ + public $runes; +} diff --git a/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathDto.php b/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathDto.php index e25b9bd0..55d18dac 100644 --- a/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathDto.php +++ b/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathDto.php @@ -19,7 +19,7 @@ namespace RiotAPI\Objects\StaticData; -use RiotAPI\Objects\ApiObject; +use RiotAPI\Objects\ApiObjectIterable; /** @@ -30,7 +30,7 @@ * * @package RiotAPI\Objects\StaticData */ -class StaticReforgedRunePathDto extends ApiObject +class StaticReforgedRunePathDto extends ApiObjectIterable { /** @var StaticReforgedRuneSlotDto[] $slots */ public $slots; diff --git a/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathList.php b/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathList.php new file mode 100644 index 00000000..0da6dc1f --- /dev/null +++ b/src/RiotAPI/Objects/StaticData/StaticReforgedRunePathList.php @@ -0,0 +1,37 @@ +. + */ + +namespace RiotAPI\Objects\StaticData; + +use RiotAPI\Objects\ApiObjectIterable; + + +/** + * Class StaticReforgedRunePathList + * This object contains collection of reforged rune paths. + * + * @iterable $paths + * + * @package RiotAPI\Objects\StaticData + */ +class StaticReforgedRunePathList extends ApiObjectIterable +{ + /** @var StaticReforgedRunePathDto[] $paths */ + public $paths; +} diff --git a/src/RiotAPI/Objects/StaticData/StaticReforgedRuneSlotDto.php b/src/RiotAPI/Objects/StaticData/StaticReforgedRuneSlotDto.php index 87ec3b05..4de4722c 100644 --- a/src/RiotAPI/Objects/StaticData/StaticReforgedRuneSlotDto.php +++ b/src/RiotAPI/Objects/StaticData/StaticReforgedRuneSlotDto.php @@ -19,7 +19,7 @@ namespace RiotAPI\Objects\StaticData; -use RiotAPI\Objects\ApiObject; +use RiotAPI\Objects\ApiObjectIterable; /** @@ -30,7 +30,7 @@ * * @package RiotAPI\Objects\StaticData */ -class StaticReforgedRuneSlotDto extends ApiObject +class StaticReforgedRuneSlotDto extends ApiObjectIterable { /** @var StaticReforgedRuneDto[] $runes */ public $runes; diff --git a/src/RiotAPI/RiotAPI.php b/src/RiotAPI/RiotAPI.php index 03fdf9f0..26f92c52 100644 --- a/src/RiotAPI/RiotAPI.php +++ b/src/RiotAPI/RiotAPI.php @@ -1986,12 +1986,12 @@ public function getStaticRealm(): StaticData\StaticRealmDto * @param string $locale * @param string|null $version * - * @return StaticData\StaticReforgedRunePathDto[] + * @return StaticData\StaticReforgedRunePathList * @throws RequestException * @throws ServerException * @throws SettingsException */ - public function getStaticReforgedRunePaths( string $locale = 'en_US', string $version = null ): array + public function getStaticReforgedRunePaths( string $locale = 'en_US', string $version = null ): StaticData\StaticReforgedRunePathList { $result = false; try @@ -2004,7 +2004,7 @@ public function getStaticReforgedRunePaths( string $locale = 'en_US', string $ve $r = []; foreach ($result as $path) $r[$path['id']] = $path; - $result = $r; + $result = [ 'paths' => $r ]; $this->result_data = $result; } @@ -2018,14 +2018,8 @@ public function getStaticReforgedRunePaths( string $locale = 'en_US', string $ve } finally { - $r = []; - foreach ($result as $item) - { - $i = new StaticData\StaticReforgedRunePathDto($item, $this); - $r[$i->id] = $i; - } - - return $r; + // Parse array and create instances + return new StaticData\StaticReforgedRunePathList($result, $this); } } @@ -2035,12 +2029,12 @@ public function getStaticReforgedRunePaths( string $locale = 'en_US', string $ve * @param string $locale * @param string|null $version * - * @return StaticData\StaticReforgedRuneDto[] + * @return StaticData\StaticReforgedRuneList * @throws RequestException * @throws ServerException * @throws SettingsException */ - public function getStaticReforgedRunes( string $locale = 'en_US', string $version = null ): array + public function getStaticReforgedRunes( string $locale = 'en_US', string $version = null ): StaticData\StaticReforgedRuneList { $result = false; try @@ -2061,7 +2055,7 @@ public function getStaticReforgedRunes( string $locale = 'en_US', string $versio } } } - $result = $r; + $result = [ 'runes' => $r ]; $this->result_data = $result; } @@ -2075,14 +2069,8 @@ public function getStaticReforgedRunes( string $locale = 'en_US', string $versio } finally { - $r = []; - foreach ($result as $item) - { - $i = new StaticData\StaticReforgedRuneDto($item, $this); - $r[$i->id] = $i; - } - - return $r; + // Parse array and create instances + return new StaticData\StaticReforgedRuneList($result, $this); } } diff --git a/tests/RiotAPI/Endpoint/StaticDataEndpointTest.php b/tests/RiotAPI/Endpoint/StaticDataEndpointTest.php index 5706eb7f..de4b9cfe 100644 --- a/tests/RiotAPI/Endpoint/StaticDataEndpointTest.php +++ b/tests/RiotAPI/Endpoint/StaticDataEndpointTest.php @@ -252,15 +252,15 @@ public function testGetStaticRealm( RiotAPI $api ) public function testGetStaticReforgedRunePaths( RiotAPI $api ) { // Get library processed results - /** @var StaticData\StaticReforgedRunePathDto[] $result */ + /** @var StaticData\StaticReforgedRunePathList $result */ $result = $api->getStaticReforgedRunePaths(); - $this->assertSameSize($api->getResult(), $result); + $this->assertSameSize($api->getResult()['paths'], $result->paths); - $this->assertArrayHasKey(8200, $result); - $this->assertSame(8200, $result[8200]->id); - $this->assertSame("Sorcery", $result[8200]->key); - $this->assertSame("Sorcery", $result[8200]->name); + $this->assertArrayHasKey(8200, $result->paths); + $this->assertSame(8200, $result->paths[8200]->id); + $this->assertSame("Sorcery", $result->paths[8200]->key); + $this->assertSame("Sorcery", $result->paths[8200]->name); } /** @@ -271,12 +271,12 @@ public function testGetStaticReforgedRunePaths( RiotAPI $api ) public function testGetStaticReforgedRunes( RiotAPI $api ) { // Get library processed results - /** @var StaticData\StaticReforgedRuneDto[] $result */ + /** @var StaticData\StaticReforgedRuneList $result */ $result = $api->getStaticReforgedRunes(); - $this->assertSame(8229, $result[8229]->id); - $this->assertSame("ArcaneComet", $result[8229]->key); - $this->assertSame("Arcane Comet", $result[8229]->name); + $this->assertSame(8229, $result->runes[8229]->id); + $this->assertSame("ArcaneComet", $result->runes[8229]->key); + $this->assertSame("Arcane Comet", $result->runes[8229]->name); } /** diff --git a/tests/RiotAPI/EndpointObjectIntegrity/StaticDataEndpointObjectIntegrityTest.php b/tests/RiotAPI/EndpointObjectIntegrity/StaticDataEndpointObjectIntegrityTest.php index 5835a781..4138ebf4 100644 --- a/tests/RiotAPI/EndpointObjectIntegrity/StaticDataEndpointObjectIntegrityTest.php +++ b/tests/RiotAPI/EndpointObjectIntegrity/StaticDataEndpointObjectIntegrityTest.php @@ -256,12 +256,12 @@ public function testGetStaticRealm( RiotAPI $api ) public function testGetStaticReforgedRunePaths( RiotAPI $api ) { // Get library processed results - /** @var StaticData\StaticReforgedRunePathDto[] $result */ + /** @var StaticData\StaticReforgedRunePathList $result */ $result = $api->getStaticReforgedRunePaths(); // Get raw result $rawResult = $api->getResult(); - $this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, StaticData\StaticReforgedRunePathDto::class); + $this->checkObjectPropertiesAndDataValidity($result, $rawResult, StaticData\StaticReforgedRunePathList::class); } /** @@ -272,12 +272,12 @@ public function testGetStaticReforgedRunePaths( RiotAPI $api ) public function testGetStaticReforgedRunes( RiotAPI $api ) { // Get library processed results - /** @var StaticData\StaticReforgedRuneDto[] $result */ + /** @var StaticData\StaticReforgedRuneList $result */ $result = $api->getStaticReforgedRunes(); // Get raw result $rawResult = $api->getResult(); - $this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, StaticData\StaticReforgedRuneDto::class); + $this->checkObjectPropertiesAndDataValidity($result, $rawResult, StaticData\StaticReforgedRuneList::class); } diff --git a/tests/RiotAPI/Library/ExtensionsTest.php b/tests/RiotAPI/Library/ExtensionsTest.php index ed9c7fac..060ad9ce 100644 --- a/tests/RiotAPI/Library/ExtensionsTest.php +++ b/tests/RiotAPI/Library/ExtensionsTest.php @@ -22,10 +22,10 @@ use PHPUnit\Framework\TestCase; use RiotAPI\Exceptions\GeneralException; -use RiotAPI\Extensions\ChampionListDtoExtension; -use RiotAPI\Objects\ChampionDto; -use RiotAPI\Objects\ChampionListDto; +use RiotAPI\Extensions\StaticReforgedRunePathListExtension; use RiotAPI\Objects\IApiObject; +use RiotAPI\Objects\StaticData\StaticReforgedRuneDto; +use RiotAPI\Objects\StaticData\StaticReforgedRunePathList; use RiotAPI\RiotAPI; use RiotAPI\Definitions\Region; @@ -43,11 +43,12 @@ class ExtensionsTest extends TestCase public function testInit() { $api = new RiotAPI([ - RiotAPI::SET_KEY => getenv('API_KEY'), - RiotAPI::SET_REGION => Region::EUROPE_EAST, - RiotAPI::SET_USE_DUMMY_DATA => true, - RiotAPI::SET_EXTENSIONS => [ - ChampionListDto::class => ChampionListDtoExtension::class, + RiotAPI::SET_KEY => getenv('API_KEY'), + RiotAPI::SET_REGION => Region::EUROPE_EAST, + RiotAPI::SET_USE_DUMMY_DATA => true, + RiotAPI::SET_DATADRAGON_INIT => true, + RiotAPI::SET_EXTENSIONS => [ + StaticReforgedRunePathList::class => StaticReforgedRunePathListExtension::class, ], ]); @@ -92,7 +93,7 @@ public function testInit_settings_invalid_ClassInterface() RiotAPI::SET_REGION => Region::EUROPE_EAST, RiotAPI::SET_USE_DUMMY_DATA => true, RiotAPI::SET_EXTENSIONS => [ - ChampionListDto::class => IApiObject::class, + StaticReforgedRunePathList::class => IApiObject::class, ], ]); } @@ -107,7 +108,7 @@ public function testInit_settings_invalid_NoninstantiableClass() RiotAPI::SET_REGION => Region::EUROPE_EAST, RiotAPI::SET_USE_DUMMY_DATA => true, RiotAPI::SET_EXTENSIONS => [ - ChampionListDto::class => NoninstantiableExtension::class, + StaticReforgedRunePathList::class => NoninstantiableExtension::class, ], ]); } @@ -122,7 +123,7 @@ public function testInit_settings_invalid_Class() RiotAPI::SET_REGION => Region::EUROPE_EAST, RiotAPI::SET_USE_DUMMY_DATA => true, RiotAPI::SET_EXTENSIONS => [ - ChampionListDto::class => "InvalidClass", + StaticReforgedRunePathList::class => "InvalidClass", ], ]); } @@ -134,21 +135,11 @@ public function testInit_settings_invalid_Class() */ public function testCallExtensionFunction_Valid( RiotAPI $api ) { - $this->markTestIncomplete("This test has not been re-implemented yet."); - - $champions = $api->getChampions(); - - $this->assertTrue($champions->isActive(61)); - $this->assertNull($champions->isActive(1347843)); + /** @var StaticReforgedRunePathListExtension $paths */ + $paths = $api->getStaticReforgedRunePaths(); - $this->assertTrue($champions->isRankedEnabled(61)); - $this->assertNull($champions->isRankedEnabled(42487643)); - - $this->assertFalse($champions->isFreeToPlay(61)); - $this->assertNull($champions->isFreeToPlay(55645198)); - - $this->assertInstanceOf(ChampionDto::class, $champions->getById(61)); - $this->assertNull($champions->getById(814684753)); + $this->assertInstanceOf(StaticReforgedRuneDto::class, $paths->getRuneById(8229)); + $this->assertNull($paths->getRuneById(814684753)); } /** @@ -158,13 +149,12 @@ public function testCallExtensionFunction_Valid( RiotAPI $api ) */ public function testCallExtensionFunction_Invalid( RiotAPI $api ) { - $this->markTestIncomplete("This test has not been re-implemented yet."); - $this->expectException(GeneralException::class); $this->expectExceptionMessage('failed to be executed'); - $masteryPages = $api->getChampions(); - $masteryPages->invalidFunction(); + /** @var StaticReforgedRunePathListExtension $paths */ + $paths = $api->getStaticReforgedRunePaths(); + $paths->invalidFunction(); } /** @@ -174,12 +164,10 @@ public function testCallExtensionFunction_Invalid( RiotAPI $api ) */ public function testCallExtensionFunction_NoExtension( RiotAPI $api ) { - $this->markTestIncomplete("This test has not been re-implemented yet."); - $this->expectException(GeneralException::class); $this->expectExceptionMessage('no extension exists for this ApiObject'); - $masteryPages = $api->getChampions(); + $masteryPages = $api->getChampionRotations(); $masteryPages->invalidFunction(); } }