Skip to content

Commit

Permalink
feat: added topscorer resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 3785a0e commit 20b7b98
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 169 deletions.
17 changes: 4 additions & 13 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1128,38 +1128,29 @@ $response = $api->teamSquads()->getAllBySeasonIdAndTeamId(1, 1);
### Topscorers

- [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/topscorers)
- Cache default max age: `1 day`

#### `getAllBySeasonId`

```php
getAllBySeasonId(int $seasonId, int $page = 1, int $perPage = 25, string $order = 'asc'): SeasonCollection
getAllBySeasonId(int $seasonId): SeasonCollection
```

Get all topscorers by season id:

```php
$topscorers = $sportMonksFootball->topscorers()->getAllBySeasonId(1);

foreach ($topscorers->getData() as $topscorer) {
echo $topscorer->getTotal();
}
$response = $api->topscorers()->getAllBySeasonId(1);
```

#### `getAllByStageId`

```php
getAllByStageId(int $stageId, int $page = 1, int $perPage = 25, string $order = 'asc'): SeasonCollection
getAllByStageId(int $stageId): SeasonCollection
```

Get all topscorers by stage id:

```php
$topscorers = $sportMonksFootball->topscorers()->getAllByStageId(1);

foreach ($topscorers->getData() as $topscorer) {
echo $topscorer->getTotal();
}
$response = $api->topscorers()->getAllByStageId(1);
```

### Transfers
Expand Down
83 changes: 0 additions & 83 deletions src/Endpoint/TopscorerEndpoint.php

This file was deleted.

42 changes: 42 additions & 0 deletions src/Resource/TopscorerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\TopscorerCollection;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use Psr\Http\Client\ClientExceptionInterface;

class TopscorerResource extends Resource
{
use PaginationTrait;

/**
* @throws ClientExceptionInterface
*/
public function getAllBySeasonId(int $seasonId): TopscorerCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/topscorers/seasons/{seasonId}', [
'seasonId' => $seasonId
])
);

return new TopscorerCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByStageId(int $stageId): TopscorerCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/topscorers/stages/{stageId}', [
'stageId' => $stageId
])
);

return new TopscorerCollection($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\TeamResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamSquadResource;
use ProgrammatorDev\SportMonksFootball\Resource\TimezoneResource;
use ProgrammatorDev\SportMonksFootball\Resource\TopscorerResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -198,11 +199,11 @@ public function timezones(): TimezoneResource
return new TimezoneResource($this);
}

// public function topscorers(): TopscorerEndpoint
// {
// return new TopscorerEndpoint($this);
// }
//
public function topscorers(): TopscorerResource
{
return new TopscorerResource($this);
}

// public function transfers(): TransferEndpoint
// {
// return new TransferEndpoint($this);
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\TeamResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamSquadResource;
use ProgrammatorDev\SportMonksFootball\Resource\TimezoneResource;
use ProgrammatorDev\SportMonksFootball\Resource\TopscorerResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand Down Expand Up @@ -60,5 +61,6 @@ public function testMethods()
$this->assertInstanceOf(TeamResource::class, $this->api->teams());
$this->assertInstanceOf(TeamSquadResource::class, $this->api->teamSquads());
$this->assertInstanceOf(TimezoneResource::class, $this->api->timezones());
$this->assertInstanceOf(TopscorerResource::class, $this->api->topscorers());
}
}
31 changes: 31 additions & 0 deletions tests/Integration/TopscorerResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

use ProgrammatorDev\SportMonksFootball\Entity\Response\TopscorerCollection;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;

class TopscorerResourceTest extends AbstractTest
{
use TestCollectionResponseTrait;

public static function provideCollectionResponseData(): \Generator
{
yield 'get all by season id' => [
TopscorerCollection::class,
MockResponse::TOPSCORER_COLLECTION_DATA,
'topscorers',
'getAllBySeasonId',
[1]
];
yield 'get all by stage id' => [
TopscorerCollection::class,
MockResponse::TOPSCORER_COLLECTION_DATA,
'topscorers',
'getAllByStageId',
[1]
];
}
}
46 changes: 0 additions & 46 deletions tests/TopscorerEndpointTest_.php

This file was deleted.

22 changes: 0 additions & 22 deletions tests/Unit/BookmakerTest.php

This file was deleted.

30 changes: 30 additions & 0 deletions tests/Unit/TopscorerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Unit;

use ProgrammatorDev\SportMonksFootball\Entity\Topscorer;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class TopscorerTest extends AbstractTest
{
public function testMethods(): void
{
$entity = new Topscorer([
'id' => 1,
'season_id' => 1,
'player_id' => 1,
'type_id' => 1,
'participant_id' => 1,
'position' => 1,
'total' => 10
], 'UTC');

$this->assertSame(1, $entity->getId());
$this->assertSame(1, $entity->getSeasonId());
$this->assertSame(1, $entity->getPlayerId());
$this->assertSame(1, $entity->getTypeId());
$this->assertSame(1, $entity->getParticipantId());
$this->assertSame(1, $entity->getPosition());
$this->assertSame(10, $entity->getTotal());
}
}

0 comments on commit 20b7b98

Please sign in to comment.