Skip to content

Commit

Permalink
feat: added referee resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 21, 2024
1 parent bc38486 commit 93b053d
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 279 deletions.
36 changes: 9 additions & 27 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,17 @@ $response = $api->players()->getAllLastUpdated();
### Referees

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

#### `getAll`

```php
getAll(int $page = 1, int $perPage = 25, string $order = 'asc'): RefereeCollection
getAll(): RefereeCollection
```

Get all referees:

```php
$referees = $sportMonksFootball->referees()->getAll();

foreach ($referees->getData() as $referee) {
echo $referee->getDisplayName();
}
$response = $api->referees()->getAll();
```

#### `getById`
Expand All @@ -596,56 +591,43 @@ getById(int $id): RefereeItem
Get referee by id:

```php
$referee = $sportMonksFootball->referees()->getById(1);
echo $referee->getData()->getDisplayName();
$response = $api->referees()->getById(1);
```

#### `getAllByCountryId`

```php
getAllByCountryId(int $countryId, int $page = 1, int $perPage = 25, string $order = 'asc'): RefereeCollection
getAllByCountryId(int $countryId): RefereeCollection
```

Get all referees by country id:

```php
$referees = $sportMonksFootball->referees()->getAllByCountryId(1);

foreach ($referees->getData() as $referee) {
echo $referee->getDisplayName();
}
$response = $api->referees()->getAllByCountryId(1);
```

#### `getAllBySeasonId`

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

Get all referees by season id:

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

foreach ($referees->getData() as $referee) {
echo $referee->getDisplayName();
}
$response = $api->referees()->getAllBySeasonId(1);
```

#### `getAllBySearchQuery`

```php
getAllBySearchQuery(string $query, int $page = 1, int $perPage = 25, string $order = 'asc'): RefereeCollection
getAllBySearchQuery(string $query): RefereeCollection
```

Get all referees by search query:

```php
$referees = $sportMonksFootball->referees()->getAllBySearchQuery('name');

foreach ($referees->getData() as $referee) {
echo $referee->getDisplayName();
}
$response = $api->referees()->getAllBySearchQuery('name');
```

### Rivals
Expand Down
2 changes: 1 addition & 1 deletion docs/05-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
- `getImagePath()`: `?string`
- `getHeight()`: `?int`
- `getWeight()`: `?int`
- `getDateOfBirth()`: `?\DateTimeImmutable`
- `getBirthdate()`: `?\DateTimeImmutable`
- `getGender()`: `?string`
- `getSport()`: [`?Sport`](#sport) (`sport` include is required)
- `getCountry()`: [`?Country`](#country) (`country` include is required)
Expand Down
156 changes: 0 additions & 156 deletions src/Endpoint/RefereeEndpoint.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Entity/Referee.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Referee

private ?int $weight;

private ?\DateTimeImmutable $dateOfBirth;
private ?\DateTimeImmutable $birthdate;

private ?string $gender;

Expand Down Expand Up @@ -63,7 +63,7 @@ public function __construct(array $data, string $timezone)
$this->imagePath = $data['image_path'] ?? null;
$this->height = $data['height'] ?? null;
$this->weight = $data['weight'] ?? null;
$this->dateOfBirth = isset($data['date_of_birth']) ? new \DateTimeImmutable($data['date_of_birth']) : null;
$this->birthdate = isset($data['date_of_birth']) ? new \DateTimeImmutable($data['date_of_birth']) : null;
$this->gender = $data['gender'] ?? null;

// include
Expand Down Expand Up @@ -134,9 +134,9 @@ public function getWeight(): ?int
return $this->weight;
}

public function getDateOfBirth(): ?\DateTimeImmutable
public function getBirthdate(): ?\DateTimeImmutable
{
return $this->dateOfBirth;
return $this->birthdate;
}

public function getGender(): ?string
Expand Down
90 changes: 90 additions & 0 deletions src/Resource/RefereeResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\RefereeCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\RefereeItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use ProgrammatorDev\Validator\Exception\ValidationException;
use Psr\Http\Client\ClientExceptionInterface;

class RefereeResource extends Resource
{
use PaginationTrait;

/**
* @throws ClientExceptionInterface
*/
public function getAll(): RefereeCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/football/referees'
);

return new RefereeCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getById(int $id): RefereeItem
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/referees/{id}', [
'id' => $id
])
);

return new RefereeItem($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByCountryId(int $countryId): RefereeCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/referees/countries/{countryId}', [
'countryId' => $countryId
])
);

return new RefereeCollection($data);
}

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

return new RefereeCollection($data);
}

/**
* @throws ValidationException
* @throws ClientExceptionInterface
*/
public function getAllBySearchQuery(string $query): RefereeCollection
{
$this->validateQuery($query, 'query');

$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/referees/search/{query}', [
'query' => $query
])
);

return new RefereeCollection($data);
}
}
Loading

0 comments on commit 93b053d

Please sign in to comment.