Skip to content

Commit 7dcae4f

Browse files
authored
Merge pull request #41 from simivar/feature/implement-all-league-exp
Implement all League Exp v4 endpoints
2 parents c91467a + 11a2ce0 commit 7dcae4f

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

src/Riot/API.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@ public function getTournamentV4(): Version4\Tournament
145145

146146
return $this->apis['tournamentV4'];
147147
}
148+
149+
public function getLeagueExpV4(): Version4\LeagueExp
150+
{
151+
if (!isset($this->apis['leagueExpV4'])) {
152+
$this->apis['leagueExpV4'] = new Version4\LeagueExp($this->riotConnection);
153+
}
154+
155+
return $this->apis['leagueExpV4'];
156+
}
148157
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\API\Version4;
6+
7+
use Riot\API\AbstractApi;
8+
use Riot\Collection\LeagueEntryDTOCollection;
9+
use Riot\Enum\DivisionEnum;
10+
use Riot\Enum\QueueEnum;
11+
use Riot\Enum\RegionEnum;
12+
use Riot\Enum\TierExpEnum;
13+
14+
final class LeagueExp extends AbstractApi
15+
{
16+
public function getByQueueAndTierAndDivision(
17+
QueueEnum $queue,
18+
TierExpEnum $tier,
19+
DivisionEnum $division,
20+
RegionEnum $region,
21+
int $page = 1
22+
): LeagueEntryDTOCollection {
23+
$response = $this->riotConnection->get(
24+
$region->__toString(),
25+
sprintf(
26+
'lol/league/v4/entries/%s/%s/%s?page=%d',
27+
$queue->__toString(),
28+
$tier->__toString(),
29+
$division->__toString(),
30+
$page
31+
),
32+
);
33+
34+
return LeagueEntryDTOCollection::createFromArray($response->getBodyContentsDecodedAsArray());
35+
}
36+
}

src/Riot/Enum/TierExpEnum.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Riot\Enum;
6+
7+
use MyCLabs\Enum\Enum;
8+
9+
/**
10+
* @method static self CHALLENGER()
11+
* @method static self GRANDMASTER()
12+
* @method static self MASTER()
13+
* @method static self DIAMOND()
14+
* @method static self PLATINUM()
15+
* @method static self GOLD()
16+
* @method static self SILVER()
17+
* @method static self BRONZE()
18+
* @method static self IRON()
19+
*
20+
* @extends Enum<string>
21+
* @psalm-immutable
22+
*/
23+
final class TierExpEnum extends Enum
24+
{
25+
private const CHALLENGER = 'CHALLENGER';
26+
private const GRANDMASTER = 'GRANDMASTER';
27+
private const MASTER = 'MASTER';
28+
private const DIAMOND = 'DIAMOND';
29+
private const PLATINUM = 'PLATINUM';
30+
private const GOLD = 'GOLD';
31+
private const SILVER = 'SILVER';
32+
private const BRONZE = 'BRONZE';
33+
private const IRON = 'IRON';
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Riot\Unit\API\Version4;
6+
7+
use Riot\API\Version4\LeagueExp;
8+
use Riot\Collection\LeagueEntryDTOCollection;
9+
use Riot\Enum\DivisionEnum;
10+
use Riot\Enum\QueueEnum;
11+
use Riot\Enum\RegionEnum;
12+
use Riot\Enum\TierExpEnum;
13+
use Riot\Tests\APITestCase;
14+
15+
final class LeagueExpTest extends APITestCase
16+
{
17+
public function testGetByQueueAndTierAndDivisionReturnsProperObjectOnSuccess(): void
18+
{
19+
$league = new LeagueExp($this->createObjectConnectionMock(
20+
'lol/league/v4/entries/RANKED_SOLO_5x5/DIAMOND/II?page=2',
21+
[
22+
[
23+
'leagueId' => 'some-league-id',
24+
'queueType' => 'RANKED_SOLO_5x5',
25+
'tier' => 'SILVER',
26+
'rank' => 'I',
27+
'summonerId' => 'some-summoner-id',
28+
'summonerName' => 'Player One',
29+
'leaguePoints' => 5,
30+
'wins' => 34,
31+
'losses' => 35,
32+
'veteran' => false,
33+
'inactive' => false,
34+
'freshBlood' => false,
35+
'hotStreak' => false,
36+
],
37+
],
38+
'eun1',
39+
));
40+
$result = $league->getByQueueAndTierAndDivision(
41+
QueueEnum::RANKED_SOLO_5x5(),
42+
TierExpEnum::DIAMOND(),
43+
DivisionEnum::II(),
44+
RegionEnum::EUN1(),
45+
2
46+
);
47+
self::assertInstanceOf(LeagueEntryDTOCollection::class, $result);
48+
}
49+
}

0 commit comments

Comments
 (0)