From fe608d1f7fc00d7ddae8d25dcc8265ff0089cf08 Mon Sep 17 00:00:00 2001 From: Einar Hansen <49709354+einar-hansen@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:07:46 +0200 Subject: [PATCH 1/5] Add void return to tests --- tests/Feature/FootballDataServiceTest.php | 22 +++++++++---------- tests/Feature/Resources/AreaResourceTest.php | 6 ++--- .../Resources/CompetitionResourceTest.php | 4 ++-- tests/Feature/Resources/MatchResourceTest.php | 4 ++-- .../Feature/Resources/PersonResourceTest.php | 4 ++-- tests/Feature/Resources/TeamResourceTest.php | 6 ++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/Feature/FootballDataServiceTest.php b/tests/Feature/FootballDataServiceTest.php index 4c1a156..5912202 100644 --- a/tests/Feature/FootballDataServiceTest.php +++ b/tests/Feature/FootballDataServiceTest.php @@ -33,7 +33,7 @@ protected function setUp(): void /** * @test */ - public function it_can_build_a_new_service() + public function it_can_build_a_new_service(): void { $this->assertInstanceOf( expected: Service::class, @@ -48,7 +48,7 @@ public function it_can_build_a_new_service() /** * @test */ - public function it_can_create_requests() + public function it_can_create_requests(): void { $request = $this->service->makeRequest()->create(); $this->assertInstanceOf( @@ -60,7 +60,7 @@ public function it_can_create_requests() /** * @test */ - public function it_can_create_a_request_with_other_base_url() + public function it_can_create_a_request_with_other_base_url(): void { $service = new FootballDataService( baseUri: 'https://example.org', @@ -80,7 +80,7 @@ public function it_can_create_a_request_with_other_base_url() /** * @test */ - public function it_can_create_a_request_without_api_token() + public function it_can_create_a_request_without_api_token(): void { $service = new FootballDataService( apiToken: null, @@ -93,7 +93,7 @@ public function it_can_create_a_request_without_api_token() /** * @test */ - public function it_can_create_a_request_with_api_token() + public function it_can_create_a_request_with_api_token(): void { $service = new FootballDataService( apiToken: '::apiToken::', @@ -111,7 +111,7 @@ public function it_can_create_a_request_with_api_token() /** * @test */ - public function it_can_send_a_request_and_get_a_response() + public function it_can_send_a_request_and_get_a_response(): void { $client = new Client(); $service = new FootballDataService(client: $client); @@ -139,7 +139,7 @@ public function it_can_send_a_request_and_get_a_response() /** * @test */ - public function it_can_get_areas_resource() + public function it_can_get_areas_resource(): void { $this->assertInstanceOf( expected: AreaResource::class, @@ -150,7 +150,7 @@ public function it_can_get_areas_resource() /** * @test */ - public function it_can_get_competitions_resource() + public function it_can_get_competitions_resource(): void { $this->assertInstanceOf( expected: CompetitionResource::class, @@ -161,7 +161,7 @@ public function it_can_get_competitions_resource() /** * @test */ - public function it_can_get_matches_resource() + public function it_can_get_matches_resource(): void { $this->assertInstanceOf( expected: MatchResource::class, @@ -172,7 +172,7 @@ public function it_can_get_matches_resource() /** * @test */ - public function it_can_get_persons_resource() + public function it_can_get_persons_resource(): void { $this->assertInstanceOf( expected: PersonResource::class, @@ -183,7 +183,7 @@ public function it_can_get_persons_resource() /** * @test */ - public function it_can_get_teams_resource() + public function it_can_get_teams_resource(): void { $this->assertInstanceOf( expected: TeamResource::class, diff --git a/tests/Feature/Resources/AreaResourceTest.php b/tests/Feature/Resources/AreaResourceTest.php index 3f2a007..dedc15c 100644 --- a/tests/Feature/Resources/AreaResourceTest.php +++ b/tests/Feature/Resources/AreaResourceTest.php @@ -35,7 +35,7 @@ protected function setUp(): void /** * @test */ - public function it_can_return_the_service_instance() + public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( expected: Service::class, @@ -46,7 +46,7 @@ public function it_can_return_the_service_instance() /** * @test */ - public function it_can_return_a_collection_of_areas() + public function it_can_return_a_collection_of_areas(): void { $this->client->addResponse( response: $this->loadResponseFixture('Area/Areas.json') @@ -73,7 +73,7 @@ public function it_can_return_an_area( string $image, int $parentId, int $children, - ) { + ): void { $this->client->addResponse( response: $this->loadResponseFixture("Area/Area-{$areaId}.json") ); diff --git a/tests/Feature/Resources/CompetitionResourceTest.php b/tests/Feature/Resources/CompetitionResourceTest.php index 3f4df1d..241a01d 100644 --- a/tests/Feature/Resources/CompetitionResourceTest.php +++ b/tests/Feature/Resources/CompetitionResourceTest.php @@ -35,7 +35,7 @@ protected function setUp(): void /** * @test */ - public function it_can_return_the_service_instance() + public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( expected: Service::class, @@ -46,7 +46,7 @@ public function it_can_return_the_service_instance() /** * @test */ - public function it_can_return_a_collection_of_competitions() + public function it_can_return_a_collection_of_competitions(): void { $this->client->addResponse( response: $this->loadResponseFixture('Competition/Competitions.json') diff --git a/tests/Feature/Resources/MatchResourceTest.php b/tests/Feature/Resources/MatchResourceTest.php index 97a6133..ad0b90f 100644 --- a/tests/Feature/Resources/MatchResourceTest.php +++ b/tests/Feature/Resources/MatchResourceTest.php @@ -35,7 +35,7 @@ protected function setUp(): void /** * @test */ - public function it_can_return_the_service_instance() + public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( expected: Service::class, @@ -46,7 +46,7 @@ public function it_can_return_the_service_instance() /** * @test */ - public function it_can_return_a_collection_of_matches() + public function it_can_return_a_collection_of_matches(): void { $this->client->addResponse( response: $this->loadResponseFixture('Match/Matches.json') diff --git a/tests/Feature/Resources/PersonResourceTest.php b/tests/Feature/Resources/PersonResourceTest.php index 8f41892..b9d70d0 100644 --- a/tests/Feature/Resources/PersonResourceTest.php +++ b/tests/Feature/Resources/PersonResourceTest.php @@ -35,7 +35,7 @@ protected function setUp(): void /** * @test */ - public function it_can_return_the_service_instance() + public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( expected: Service::class, @@ -46,7 +46,7 @@ public function it_can_return_the_service_instance() /** * @test */ - public function it_can_return_a_collection_of_areas() + public function it_can_return_a_collection_of_areas(): void { $this->client->addResponse( response: $this->loadResponseFixture('Person/Person-304.json') diff --git a/tests/Feature/Resources/TeamResourceTest.php b/tests/Feature/Resources/TeamResourceTest.php index 9564ad8..937290c 100644 --- a/tests/Feature/Resources/TeamResourceTest.php +++ b/tests/Feature/Resources/TeamResourceTest.php @@ -37,7 +37,7 @@ protected function setUp(): void /** * @test */ - public function it_can_return_the_service_instance() + public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( expected: Service::class, @@ -48,7 +48,7 @@ public function it_can_return_the_service_instance() /** * @test */ - public function it_returns_a_paginated_collection_of_teams() + public function it_returns_a_paginated_collection_of_teams(): void { $this->client->addResponse( response: $this->loadResponseFixture('Team/Teams-page-1.json') @@ -67,7 +67,7 @@ public function it_returns_a_paginated_collection_of_teams() /** * @test */ - public function it_returns_all_teams_when_calling_all_collection_of_teams() + public function it_returns_all_teams_when_calling_all_collection_of_teams(): void { $this->client->addResponse( response: $this->loadResponseFixture('Team/Teams-page-1.json') From f11681631de5e2d002297a9a38391f8077be30c2 Mon Sep 17 00:00:00 2001 From: Einar Hansen <49709354+einar-hansen@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:10:28 +0200 Subject: [PATCH 2/5] Use attributes instead of docblocks in tests --- tests/Feature/FootballDataServiceTest.php | 65 +++++++------------ tests/Feature/Resources/AreaResourceTest.php | 18 ++--- .../Resources/CompetitionResourceTest.php | 9 +-- tests/Feature/Resources/MatchResourceTest.php | 9 +-- .../Feature/Resources/PersonResourceTest.php | 9 +-- tests/Feature/Resources/TeamResourceTest.php | 13 ++-- 6 files changed, 43 insertions(+), 80 deletions(-) diff --git a/tests/Feature/FootballDataServiceTest.php b/tests/Feature/FootballDataServiceTest.php index 5912202..2df2c53 100644 --- a/tests/Feature/FootballDataServiceTest.php +++ b/tests/Feature/FootballDataServiceTest.php @@ -13,6 +13,7 @@ use EinarHansen\Http\Contracts\Service\Service; use EinarHansen\Http\Message\RequestFactory; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -25,14 +26,12 @@ protected function setUp(): void { $this->service = new FootballDataService( apiToken: '::apiToken::', - baseUri: 'https://api.football-data.org', + baseUri: 'https://api.football-data.org', client: new Client() ); } - /** - * @test - */ + #[Test] public function it_can_build_a_new_service(): void { $this->assertInstanceOf( @@ -45,9 +44,7 @@ public function it_can_build_a_new_service(): void ); } - /** - * @test - */ + #[Test] public function it_can_create_requests(): void { $request = $this->service->makeRequest()->create(); @@ -57,16 +54,14 @@ public function it_can_create_requests(): void ); } - /** - * @test - */ + #[Test] public function it_can_create_a_request_with_other_base_url(): void { - $service = new FootballDataService( - baseUri: 'https://example.org', + $footballDataService = new FootballDataService( + baseUri: 'https://example.org', client: new Client() ); - $request = $service->makeRequest()->create(); + $request = $footballDataService->makeRequest()->create(); $this->assertInstanceOf( expected: RequestInterface::class, actual: $request, @@ -77,29 +72,25 @@ public function it_can_create_a_request_with_other_base_url(): void ); } - /** - * @test - */ + #[Test] public function it_can_create_a_request_without_api_token(): void { - $service = new FootballDataService( + $footballDataService = new FootballDataService( apiToken: null, client: new Client() ); - $request = $service->makeRequest()->create(); + $request = $footballDataService->makeRequest()->create(); $this->assertFalse(condition: $request->hasHeader('X-Auth-Token')); } - /** - * @test - */ + #[Test] public function it_can_create_a_request_with_api_token(): void { - $service = new FootballDataService( + $footballDataService = new FootballDataService( apiToken: '::apiToken::', client: new Client() ); - $request = $service->makeRequest()->create(); + $request = $footballDataService->makeRequest()->create(); $this->assertTrue(condition: $request->hasHeader('X-Auth-Token')); $this->assertSame( expected: '::apiToken::', @@ -108,18 +99,18 @@ public function it_can_create_a_request_with_api_token(): void } /** - /** - * @test + /** */ + #[Test] public function it_can_send_a_request_and_get_a_response(): void { $client = new Client(); - $service = new FootballDataService(client: $client); + $footballDataService = new FootballDataService(client: $client); $response = $this->createMock(ResponseInterface::class); $client->addResponse($response); - $request = $service->makeRequest()->create(); + $request = $footballDataService->makeRequest()->create(); $returnedResponse = $client->sendRequest($request); $this->assertSame( @@ -136,9 +127,7 @@ public function it_can_send_a_request_and_get_a_response(): void ); } - /** - * @test - */ + #[Test] public function it_can_get_areas_resource(): void { $this->assertInstanceOf( @@ -147,9 +136,7 @@ public function it_can_get_areas_resource(): void ); } - /** - * @test - */ + #[Test] public function it_can_get_competitions_resource(): void { $this->assertInstanceOf( @@ -158,9 +145,7 @@ public function it_can_get_competitions_resource(): void ); } - /** - * @test - */ + #[Test] public function it_can_get_matches_resource(): void { $this->assertInstanceOf( @@ -169,9 +154,7 @@ public function it_can_get_matches_resource(): void ); } - /** - * @test - */ + #[Test] public function it_can_get_persons_resource(): void { $this->assertInstanceOf( @@ -180,9 +163,7 @@ public function it_can_get_persons_resource(): void ); } - /** - * @test - */ + #[Test] public function it_can_get_teams_resource(): void { $this->assertInstanceOf( diff --git a/tests/Feature/Resources/AreaResourceTest.php b/tests/Feature/Resources/AreaResourceTest.php index dedc15c..92743f4 100644 --- a/tests/Feature/Resources/AreaResourceTest.php +++ b/tests/Feature/Resources/AreaResourceTest.php @@ -10,6 +10,8 @@ use EinarHansen\FootballData\Tests\Fixtures\HasResponseFixtures; use EinarHansen\Http\Contracts\Service\Service; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -32,9 +34,7 @@ protected function setUp(): void $this->resource = $this->service->areas(); } - /** - * @test - */ + #[Test] public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( @@ -43,9 +43,7 @@ public function it_can_return_the_service_instance(): void ); } - /** - * @test - */ + #[Test] public function it_can_return_a_collection_of_areas(): void { $this->client->addResponse( @@ -62,10 +60,8 @@ public function it_can_return_a_collection_of_areas(): void ); } - /** - * @dataProvider provideAreaData - * @test - */ + #[Test] + #[DataProvider('provideAreaData')] public function it_can_return_an_area( int $areaId, string $name, @@ -93,7 +89,7 @@ public function it_can_return_an_area( $this->assertCount($children, $data->children); } - public function provideAreaData() + public function provideAreaData(): array { return [ 'England' => [ diff --git a/tests/Feature/Resources/CompetitionResourceTest.php b/tests/Feature/Resources/CompetitionResourceTest.php index 241a01d..74309a9 100644 --- a/tests/Feature/Resources/CompetitionResourceTest.php +++ b/tests/Feature/Resources/CompetitionResourceTest.php @@ -10,6 +10,7 @@ use EinarHansen\FootballData\Tests\Fixtures\HasResponseFixtures; use EinarHansen\Http\Contracts\Service\Service; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -32,9 +33,7 @@ protected function setUp(): void $this->resource = $this->service->competitions(); } - /** - * @test - */ + #[Test] public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( @@ -43,9 +42,7 @@ public function it_can_return_the_service_instance(): void ); } - /** - * @test - */ + #[Test] public function it_can_return_a_collection_of_competitions(): void { $this->client->addResponse( diff --git a/tests/Feature/Resources/MatchResourceTest.php b/tests/Feature/Resources/MatchResourceTest.php index ad0b90f..851a350 100644 --- a/tests/Feature/Resources/MatchResourceTest.php +++ b/tests/Feature/Resources/MatchResourceTest.php @@ -10,6 +10,7 @@ use EinarHansen\FootballData\Tests\Fixtures\HasResponseFixtures; use EinarHansen\Http\Contracts\Service\Service; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -32,9 +33,7 @@ protected function setUp(): void $this->resource = $this->service->matches(); } - /** - * @test - */ + #[Test] public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( @@ -43,9 +42,7 @@ public function it_can_return_the_service_instance(): void ); } - /** - * @test - */ + #[Test] public function it_can_return_a_collection_of_matches(): void { $this->client->addResponse( diff --git a/tests/Feature/Resources/PersonResourceTest.php b/tests/Feature/Resources/PersonResourceTest.php index b9d70d0..d4c1340 100644 --- a/tests/Feature/Resources/PersonResourceTest.php +++ b/tests/Feature/Resources/PersonResourceTest.php @@ -10,6 +10,7 @@ use EinarHansen\FootballData\Tests\Fixtures\HasResponseFixtures; use EinarHansen\Http\Contracts\Service\Service; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -32,9 +33,7 @@ protected function setUp(): void $this->resource = $this->service->persons(); } - /** - * @test - */ + #[Test] public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( @@ -43,9 +42,7 @@ public function it_can_return_the_service_instance(): void ); } - /** - * @test - */ + #[Test] public function it_can_return_a_collection_of_areas(): void { $this->client->addResponse( diff --git a/tests/Feature/Resources/TeamResourceTest.php b/tests/Feature/Resources/TeamResourceTest.php index 937290c..9f706ed 100644 --- a/tests/Feature/Resources/TeamResourceTest.php +++ b/tests/Feature/Resources/TeamResourceTest.php @@ -11,6 +11,7 @@ use EinarHansen\Http\Collection\LazyCollectionFactory; use EinarHansen\Http\Contracts\Service\Service; use Http\Mock\Client; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -34,9 +35,7 @@ protected function setUp(): void $this->resource = $this->service->teams(); } - /** - * @test - */ + #[Test] public function it_can_return_the_service_instance(): void { $this->assertInstanceOf( @@ -45,9 +44,7 @@ public function it_can_return_the_service_instance(): void ); } - /** - * @test - */ + #[Test] public function it_returns_a_paginated_collection_of_teams(): void { $this->client->addResponse( @@ -64,9 +61,7 @@ public function it_returns_a_paginated_collection_of_teams(): void ); } - /** - * @test - */ + #[Test] public function it_returns_all_teams_when_calling_all_collection_of_teams(): void { $this->client->addResponse( From 052aa1f881ee33fc91beea32c282e72515d30105 Mon Sep 17 00:00:00 2001 From: Einar Hansen <49709354+einar-hansen@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:12:25 +0200 Subject: [PATCH 3/5] Run Laravel Pint on codebase --- src/Data/Area.php | 5 +- src/Data/Competition.php | 3 +- src/Data/Contract.php | 3 +- src/Data/FootballMatch.php | 7 +-- src/Data/Person.php | 7 +-- src/Data/PersonGoalScore.php | 3 +- src/Data/Score.php | 3 +- src/Data/ScoreResult.php | 3 +- src/Data/Season.php | 7 +-- src/Data/Standing.php | 7 +-- src/Data/TablePosition.php | 3 +- src/Data/Team.php | 3 +- src/Exceptions/FootballDataException.php | 4 +- src/Factories/AreaFactory.php | 12 ++-- src/Factories/CompetitionFactory.php | 30 ++++------ src/Factories/FootballMatchFactory.php | 47 +++++---------- src/Factories/PersonFactory.php | 43 +++++--------- src/Factories/PersonGoalScoreFactory.php | 16 ++--- src/Factories/ScoreFactory.php | 20 ++----- src/Factories/SeasonFactory.php | 21 +++---- src/Factories/StandingFactory.php | 19 +++--- src/Factories/TablePositionFactory.php | 28 ++++----- src/Factories/TeamFactory.php | 22 +++---- src/FootballDataService.php | 49 +++++++--------- src/Pagination/Paginator.php | 63 ++++++++++---------- src/Pagination/TeamPaginator.php | 1 + src/Resources/AreaResource.php | 8 +-- src/Resources/CompetitionResource.php | 74 ++++++++++++------------ src/Resources/MatchResource.php | 68 +++++++++++----------- src/Resources/PersonResource.php | 33 +++++------ src/Resources/Resource.php | 4 +- src/Resources/TeamResource.php | 64 ++++++++++---------- src/Traits/MapsCollections.php | 5 +- 33 files changed, 296 insertions(+), 389 deletions(-) diff --git a/src/Data/Area.php b/src/Data/Area.php index bb9fc76..2478128 100644 --- a/src/Data/Area.php +++ b/src/Data/Area.php @@ -19,8 +19,7 @@ public function __construct( public readonly ?int $parentId = null, public readonly ?string $parentName = null, public readonly array $children = [], - ) { - } + ) {} /** * {@inheritDoc} @@ -36,7 +35,7 @@ public function toArray(): array 'parentName' => $this->parentName, 'children' => array_map( array: $this->children, - callback: fn (Area $child) => $child->toArray() + callback: fn (Area $area): array => $area->toArray() ), ]; } diff --git a/src/Data/Competition.php b/src/Data/Competition.php index 65da9f7..d8e420c 100644 --- a/src/Data/Competition.php +++ b/src/Data/Competition.php @@ -19,8 +19,7 @@ public function __construct( public readonly ?int $seasonCount = null, public readonly ?Season $season = null, public readonly ?DateTimeInterface $updatedAt = null, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/Contract.php b/src/Data/Contract.php index a9f9b7d..db39064 100644 --- a/src/Data/Contract.php +++ b/src/Data/Contract.php @@ -12,8 +12,7 @@ class Contract implements Data public function __construct( public readonly ?DateTimeInterface $start = null, public readonly ?DateTimeInterface $end = null, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/FootballMatch.php b/src/Data/FootballMatch.php index 8248545..9658183 100644 --- a/src/Data/FootballMatch.php +++ b/src/Data/FootballMatch.php @@ -12,7 +12,7 @@ class FootballMatch implements Data { /** - * @param \EinarHansen\FootballData\Data\Person[] $referees + * @param Person[] $referees */ public function __construct( public readonly int $id, @@ -27,8 +27,7 @@ public function __construct( public readonly DateTimeInterface $updatedAt, public readonly ?string $group = null, public readonly array $referees = [], - ) { - } + ) {} /** * {@inheritDoc} @@ -49,7 +48,7 @@ public function toArray(): array 'group' => $this->group, 'referees' => array_map( array: $this->referees, - callback: fn (Person $person) => $person->toArray() + callback: fn (Person $person): array => $person->toArray() ), ]; } diff --git a/src/Data/Person.php b/src/Data/Person.php index cc1939b..543c8f4 100644 --- a/src/Data/Person.php +++ b/src/Data/Person.php @@ -10,7 +10,7 @@ class Person implements Data { /** - * @param \EinarHansen\FootballData\Data\Competition[] $competitions + * @param Competition[] $competitions */ public function __construct( public readonly int $id, @@ -25,8 +25,7 @@ public function __construct( public readonly ?Team $team = null, public readonly ?Contract $contract = null, public readonly array $competitions = [], - ) { - } + ) {} /** * {@inheritDoc} @@ -46,7 +45,7 @@ public function toArray(): array 'contract' => $this->contract?->toArray(), 'competitions' => array_map( array: $this->competitions, - callback: fn (Competition $competition) => $competition->toArray() + callback: fn (Competition $competition): array => $competition->toArray() ), 'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ISO8601), ]; diff --git a/src/Data/PersonGoalScore.php b/src/Data/PersonGoalScore.php index 492f69e..96bcece 100644 --- a/src/Data/PersonGoalScore.php +++ b/src/Data/PersonGoalScore.php @@ -13,8 +13,7 @@ public function __construct( public readonly int $goals = 0, public readonly int $assists = 0, public readonly int $penalties = 0, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/Score.php b/src/Data/Score.php index 98d80bf..e07415a 100644 --- a/src/Data/Score.php +++ b/src/Data/Score.php @@ -13,8 +13,7 @@ public function __construct( public readonly ScoreResult $fullTime, public readonly ScoreResult $halfTime, public readonly ?string $winner = null, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/ScoreResult.php b/src/Data/ScoreResult.php index 725c3f2..e9ad94b 100644 --- a/src/Data/ScoreResult.php +++ b/src/Data/ScoreResult.php @@ -11,8 +11,7 @@ class ScoreResult implements Data public function __construct( public readonly ?int $home = null, public readonly ?int $away = null, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/Season.php b/src/Data/Season.php index 126ce41..a9af245 100644 --- a/src/Data/Season.php +++ b/src/Data/Season.php @@ -14,9 +14,8 @@ public function __construct( public readonly DateTimeInterface $startingAt, public readonly DateTimeInterface $endingAt, public readonly int $matchDay = 0, - public readonly ?Team $winner = null, - ) { - } + public readonly ?Team $team = null, + ) {} /** * {@inheritDoc} @@ -28,7 +27,7 @@ public function toArray(): array 'startingAt' => $this->startingAt->format(format: DateTimeInterface::ISO8601), 'endingAt' => $this->endingAt->format(format: DateTimeInterface::ISO8601), 'matchDay' => $this->matchDay, - 'winner' => $this->winner?->toArray(), + 'winner' => $this->team?->toArray(), ]; } diff --git a/src/Data/Standing.php b/src/Data/Standing.php index ae3a665..fe664c0 100644 --- a/src/Data/Standing.php +++ b/src/Data/Standing.php @@ -10,15 +10,14 @@ class Standing implements Data { /** - * @param \EinarHansen\FootballData\Data\TablePosition[] $positions + * @param TablePosition[] $positions */ public function __construct( public readonly Stage $stage, public readonly string $type, public readonly ?string $group = null, public readonly array $positions = [], - ) { - } + ) {} /** * {@inheritDoc} @@ -31,7 +30,7 @@ public function toArray(): array 'group' => $this->group, 'positions' => array_map( array: $this->positions, - callback: fn (TablePosition $tablePosition) => $tablePosition->toArray() + callback: fn (TablePosition $tablePosition): array => $tablePosition->toArray() ), ]; } diff --git a/src/Data/TablePosition.php b/src/Data/TablePosition.php index ff3bfa5..4093e3c 100644 --- a/src/Data/TablePosition.php +++ b/src/Data/TablePosition.php @@ -20,8 +20,7 @@ public function __construct( public readonly int $goalsFor, public readonly int $goalsAgainst, public readonly int $goalDifference, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Data/Team.php b/src/Data/Team.php index cfacbd6..34fc595 100644 --- a/src/Data/Team.php +++ b/src/Data/Team.php @@ -21,8 +21,7 @@ public function __construct( public readonly ?string $colors = null, public readonly ?string $venue = null, public readonly ?DateTimeInterface $updatedAt = null, - ) { - } + ) {} /** * {@inheritDoc} diff --git a/src/Exceptions/FootballDataException.php b/src/Exceptions/FootballDataException.php index 51afb4c..9bb5399 100644 --- a/src/Exceptions/FootballDataException.php +++ b/src/Exceptions/FootballDataException.php @@ -6,6 +6,4 @@ use Exception; -class FootballDataException extends Exception -{ -} +class FootballDataException extends Exception {} diff --git a/src/Factories/AreaFactory.php b/src/Factories/AreaFactory.php index 75b41ed..e0a6211 100644 --- a/src/Factories/AreaFactory.php +++ b/src/Factories/AreaFactory.php @@ -15,13 +15,13 @@ public function make(array $attributes): Area $attributes = new AttributeBag($attributes); return new Area( - id: $attributes->integer(key: 'id'), - name: $attributes->string(key: 'name'), - code: $attributes->stringOrNull(key: 'countryCode') ?? $attributes->string(key: 'code'), - image: $attributes->stringOrNull(key: 'flag'), - parentId: $attributes->integerOrNull(key: 'parentAreaId'), + id: $attributes->integer(key: 'id'), + name: $attributes->string(key: 'name'), + code: $attributes->stringOrNull(key: 'countryCode') ?? $attributes->string(key: 'code'), + image: $attributes->stringOrNull(key: 'flag'), + parentId: $attributes->integerOrNull(key: 'parentAreaId'), parentName: $attributes->stringOrNull(key: 'parentArea'), - children: $attributes->map( + children: $attributes->map( key: 'childAreas', callback: fn (array $child): Area => $this->make($child) ) diff --git a/src/Factories/CompetitionFactory.php b/src/Factories/CompetitionFactory.php index 9884fc3..9182e2b 100644 --- a/src/Factories/CompetitionFactory.php +++ b/src/Factories/CompetitionFactory.php @@ -11,17 +11,7 @@ class CompetitionFactory implements DataFactory { - protected readonly AreaFactory $areaFactory; - - protected readonly SeasonFactory $seasonFactory; - - public function __construct( - ?AreaFactory $areaFactory = null, - ?SeasonFactory $seasonFactory = null, - ) { - $this->areaFactory = $areaFactory ?? new AreaFactory(); - $this->seasonFactory = $seasonFactory ?? new SeasonFactory(); - } + public function __construct(protected readonly AreaFactory $areaFactory = new AreaFactory(), protected readonly SeasonFactory $seasonFactory = new SeasonFactory()) {} public function make(array $attributes): Competition { @@ -30,19 +20,19 @@ public function make(array $attributes): Competition $season = $attributes->arrayOrNull(key: 'currentSeason') ?? $attributes->arrayOrNull(key: 'season'); return new Competition( - id: $attributes->integer(key: 'id'), - name: $attributes->string(key: 'name'), - code: $attributes->string(key: 'code'), - type: $attributes->string(key: 'type'), - image: $attributes->stringOrNull(key: 'emblem'), - area: $this->areaFactory->make( + id: $attributes->integer(key: 'id'), + name: $attributes->string(key: 'name'), + code: $attributes->string(key: 'code'), + type: $attributes->string(key: 'type'), + image: $attributes->stringOrNull(key: 'emblem'), + area: $this->areaFactory->make( attributes: $attributes->array(key: 'area') ), - seasonCount: $attributes->integer(key: 'numberOfAvailableSeasons'), - season: $season ? $this->seasonFactory->make( + seasonCount: $attributes->integer(key: 'numberOfAvailableSeasons'), + season: $season ? $this->seasonFactory->make( attributes: $season, ) : null, - updatedAt: $attributes->dateTime( + updatedAt: $attributes->dateTime( key: 'lastUpdated', format: DateTimeInterface::ISO8601 ), diff --git a/src/Factories/FootballMatchFactory.php b/src/Factories/FootballMatchFactory.php index ebb8618..8f35965 100644 --- a/src/Factories/FootballMatchFactory.php +++ b/src/Factories/FootballMatchFactory.php @@ -5,6 +5,7 @@ namespace EinarHansen\FootballData\Factories; use EinarHansen\FootballData\Data\FootballMatch; +use EinarHansen\FootballData\Data\Person; use EinarHansen\FootballData\Enums\Stage; use EinarHansen\FootballData\Enums\Status; use EinarHansen\Http\Contracts\Data\DataFactory; @@ -12,56 +13,38 @@ class FootballMatchFactory implements DataFactory { - protected readonly CompetitionFactory $competitionFactory; - - protected readonly PersonFactory $personFactory; - - protected readonly ScoreFactory $scoreFactory; - - protected readonly TeamFactory $teamFactory; - - public function __construct( - ?CompetitionFactory $competitionFactory = null, - ?PersonFactory $personFactory = null, - ?ScoreFactory $scoreFactory = null, - ?TeamFactory $teamFactory = null, - ) { - $this->competitionFactory = $competitionFactory ?? new CompetitionFactory(); - $this->personFactory = $personFactory ?? new PersonFactory(); - $this->scoreFactory = $scoreFactory ?? new ScoreFactory(); - $this->teamFactory = $teamFactory ?? new TeamFactory(); - } + public function __construct(protected readonly CompetitionFactory $competitionFactory = new CompetitionFactory(), protected readonly PersonFactory $personFactory = new PersonFactory(), protected readonly ScoreFactory $scoreFactory = new ScoreFactory(), protected readonly TeamFactory $teamFactory = new TeamFactory()) {} public function make(array $attributes): FootballMatch { $attributes = new AttributeBag($attributes); return new FootballMatch( - id: $attributes->integer(key: 'id'), - competition: $this->competitionFactory->make( + id: $attributes->integer(key: 'id'), + competition: $this->competitionFactory->make( attributes: $attributes->array(key: 'competition') + [ 'area' => $attributes->arrayOrNull(key: 'area'), 'season' => $attributes->arrayOrNull(key: 'season'), ], ), - homeTeam: $this->teamFactory->make( + homeTeam: $this->teamFactory->make( attributes: $attributes->array(key: 'homeTeam'), ), - awayTeam: $this->teamFactory->make( + awayTeam: $this->teamFactory->make( attributes: $attributes->array(key: 'awayTeam'), ), - score: $this->scoreFactory->make( + score: $this->scoreFactory->make( attributes: $attributes->array(key: 'score'), ), - matchday: $attributes->integer(key: 'matchday', default: 0), - startingAt: $attributes->dateTime(key: 'utcDate'), - status: Status::from($attributes->string(key: 'status')), - stage: Stage::from($attributes->string(key: 'stage')), - group: $attributes->stringOrNull(key: 'group'), - updatedAt: $attributes->dateTime(key: 'lastUpdated'), - referees: $attributes->map( + matchday: $attributes->integer(key: 'matchday', default: 0), + startingAt: $attributes->dateTime(key: 'utcDate'), + status: Status::from($attributes->string(key: 'status')), + stage: Stage::from($attributes->string(key: 'stage')), + group: $attributes->stringOrNull(key: 'group'), + updatedAt: $attributes->dateTime(key: 'lastUpdated'), + referees: $attributes->map( key: 'childAreas', - callback: fn (array $child) => $this->personFactory->make($child) + callback: fn (array $child): Person => $this->personFactory->make($child) ) ); } diff --git a/src/Factories/PersonFactory.php b/src/Factories/PersonFactory.php index e96d331..6fbfe80 100644 --- a/src/Factories/PersonFactory.php +++ b/src/Factories/PersonFactory.php @@ -4,27 +4,14 @@ namespace EinarHansen\FootballData\Factories; +use EinarHansen\FootballData\Data\Competition; use EinarHansen\FootballData\Data\Person; use EinarHansen\Http\Contracts\Data\DataFactory; use EinarHansen\Http\Support\AttributeBag; class PersonFactory implements DataFactory { - protected readonly CompetitionFactory $competitionFactory; - - protected readonly ContractFactory $contractFactory; - - protected readonly TeamFactory $teamFactory; - - public function __construct( - ?CompetitionFactory $competitionFactory = null, - ?ContractFactory $contractFactory = null, - ?TeamFactory $teamFactory = null, - ) { - $this->competitionFactory = $competitionFactory ?? new CompetitionFactory(); - $this->contractFactory = $contractFactory ?? new ContractFactory(); - $this->teamFactory = $teamFactory ?? new TeamFactory(); - } + public function __construct(protected readonly CompetitionFactory $competitionFactory = new CompetitionFactory(), protected readonly ContractFactory $contractFactory = new ContractFactory(), protected readonly TeamFactory $teamFactory = new TeamFactory()) {} public function make(array $attributes): Person { @@ -36,24 +23,24 @@ public function make(array $attributes): Person $competitions = $team['runningCompetitions'] ?? []; return new Person( - id: $attributes->integer(key: 'id'), - name: $attributes->string(key: 'name'), - firstName: $attributes->string(key: 'firstName'), - lastName: $attributes->string(key: 'lastName'), - dateOfBirth: $attributes->date(key: 'dateOfBirth'), - nationality: $attributes->string(key: 'nationality', default: ''), - position: $attributes->stringOrNull(key: 'position'), - shirtNumber: $attributes->integerOrNull(key: 'shirtNumber'), - updatedAt: $attributes->date(key: 'updatedAt'), - team: $team ? $this->teamFactory->make( + id: $attributes->integer(key: 'id'), + name: $attributes->string(key: 'name'), + firstName: $attributes->string(key: 'firstName'), + lastName: $attributes->string(key: 'lastName'), + dateOfBirth: $attributes->date(key: 'dateOfBirth'), + nationality: $attributes->string(key: 'nationality', default: ''), + position: $attributes->stringOrNull(key: 'position'), + shirtNumber: $attributes->integerOrNull(key: 'shirtNumber'), + updatedAt: $attributes->date(key: 'updatedAt'), + team: $team ? $this->teamFactory->make( attributes: $team ) : null, - contract: $contract ? $this->contractFactory->make( + contract: $contract ? $this->contractFactory->make( attributes: $contract ) : null, - competitions: array_map( + competitions: array_map( array: $competitions, - callback: fn ($attributes) => $this->competitionFactory->make( + callback: fn ($attributes): Competition => $this->competitionFactory->make( attributes: $attributes + ['area' => $area] ), ), diff --git a/src/Factories/PersonGoalScoreFactory.php b/src/Factories/PersonGoalScoreFactory.php index 48f41b4..bc6419f 100644 --- a/src/Factories/PersonGoalScoreFactory.php +++ b/src/Factories/PersonGoalScoreFactory.php @@ -10,27 +10,21 @@ class PersonGoalScoreFactory implements DataFactory { - protected readonly PersonFactory $personFactory; - - public function __construct( - ?PersonFactory $personFactory = null, - ) { - $this->personFactory = $personFactory ?? new PersonFactory(); - } + public function __construct(protected readonly PersonFactory $personFactory = new PersonFactory()) {} public function make(array $attributes): PersonGoalScore { $attributes = new AttributeBag($attributes); return new PersonGoalScore( - person: $this->personFactory->make( + person: $this->personFactory->make( attributes: $attributes->array(key: 'player') + [ 'team' => $attributes->array(key: 'team'), ], ), - goals: $attributes->integer(key: 'goals'), - assists: $attributes->integer(key: 'assists'), - penalties: $attributes->integer(key: 'penalties'), + goals: $attributes->integer(key: 'goals'), + assists: $attributes->integer(key: 'assists'), + penalties: $attributes->integer(key: 'penalties'), ); } } diff --git a/src/Factories/ScoreFactory.php b/src/Factories/ScoreFactory.php index d19be92..388ad84 100644 --- a/src/Factories/ScoreFactory.php +++ b/src/Factories/ScoreFactory.php @@ -10,31 +10,21 @@ class ScoreFactory implements DataFactory { - protected readonly ScoreResultFactory $scoreResultFactory; - - protected readonly TeamFactory $teamFactory; - - public function __construct( - ?ScoreResultFactory $scoreResultFactory = null, - ?TeamFactory $teamFactory = null, - ) { - $this->scoreResultFactory = $scoreResultFactory ?? new ScoreResultFactory(); - $this->teamFactory = $teamFactory ?? new TeamFactory(); - } + public function __construct(protected readonly ScoreResultFactory $scoreResultFactory = new ScoreResultFactory(), protected readonly TeamFactory $teamFactory = new TeamFactory()) {} public function make(array $attributes): Score { $attributes = new AttributeBag($attributes); return new Score( - duration: $attributes->string(key: 'duration'), - fullTime: $this->scoreResultFactory->make( + duration: $attributes->string(key: 'duration'), + fullTime: $this->scoreResultFactory->make( attributes: $attributes->array(key: 'fullTime'), ), - halfTime: $this->scoreResultFactory->make( + halfTime: $this->scoreResultFactory->make( attributes: $attributes->array(key: 'halfTime'), ), - winner: $attributes->string(key: 'winner'), + winner: $attributes->string(key: 'winner'), ); } } diff --git a/src/Factories/SeasonFactory.php b/src/Factories/SeasonFactory.php index d648e29..27b1007 100644 --- a/src/Factories/SeasonFactory.php +++ b/src/Factories/SeasonFactory.php @@ -5,31 +5,26 @@ namespace EinarHansen\FootballData\Factories; use EinarHansen\FootballData\Data\Season; +use EinarHansen\FootballData\Data\Team; use EinarHansen\Http\Contracts\Data\DataFactory; use EinarHansen\Http\Support\AttributeBag; class SeasonFactory implements DataFactory { - protected readonly TeamFactory $teamFactory; - - public function __construct( - ?TeamFactory $teamFactory = null, - ) { - $this->teamFactory = $teamFactory ?? new TeamFactory(); - } + public function __construct(protected readonly TeamFactory $teamFactory = new TeamFactory()) {} public function make(array $attributes): Season { $attributes = new AttributeBag($attributes); return new Season( - id: $attributes->integer(key: 'id'), - startingAt: $attributes->date(key: 'startDate'), - endingAt: $attributes->date(key: 'endDate'), - matchDay: $attributes->integer(key: 'currentMatchday', default: 0), - winner: $attributes->when( + id: $attributes->integer(key: 'id'), + startingAt: $attributes->date(key: 'startDate'), + endingAt: $attributes->date(key: 'endDate'), + matchDay: $attributes->integer(key: 'currentMatchday', default: 0), + winner: $attributes->when( key: 'winner', - callback: fn (array $team) => $this->teamFactory->make( + callback: fn (array $team): Team => $this->teamFactory->make( attributes: $team ), ), diff --git a/src/Factories/StandingFactory.php b/src/Factories/StandingFactory.php index 7817e39..c4f004c 100644 --- a/src/Factories/StandingFactory.php +++ b/src/Factories/StandingFactory.php @@ -5,31 +5,26 @@ namespace EinarHansen\FootballData\Factories; use EinarHansen\FootballData\Data\Standing; +use EinarHansen\FootballData\Data\TablePosition; use EinarHansen\FootballData\Enums\Stage; use EinarHansen\Http\Contracts\Data\DataFactory; use EinarHansen\Http\Support\AttributeBag; class StandingFactory implements DataFactory { - protected readonly TablePositionFactory $tablePositionFactory; - - public function __construct( - ?TablePositionFactory $tablePositionFactory = null, - ) { - $this->tablePositionFactory = $tablePositionFactory ?? new TablePositionFactory(); - } + public function __construct(protected readonly TablePositionFactory $tablePositionFactory = new TablePositionFactory()) {} public function make(array $attributes): Standing { $attributes = new AttributeBag($attributes); return new Standing( - stage: $attributes->enum(key: 'stage', enumClass: Stage::class), - type: $attributes->string(key: 'type'), - group: $attributes->stringOrNull(key: 'group'), - positions: array_map( + stage: $attributes->enum(key: 'stage', enumClass: Stage::class), + type: $attributes->string(key: 'type'), + group: $attributes->stringOrNull(key: 'group'), + positions: array_map( array: $attributes->array(key: 'table'), - callback: fn ($attributes) => $this->tablePositionFactory->make( + callback: fn ($attributes): TablePosition => $this->tablePositionFactory->make( attributes: $attributes ), ), diff --git a/src/Factories/TablePositionFactory.php b/src/Factories/TablePositionFactory.php index 2627277..e53ff50 100644 --- a/src/Factories/TablePositionFactory.php +++ b/src/Factories/TablePositionFactory.php @@ -10,31 +10,25 @@ class TablePositionFactory implements DataFactory { - protected readonly TeamFactory $teamFactory; - - public function __construct( - ?TeamFactory $teamFactory = null, - ) { - $this->teamFactory = $teamFactory ?? new TeamFactory(); - } + public function __construct(protected readonly TeamFactory $teamFactory = new TeamFactory()) {} public function make(array $attributes): TablePosition { $attributes = new AttributeBag($attributes); return new TablePosition( - position: $attributes->integer('position'), - team: $this->teamFactory->make( + position: $attributes->integer('position'), + team: $this->teamFactory->make( attributes: $attributes->array(key: 'team'), ), - playedGames: $attributes->integer('playedGames'), - form: $attributes->string('form'), - won: $attributes->integer('won'), - draw: $attributes->integer('draw'), - lost: $attributes->integer('lost'), - points: $attributes->integer('points'), - goalsFor: $attributes->integer('goalsFor'), - goalsAgainst: $attributes->integer('goalsAgainst'), + playedGames: $attributes->integer('playedGames'), + form: $attributes->string('form'), + won: $attributes->integer('won'), + draw: $attributes->integer('draw'), + lost: $attributes->integer('lost'), + points: $attributes->integer('points'), + goalsFor: $attributes->integer('goalsFor'), + goalsAgainst: $attributes->integer('goalsAgainst'), goalDifference: $attributes->integer('goalDifference'), ); } diff --git a/src/Factories/TeamFactory.php b/src/Factories/TeamFactory.php index 3f2dd13..83789cf 100644 --- a/src/Factories/TeamFactory.php +++ b/src/Factories/TeamFactory.php @@ -15,17 +15,17 @@ public function make(array $attributes): Team $attributes = new AttributeBag($attributes); return new Team( - id: $attributes->integer(key: 'id'), - name: $attributes->string(key: 'name'), - shortName: $attributes->string(key: 'shortName'), - code: $attributes->string(key: 'tla', default: ''), - image: $attributes->stringOrNull(key: 'crest'), - address: $attributes->stringOrNull(key: 'address'), - website: $attributes->stringOrNull(key: 'website'), - founded: $attributes->integerOrNull(key: 'founded'), - colors: $attributes->stringOrNull(key: 'colors') ?? $attributes->stringOrNull(key: 'clubColors'), - venue: $attributes->stringOrNull(key: 'venue'), - updatedAt: $attributes->dateTimeOrNull(key: 'startDate'), + id: $attributes->integer(key: 'id'), + name: $attributes->string(key: 'name'), + shortName: $attributes->string(key: 'shortName'), + code: $attributes->string(key: 'tla', default: ''), + image: $attributes->stringOrNull(key: 'crest'), + address: $attributes->stringOrNull(key: 'address'), + website: $attributes->stringOrNull(key: 'website'), + founded: $attributes->integerOrNull(key: 'founded'), + colors: $attributes->stringOrNull(key: 'colors') ?? $attributes->stringOrNull(key: 'clubColors'), + venue: $attributes->stringOrNull(key: 'venue'), + updatedAt: $attributes->dateTimeOrNull(key: 'startDate'), ); } } diff --git a/src/FootballDataService.php b/src/FootballDataService.php index bff35bb..e3aac11 100644 --- a/src/FootballDataService.php +++ b/src/FootballDataService.php @@ -25,19 +25,20 @@ use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; -final class FootballDataService extends Service implements ServiceContract, RateLimited +final class FootballDataService extends Service implements RateLimited, ServiceContract { - public RateLimiterState $rateLimiterState; - public function __construct( public readonly ?string $apiToken = null, public readonly string $baseUri = 'https://api.football-data.org', - ClientInterface $client = null, - RequestFactoryInterface $requestFactory = null, - UriFactoryInterface $uriFactory = null, - StreamFactoryInterface $streamFactory = null, - CollectionFactory $collectionFactory = null, - RateLimiterState $rateLimiterState = null + ?ClientInterface $client = null, + ?RequestFactoryInterface $requestFactory = null, + ?UriFactoryInterface $uriFactory = null, + ?StreamFactoryInterface $streamFactory = null, + ?CollectionFactory $collectionFactory = null, + public RateLimiterState $rateLimiterState = new MemoryRateLimitState( + maxAttempts: 10, + decaySeconds: 60, + ) ) { parent::__construct( client: $client, @@ -46,10 +47,6 @@ public function __construct( streamFactory: $streamFactory, collectionFactory: $collectionFactory, ); - $this->rateLimiterState = $rateLimiterState ?? new MemoryRateLimitState( - maxAttempts: 10, - decaySeconds: 60, - ); } /** @@ -65,12 +62,10 @@ public function makeRequest(): RequestFactory value: 'application/json' )->when( value: $this->apiToken, - callback: function ($requestFactory, $token) { - return $requestFactory->withHeader( - name: 'X-Auth-Token', - value: $token - ); - } + callback: fn ($requestFactory, $token) => $requestFactory->withHeader( + name: 'X-Auth-Token', + value: $token + ) )->withMethod(method: RequestMethod::GET); } @@ -86,29 +81,27 @@ public function getRateLimitState(): RateLimiterState * Attempts to execute a callback if it's not limited. If the * limit is reached it will return false. * - * @param \EinarHansen\Http\Message\RequestFactory $request - * @return \Psr\Http\Message\ResponseInterface|false - * * @throws FootballDataException */ - public function attempt(RequestFactory $request): ResponseInterface|false + public function attempt(RequestFactory $requestFactory): ResponseInterface|false { /** @var ResponseInterface|false $response */ - $response = $this - ->getRateLimitState() - ->attempt(fn (): ResponseInterface => $request->send()); + $response = $this->rateLimiterState + ->attempt(fn (): ResponseInterface => $requestFactory->send()); if ($response) { // Since our response contains the exact details of the rate-limit state // we are going to manually override/set the states on our state object. if ($remaining = $response->getHeaderLine('X-Requests-Available-Minute')) { - $this->getRateLimitState()->setRemaining((int) $remaining); + $this->rateLimiterState->setRemaining((int) $remaining); } + if ($expiresIn = $response->getHeaderLine('X-RequestCounter-Reset')) { // We add an extra second to avoid hiting the limit, since the // quantity of time (ms) in the second might be more than ours. - $this->getRateLimitState()->setExpiresIn(((int) $expiresIn) + 1); + $this->rateLimiterState->setExpiresIn(((int) $expiresIn) + 1); } + if ((int) $response->getStatusCode() === StatusCode::BAD_REQUEST->value) { /** @var array{ message: string } $body */ $body = json_decode( diff --git a/src/Pagination/Paginator.php b/src/Pagination/Paginator.php index 809ad84..8b4852b 100644 --- a/src/Pagination/Paginator.php +++ b/src/Pagination/Paginator.php @@ -18,9 +18,7 @@ class Paginator implements PaginatorContract * Pass closure or array if you want to run the collection multiple times, or * pass a Generator if you only want to run it one * - * @param Traversable|array|(Closure(): Generator) $items - * @param int $perPage - * @param int $currentPage + * @param Traversable|array|(Closure(): Generator) $items */ public function __construct( public readonly Closure|iterable $items, @@ -29,8 +27,7 @@ public function __construct( public readonly ?Closure $nextPage = null, public readonly ?Closure $previousPage = null, public readonly ?Resource $resource = null, - ) { - } + ) {} /** * {@inheritDoc} @@ -45,11 +42,15 @@ public function currentPage(): int */ public function nextPage(): ?static { - if ($this->hasMorePages() && ! is_null($this->nextPage)) { - return ($this->nextPage)(); + if (! $this->hasMorePages()) { + return null; } - return null; + if (is_null($this->nextPage)) { + return null; + } + + return ($this->nextPage)(); } /** @@ -57,11 +58,15 @@ public function nextPage(): ?static */ public function previousPage(): ?static { - if ($this->currentPage() > 1 && ! is_null($this->previousPage)) { - return ($this->previousPage)(); + if ($this->currentPage() <= 1) { + return null; } - return null; + if (is_null($this->previousPage)) { + return null; + } + + return ($this->previousPage)(); } /** @@ -93,9 +98,7 @@ public function lastItem(): int */ public function first(): ?Data { - $needle = null; - - foreach ($this as $key => $value) { + foreach ($this as $value) { return $value; } @@ -109,7 +112,7 @@ public function last(): ?Data { $needle = null; - foreach ($this as $key => $value) { + foreach ($this as $value) { $needle = $value; } @@ -132,8 +135,6 @@ public function get(int $key): ?Data /** * Reset the keys on the underlying array. - * - * @return static */ public function values(): static { @@ -176,19 +177,19 @@ public function count(): int return iterator_count($this->getIterator()); } - /** - * {@inheritDoc} - */ - public function isEmpty(): bool - { - $iterator = $this->getIterator(); - if ($iterator instanceof Iterator) { - return $iterator->valid(); - } - - return $this->count() > 0; + /** + * {@inheritDoc} + */ + public function isEmpty(): bool + { + $iterator = $this->getIterator(); + if ($iterator instanceof Iterator) { + return $iterator->valid(); } + return $this->count() > 0; + } + /** * {@inheritDoc} */ @@ -208,7 +209,7 @@ public function getIterator(): Traversable /** * Make an iterator from the given source. * - * @param Traversable|array|(Closure(): Generator) $source + * @param Traversable|array|(Closure(): Generator) $source * @return Traversable */ protected function makeIterator($source) @@ -249,8 +250,8 @@ public function toArray(): array } return iterator_to_array( - iterator: $this->getIterator(), - preserve_keys: false + iterator: $this->getIterator(), + preserve_keys: false ); } } diff --git a/src/Pagination/TeamPaginator.php b/src/Pagination/TeamPaginator.php index f3aacc0..c159e1f 100644 --- a/src/Pagination/TeamPaginator.php +++ b/src/Pagination/TeamPaginator.php @@ -8,6 +8,7 @@ /** * @property TeamResource $resource + * * @implements IteratorAggregate */ class TeamPaginator extends Paginator implements IteratorAggregate diff --git a/src/Resources/AreaResource.php b/src/Resources/AreaResource.php index 873c134..9c9410f 100644 --- a/src/Resources/AreaResource.php +++ b/src/Resources/AreaResource.php @@ -15,7 +15,7 @@ class AreaResource extends Resource * * No filters are available for this endpoint. * - * @return iterable|false + * @return iterable|false */ public function all(): iterable|false { @@ -38,15 +38,13 @@ public function all(): iterable|false /** * List one particular area. - * - * @param int $areaId */ public function find(int $areaId): Area|false|null { $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/areas/$areaId" + path: "/v4/areas/{$areaId}" ) ); if (! $response) { @@ -62,7 +60,7 @@ public function find(int $areaId): Area|false|null /** * List all competitions in an area. * - * @return iterable|false + * @return iterable|false */ public function competitions(Area|int $areaId): iterable|false { diff --git a/src/Resources/CompetitionResource.php b/src/Resources/CompetitionResource.php index 69dd7a0..4286c2e 100644 --- a/src/Resources/CompetitionResource.php +++ b/src/Resources/CompetitionResource.php @@ -27,9 +27,9 @@ class CompetitionResource extends Resource * Optional filter of $areaId * * @param int|int[] $areaIds - * @return iterable|false + * @return iterable|false */ - public function all(int|array $areaIds = null): iterable|false + public function all(int|array|null $areaIds = null): iterable|false { $response = $this->attempt( $this->makeRequest() @@ -38,7 +38,7 @@ public function all(int|array $areaIds = null): iterable|false )->withQuery( query: array_filter( array: ['areas' => $areaIds], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); @@ -55,16 +55,14 @@ public function all(int|array $areaIds = null): iterable|false /** * List one particular competition. - * - * @param int $competitionId */ public function find(int $competitionId): Competition|false|null { $response = $this->attempt( $this->makeRequest() - ->withPath( - path: "/v4/competitions/$competitionId" - ) + ->withPath( + path: "/v4/competitions/{$competitionId}" + ) ); if (! $response) { return false; @@ -88,27 +86,28 @@ public function find(int $competitionId): Competition|false|null * - group={GROUP} Filtering for groupings in a competition * - season={YEAR} The starting year of a season e.g. 2017 or 2016 * - * @return iterable|false + * @return iterable|false * * @throws FootballDataException */ public function matches( Competition|int $competitionId, - string|DateTimeInterface $dateFrom = null, - string|DateTimeInterface $dateTo = null, - Status $status = null, - Stage $stage = null, - int $matchday = null, - string $group = null, - int $season = null + string|DateTimeInterface|null $dateFrom = null, + string|DateTimeInterface|null $dateTo = null, + ?Status $status = null, + ?Stage $stage = null, + ?int $matchday = null, + ?string $group = null, + ?int $season = null ): iterable|false { if ($competitionId instanceof Competition) { $competitionId = $competitionId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/competitions/$competitionId/matches" + path: "/v4/competitions/{$competitionId}/matches" )->withQuery( query: array_filter( array: [ @@ -118,13 +117,13 @@ public function matches( 'dateTo' => $dateTo ? (is_string($dateTo) ? $dateTo : $dateTo->format('Y-m-d')) : null, - 'stage' => $stage ? $stage->value : null, - 'status' => $status ? $status->value : null, + 'stage' => $stage instanceof Stage ? $stage->value : null, + 'status' => $status instanceof Status ? $status->value : null, 'matchday' => $matchday, 'group' => $group, 'season' => $season, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); @@ -147,23 +146,24 @@ public function matches( * - season={YEAR} The starting year of a season e.g. 2017 or 2016 * - date={DATE} e.g. 2018-06-22 * - * @return iterable|false + * @return iterable|false * * @throws FootballDataException */ public function standings( Competition|int $competitionId, - int $season = null, - int $matchday = null, - string|DateTimeInterface $date = null + ?int $season = null, + ?int $matchday = null, + string|DateTimeInterface|null $date = null ): iterable|false { if ($competitionId instanceof Competition) { $competitionId = $competitionId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/competitions/$competitionId/standings" + path: "/v4/competitions/{$competitionId}/standings" )->withQuery( query: array_filter( array: [ @@ -173,7 +173,7 @@ public function standings( ? (is_string($date) ? $date : $date->format('Y-m-d')) : null, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); @@ -194,27 +194,28 @@ public function standings( * Optional filters of: * - season={YEAR} The starting year of a season e.g. 2017 or 2016 * - * @return iterable|false + * @return iterable|false * - * @throws FootballDataException + * @throws FootballDataException */ public function teams( Competition|int $competitionId, - int $season = null, + ?int $season = null, ): iterable|false { if ($competitionId instanceof Competition) { $competitionId = $competitionId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/competitions/$competitionId/teams" + path: "/v4/competitions/{$competitionId}/teams" )->withQuery( query: array_filter( array: [ 'season' => $season, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); @@ -236,29 +237,30 @@ public function teams( * - season={YEAR} The starting year of a season e.g. 2017 or 2016 * - limit={LIMIT} The number of results * - * @return iterable|false + * @return iterable|false * * @throws FootballDataException */ public function topScorers( Competition|int $competitionId, - int $season = null, - int $limit = null, + ?int $season = null, + ?int $limit = null, ): iterable|false { if ($competitionId instanceof Competition) { $competitionId = $competitionId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/competitions/$competitionId/scorers" + path: "/v4/competitions/{$competitionId}/scorers" )->withQuery( query: array_filter( array: [ 'season' => $season, 'limit' => $limit, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); diff --git a/src/Resources/MatchResource.php b/src/Resources/MatchResource.php index a432bcb..1219013 100644 --- a/src/Resources/MatchResource.php +++ b/src/Resources/MatchResource.php @@ -22,38 +22,38 @@ class MatchResource extends Resource * dateTo={DATE} e.g. 2018-06-22 * status={STATUS} EinarHansen\FootballData\Enums\Status * - * @param array|int $competitionIds - * @return iterable|false + * @param array|int $competitionIds + * @return iterable|false * * @throws FootballDataException */ public function all( - array|int $matchIds = null, - string|DateTimeInterface $dateFrom = null, - string|DateTimeInterface $dateTo = null, - Status $status = null, - array|int $competitionIds = null, + array|int|null $matchIds = null, + string|DateTimeInterface|null $dateFrom = null, + string|DateTimeInterface|null $dateTo = null, + ?Status $status = null, + array|int|null $competitionIds = null, ): iterable|false { $response = $this->attempt( $this->makeRequest() - ->withPath( - path: '/v4/matches' - )->withQuery( - query: array_filter( - array: [ - 'ids' => $matchIds, - 'competitions' => $competitionIds, - 'dateFrom' => $dateFrom - ? (is_string($dateFrom) ? $dateFrom : $dateFrom->format('Y-m-d')) - : null, - 'dateTo' => $dateTo - ? (is_string($dateTo) ? $dateTo : $dateTo->format('Y-m-d')) - : null, - 'status' => $status ? $status->value : null, - ], - callback: fn ($query) => ! is_null($query) + ->withPath( + path: '/v4/matches' + )->withQuery( + query: array_filter( + array: [ + 'ids' => $matchIds, + 'competitions' => $competitionIds, + 'dateFrom' => $dateFrom + ? (is_string($dateFrom) ? $dateFrom : $dateFrom->format('Y-m-d')) + : null, + 'dateTo' => $dateTo + ? (is_string($dateTo) ? $dateTo : $dateTo->format('Y-m-d')) + : null, + 'status' => $status instanceof Status ? $status->value : null, + ], + callback: fn ($query): bool => ! is_null($query) + ) ) - ) ); if (! $response) { return false; @@ -74,7 +74,7 @@ public function find(int $matchId): FootballMatch|false|null $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/matches/$matchId" + path: "/v4/matches/{$matchId}" ) ); if (! $response) { @@ -96,22 +96,22 @@ public function find(int $matchId): FootballMatch|false|null * competitions={competitionIds} The ids for the competitions to filter by * limit={LIMIT} The number of results * - * @param array|int $competitionIds - * @return iterable|false + * @param array|int $competitionIds + * @return iterable|false * - * @throws FootballDataException + * @throws FootballDataException */ public function matchHead2Head( int $matchId, - string|DateTimeInterface $dateFrom = null, - string|DateTimeInterface $dateTo = null, - array|int $competitionIds = null, - int $limit = null, + string|DateTimeInterface|null $dateFrom = null, + string|DateTimeInterface|null $dateTo = null, + array|int|null $competitionIds = null, + ?int $limit = null, ): iterable|false { $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/matches/$matchId/head2head" + path: "/v4/matches/{$matchId}/head2head" )->withQuery( query: array_filter( array: [ @@ -124,7 +124,7 @@ public function matchHead2Head( : null, 'limit' => $limit, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); diff --git a/src/Resources/PersonResource.php b/src/Resources/PersonResource.php index 8ab977e..28d29d5 100644 --- a/src/Resources/PersonResource.php +++ b/src/Resources/PersonResource.php @@ -15,16 +15,14 @@ class PersonResource extends Resource { /** * List one particular person. - * - * @param int $personId */ public function find(int $personId): Person|false|null { $response = $this->attempt( $this->makeRequest() - ->withPath( - path: "/v4/persons/$personId" - ) + ->withPath( + path: "/v4/persons/{$personId}" + ) ); if (! $response) { return false; @@ -47,27 +45,28 @@ public function find(int $personId): Person|false|null * limit={LIMIT} The number of results * offset={OFFSET} The offset/starting point when paginating * - * @param array|int $competitionIds - * @return iterable|false + * @param array|int $competitionIds + * @return iterable|false * - * @throws FootballDataException + * @throws FootballDataException */ public function matches( Person|int $personId, - string|DateTimeInterface $dateFrom = null, - string|DateTimeInterface $dateTo = null, - Status $status = null, - array|int $competitionIds = null, - int $limit = null, - int $offset = null + string|DateTimeInterface|null $dateFrom = null, + string|DateTimeInterface|null $dateTo = null, + ?Status $status = null, + array|int|null $competitionIds = null, + ?int $limit = null, + ?int $offset = null ): iterable|false { if ($personId instanceof Person) { $personId = $personId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/players/$personId/matches" + path: "/v4/players/{$personId}/matches" )->withQuery( query: array_filter( array: [ @@ -77,12 +76,12 @@ public function matches( 'dateTo' => $dateTo ? (is_string($dateTo) ? $dateTo : $dateTo->format('Y-m-d')) : null, - 'status' => $status ? $status->value : null, + 'status' => $status instanceof Status ? $status->value : null, 'competitionIds' => $competitionIds, 'limit' => $limit, 'offset' => $offset, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index d06d4fc..ab6e325 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -10,9 +10,9 @@ class Resource extends BaseResource { - public function attempt(RequestFactory $request): ResponseInterface|false + public function attempt(RequestFactory $requestFactory): ResponseInterface|false { - return $this->service()->attempt($request); + return $this->service()->attempt($requestFactory); } public function makeRequest(): RequestFactory diff --git a/src/Resources/TeamResource.php b/src/Resources/TeamResource.php index 67b0dda..41bb2ba 100644 --- a/src/Resources/TeamResource.php +++ b/src/Resources/TeamResource.php @@ -24,7 +24,7 @@ class TeamResource extends Resource * limit={LIMIT} The number of results * offset={OFFSET} The offset/starting point when paginating * - * @return iterable|false + * @return iterable|false */ public function paginate( int $limit = 50, @@ -33,30 +33,31 @@ public function paginate( if ($page <= 0) { $page = 1; } + $response = $this->attempt( $this->makeRequest() - ->withPath( - path: '/v4/teams' - )->withQuery( - query: [ - 'limit' => (string) $limit, - 'offset' => (string) ($limit * ($page - 1)), - ], - ) + ->withPath( + path: '/v4/teams' + )->withQuery( + query: [ + 'limit' => (string) $limit, + 'offset' => (string) ($limit * ($page - 1)), + ], + ) ); if (! $response) { return false; } return new TeamPaginator( - items: $this->makeDataCollection( + items: $this->makeDataCollection( response: $response, factory: TeamFactory::class, pointer: '/teams' ), perPage: $limit, currentPage: $page, - resource: $this + resource: $this ); } @@ -65,7 +66,7 @@ public function paginate( * request as you iterate through the results, until the server * is done. You can add maxPage to avoid anarchy. * - * @return iterable|false + * @return iterable|false */ public function all(int $maxPage = 10): iterable|false { @@ -82,9 +83,9 @@ public function find(int $teamId): Team|false|null { $response = $this->attempt( $this->makeRequest() - ->withPath( - path: "/v4/teams/$teamId" - ) + ->withPath( + path: "/v4/teams/{$teamId}" + ) ); if (! $response) { return false; @@ -108,28 +109,29 @@ public function find(int $teamId): Team|false|null * venue={VENUE} EinarHansen\FootballData\Enums\Venue * limit={LIMIT} The number of results * - * @param array|int $competitionIds - * @return iterable|false + * @param array|int $competitionIds + * @return iterable|false * * @throws FootballDataException */ public function matches( Team|int $teamId, - string|DateTimeInterface $dateFrom = null, - string|DateTimeInterface $dateTo = null, - Status $status = null, - array|int $competitionIds = null, - Venue $venue = null, - int $season = null, - int $limit = null, + string|DateTimeInterface|null $dateFrom = null, + string|DateTimeInterface|null $dateTo = null, + ?Status $status = null, + array|int|null $competitionIds = null, + ?Venue $venue = null, + ?int $season = null, + ?int $limit = null, ): iterable|false { if ($teamId instanceof Team) { $teamId = $teamId->id; } + $response = $this->attempt( $this->makeRequest() ->withPath( - path: "/v4/teams/$teamId/matches" + path: "/v4/teams/{$teamId}/matches" )->withQuery( query: array_filter( array: [ @@ -139,13 +141,13 @@ public function matches( 'dateTo' => $dateTo ? (is_string($dateTo) ? $dateTo : $dateTo->format('Y-m-d')) : null, - 'status' => $status ? $status->value : null, + 'status' => $status instanceof Status ? $status->value : null, 'competitionIds' => $competitionIds, - 'venue' => $venue ? $venue->value : null, + 'venue' => $venue instanceof Venue ? $venue->value : null, 'season' => $season, 'limit' => $limit, ], - callback: fn ($query) => ! is_null($query) + callback: fn ($query): bool => ! is_null($query) ) ) ); @@ -161,15 +163,15 @@ public function matches( } /** - * @param Paginator $paginator - * @param int|null $maxPage + * @param Paginator $paginator * @return iterable */ - public static function loop(Paginator $paginator, int $maxPage = null): iterable + public static function loop(Paginator $paginator, ?int $maxPage = null): iterable { foreach ($paginator as $item) { yield $item; } + if ($paginator->hasMorePages()) { if (! is_null($maxPage) && $paginator->currentPage() >= $maxPage) { return null; diff --git a/src/Traits/MapsCollections.php b/src/Traits/MapsCollections.php index dba9d73..a70292d 100644 --- a/src/Traits/MapsCollections.php +++ b/src/Traits/MapsCollections.php @@ -12,12 +12,9 @@ trait MapsCollections * @param array> $collection * @param string $class * @param array $extraData - * @return array */ protected function mapToArray(array $collection, $class, array $extraData = []): array { - return array_map(function ($data) use ($class, $extraData) { - return new $class($data + $extraData, $this->forge); - }, $collection); + return array_map(fn ($data): object => new $class($data + $extraData, $this->forge), $collection); } } From 612e3f7df9def2c30b16de3540df73cf43e70559 Mon Sep 17 00:00:00 2001 From: Einar Hansen <49709354+einar-hansen@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:28:55 +0200 Subject: [PATCH 4/5] Upgrade PHPUnit version --- composer.json | 4 ++-- phpunit.xml.dist | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index eb8c70f..654826c 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^10.0", "symfony/http-client": "^6.1", "symfony/var-dumper": "^6.1" }, @@ -50,7 +50,7 @@ "scripts": { "analyse": "vendor/bin/phpstan --level=9 analyse", "format": "vendor/bin/pint", - "test": "vendor/bin/pest", + "test": "vendor/bin/phpunit", "test-coverage": "vendor/bin/phpunit --coverage-html coverage" }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f05ae55..522955c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - - - - src/ - - + tests + + + src/ + + From 038394f0076d149adc533e40a439750a410a6fdf Mon Sep 17 00:00:00 2001 From: Einar Hansen <49709354+einar-hansen@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:29:55 +0200 Subject: [PATCH 5/5] Remove deprecated datetime const --- src/Data/Competition.php | 2 +- src/Data/Contract.php | 4 ++-- src/Data/FootballMatch.php | 4 ++-- src/Data/Person.php | 4 ++-- src/Data/Season.php | 4 ++-- src/Data/Team.php | 2 +- src/Factories/CompetitionFactory.php | 2 +- src/Factories/SeasonFactory.php | 2 +- src/Pagination/TeamPaginator.php | 4 ++-- tests/Feature/Resources/AreaResourceTest.php | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Data/Competition.php b/src/Data/Competition.php index d8e420c..f1abb74 100644 --- a/src/Data/Competition.php +++ b/src/Data/Competition.php @@ -35,7 +35,7 @@ public function toArray(): array 'area' => $this->area?->toArray(), 'seasonCount' => $this->seasonCount, 'season' => $this->season?->toArray(), - 'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ISO8601), + 'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ATOM), ]; } diff --git a/src/Data/Contract.php b/src/Data/Contract.php index db39064..454dc81 100644 --- a/src/Data/Contract.php +++ b/src/Data/Contract.php @@ -20,8 +20,8 @@ public function __construct( public function toArray(): array { return [ - 'start' => $this->start?->format(format: DateTimeInterface::ISO8601), - 'end' => $this->end?->format(format: DateTimeInterface::ISO8601), + 'start' => $this->start?->format(format: DateTimeInterface::ATOM), + 'end' => $this->end?->format(format: DateTimeInterface::ATOM), ]; } diff --git a/src/Data/FootballMatch.php b/src/Data/FootballMatch.php index 9658183..536b4b3 100644 --- a/src/Data/FootballMatch.php +++ b/src/Data/FootballMatch.php @@ -41,10 +41,10 @@ public function toArray(): array 'awayTeam' => $this->awayTeam->toArray(), 'score' => $this->score->toArray(), 'matchday' => $this->matchday, - 'startingAt' => $this->startingAt->format(format: DateTimeInterface::ISO8601), + 'startingAt' => $this->startingAt->format(format: DateTimeInterface::ATOM), 'status' => $this->status->value, 'stage' => $this->stage->value, - 'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ISO8601), + 'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ATOM), 'group' => $this->group, 'referees' => array_map( array: $this->referees, diff --git a/src/Data/Person.php b/src/Data/Person.php index 543c8f4..f88cc3e 100644 --- a/src/Data/Person.php +++ b/src/Data/Person.php @@ -37,7 +37,7 @@ public function toArray(): array 'name' => $this->name, 'firstName' => $this->firstName, 'lastName' => $this->lastName, - 'dateOfBirth' => $this->dateOfBirth->format(format: DateTimeInterface::ISO8601), + 'dateOfBirth' => $this->dateOfBirth->format(format: DateTimeInterface::ATOM), 'nationality' => $this->nationality, 'position' => $this->position, 'shirtNumber' => $this->shirtNumber, @@ -47,7 +47,7 @@ public function toArray(): array array: $this->competitions, callback: fn (Competition $competition): array => $competition->toArray() ), - 'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ISO8601), + 'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ATOM), ]; } diff --git a/src/Data/Season.php b/src/Data/Season.php index a9af245..3de4198 100644 --- a/src/Data/Season.php +++ b/src/Data/Season.php @@ -24,8 +24,8 @@ public function toArray(): array { return [ 'id' => $this->id, - 'startingAt' => $this->startingAt->format(format: DateTimeInterface::ISO8601), - 'endingAt' => $this->endingAt->format(format: DateTimeInterface::ISO8601), + 'startingAt' => $this->startingAt->format(format: DateTimeInterface::ATOM), + 'endingAt' => $this->endingAt->format(format: DateTimeInterface::ATOM), 'matchDay' => $this->matchDay, 'winner' => $this->team?->toArray(), ]; diff --git a/src/Data/Team.php b/src/Data/Team.php index 34fc595..c88c79d 100644 --- a/src/Data/Team.php +++ b/src/Data/Team.php @@ -39,7 +39,7 @@ public function toArray(): array 'founded' => $this->founded, 'colors' => $this->colors, 'venue' => $this->venue, - 'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ISO8601), + 'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ATOM), ]; } diff --git a/src/Factories/CompetitionFactory.php b/src/Factories/CompetitionFactory.php index 9182e2b..edf6a79 100644 --- a/src/Factories/CompetitionFactory.php +++ b/src/Factories/CompetitionFactory.php @@ -34,7 +34,7 @@ public function make(array $attributes): Competition ) : null, updatedAt: $attributes->dateTime( key: 'lastUpdated', - format: DateTimeInterface::ISO8601 + format: DateTimeInterface::ATOM ), ); } diff --git a/src/Factories/SeasonFactory.php b/src/Factories/SeasonFactory.php index 27b1007..6d5da58 100644 --- a/src/Factories/SeasonFactory.php +++ b/src/Factories/SeasonFactory.php @@ -22,7 +22,7 @@ public function make(array $attributes): Season startingAt: $attributes->date(key: 'startDate'), endingAt: $attributes->date(key: 'endDate'), matchDay: $attributes->integer(key: 'currentMatchday', default: 0), - winner: $attributes->when( + team: $attributes->when( key: 'winner', callback: fn (array $team): Team => $this->teamFactory->make( attributes: $team diff --git a/src/Pagination/TeamPaginator.php b/src/Pagination/TeamPaginator.php index c159e1f..45cf828 100644 --- a/src/Pagination/TeamPaginator.php +++ b/src/Pagination/TeamPaginator.php @@ -16,7 +16,7 @@ class TeamPaginator extends Paginator implements IteratorAggregate /** * {@inheritDoc} */ - public function nextPage(): ?TeamPaginator + public function nextPage(): ?static { if ($this->hasMorePages()) { return $this->resource @@ -32,7 +32,7 @@ public function nextPage(): ?TeamPaginator /** * {@inheritDoc} */ - public function previousPage(): ?TeamPaginator + public function previousPage(): ?static { if ($this->currentPage() > 1) { return $this->resource diff --git a/tests/Feature/Resources/AreaResourceTest.php b/tests/Feature/Resources/AreaResourceTest.php index 92743f4..aa65116 100644 --- a/tests/Feature/Resources/AreaResourceTest.php +++ b/tests/Feature/Resources/AreaResourceTest.php @@ -89,7 +89,7 @@ public function it_can_return_an_area( $this->assertCount($children, $data->children); } - public function provideAreaData(): array + public static function provideAreaData(): array { return [ 'England' => [