Skip to content

Commit

Permalink
Extension test fixes + StaticReforgedRunePathListExtension (#26)
Browse files Browse the repository at this point in the history
[LeagueAPI] StaticData Reforged runes changes & fixes
[LeagueAPI] Test fixes and updates (Extension & StaticData Ref.Rune)
[LeagueAPI] Removed deprecated extensions
  • Loading branch information
dolejska-daniel committed Dec 13, 2018
1 parent 205d6d7 commit eb957b2
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 161 deletions.
89 changes: 0 additions & 89 deletions src/RiotAPI/Extensions/ChampionListDtoExtension.php

This file was deleted.

73 changes: 73 additions & 0 deletions src/RiotAPI/Extensions/StaticReforgedRunePathListExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* Copyright (C) 2016-2018 Daniel Dolejška
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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];
}
}
37 changes: 37 additions & 0 deletions src/RiotAPI/Objects/StaticData/StaticReforgedRuneList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Copyright (C) 2016-2018 Daniel Dolejška
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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;
}
4 changes: 2 additions & 2 deletions src/RiotAPI/Objects/StaticData/StaticReforgedRunePathDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace RiotAPI\Objects\StaticData;

use RiotAPI\Objects\ApiObject;
use RiotAPI\Objects\ApiObjectIterable;


/**
Expand All @@ -30,7 +30,7 @@
*
* @package RiotAPI\Objects\StaticData
*/
class StaticReforgedRunePathDto extends ApiObject
class StaticReforgedRunePathDto extends ApiObjectIterable
{
/** @var StaticReforgedRuneSlotDto[] $slots */
public $slots;
Expand Down
37 changes: 37 additions & 0 deletions src/RiotAPI/Objects/StaticData/StaticReforgedRunePathList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Copyright (C) 2016-2018 Daniel Dolejška
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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;
}
4 changes: 2 additions & 2 deletions src/RiotAPI/Objects/StaticData/StaticReforgedRuneSlotDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace RiotAPI\Objects\StaticData;

use RiotAPI\Objects\ApiObject;
use RiotAPI\Objects\ApiObjectIterable;


/**
Expand All @@ -30,7 +30,7 @@
*
* @package RiotAPI\Objects\StaticData
*/
class StaticReforgedRuneSlotDto extends ApiObject
class StaticReforgedRuneSlotDto extends ApiObjectIterable
{
/** @var StaticReforgedRuneDto[] $runes */
public $runes;
Expand Down
32 changes: 10 additions & 22 deletions src/RiotAPI/RiotAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand All @@ -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
Expand All @@ -2061,7 +2055,7 @@ public function getStaticReforgedRunes( string $locale = 'en_US', string $versio
}
}
}
$result = $r;
$result = [ 'runes' => $r ];

$this->result_data = $result;
}
Expand All @@ -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);
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/RiotAPI/Endpoint/StaticDataEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
Loading

0 comments on commit eb957b2

Please sign in to comment.