From 2c5a03fd533cde7f570c1ee22a58801f14bbe32c Mon Sep 17 00:00:00 2001 From: Joe Bocock Date: Sat, 11 Nov 2023 16:47:58 +0000 Subject: [PATCH] TRE-7: Index to List --- src/Client/AgencyClient.php | 6 +++--- src/Collection/AgencyIndexCollection.php | 18 ------------------ src/Collection/AgencyListCollection.php | 18 ++++++++++++++++++ src/Entity/{AgencyIndex.php => AgencyList.php} | 2 +- src/Request/Agency/ListAgency.php | 6 +++--- tests/Feature/Client/AgencyClientTest.php | 4 ++-- tests/Feature/Collection/CollectionTest.php | 6 +++--- tests/Feature/ResponseTest.php | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 src/Collection/AgencyIndexCollection.php create mode 100644 src/Collection/AgencyListCollection.php rename src/Entity/{AgencyIndex.php => AgencyList.php} (98%) diff --git a/src/Client/AgencyClient.php b/src/Client/AgencyClient.php index 7ab933d..18ace01 100644 --- a/src/Client/AgencyClient.php +++ b/src/Client/AgencyClient.php @@ -4,7 +4,7 @@ namespace JoeBocock\LaunchLibrary\Client; -use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection; +use JoeBocock\LaunchLibrary\Collection\AgencyListCollection; use JoeBocock\LaunchLibrary\Request\Agency\ListAgency; class AgencyClient extends SubClient @@ -80,7 +80,7 @@ public function list( int $totalLaunchCountGTE = null, int $totalLaunchCountLT = null, int $totalLaunchCountLTE = null, - ): AgencyIndexCollection { + ): AgencyListCollection { $request = new ListAgency( $this->client->url, $this->client->version @@ -354,7 +354,7 @@ public function list( $request->setTotalLaunchCountLTE($totalLaunchCountLTE); } - return new AgencyIndexCollection( + return new AgencyListCollection( $this->client, $request, ); diff --git a/src/Collection/AgencyIndexCollection.php b/src/Collection/AgencyIndexCollection.php deleted file mode 100644 index ef97826..0000000 --- a/src/Collection/AgencyIndexCollection.php +++ /dev/null @@ -1,18 +0,0 @@ - - */ -class AgencyIndexCollection extends Collection -{ - public function current(): AgencyIndex - { - return parent::current(); - } -} diff --git a/src/Collection/AgencyListCollection.php b/src/Collection/AgencyListCollection.php new file mode 100644 index 0000000..11cb083 --- /dev/null +++ b/src/Collection/AgencyListCollection.php @@ -0,0 +1,18 @@ + + */ +class AgencyListCollection extends Collection +{ + public function current(): AgencyList + { + return parent::current(); + } +} diff --git a/src/Entity/AgencyIndex.php b/src/Entity/AgencyList.php similarity index 98% rename from src/Entity/AgencyIndex.php rename to src/Entity/AgencyList.php index 1be3896..b66774b 100644 --- a/src/Entity/AgencyIndex.php +++ b/src/Entity/AgencyList.php @@ -4,7 +4,7 @@ namespace JoeBocock\LaunchLibrary\Entity; -class AgencyIndex extends Entity +class AgencyList extends Entity { public function __construct( public int $id, diff --git a/src/Request/Agency/ListAgency.php b/src/Request/Agency/ListAgency.php index c785f10..9e8bc82 100644 --- a/src/Request/Agency/ListAgency.php +++ b/src/Request/Agency/ListAgency.php @@ -4,7 +4,7 @@ namespace JoeBocock\LaunchLibrary\Request\Agency; -use JoeBocock\LaunchLibrary\Entity\AgencyIndex; +use JoeBocock\LaunchLibrary\Entity\AgencyList; use JoeBocock\LaunchLibrary\Request\PaginatedRequest; class ListAgency extends PaginatedRequest @@ -180,7 +180,7 @@ public function getQueryParameters(): array * }[] * } $body * - * @return array + * @return array */ public function hydrate(array $body, array $headers = null): array { @@ -190,7 +190,7 @@ public function hydrate(array $body, array $headers = null): array if (isset($body['results'])) { foreach ($body['results'] as $result) { - $results[] = new AgencyIndex( + $results[] = new AgencyList( $result['id'], $result['url'], $result['name'], diff --git a/tests/Feature/Client/AgencyClientTest.php b/tests/Feature/Client/AgencyClientTest.php index c81d9b2..b57c4a5 100644 --- a/tests/Feature/Client/AgencyClientTest.php +++ b/tests/Feature/Client/AgencyClientTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); use JoeBocock\LaunchLibrary\Client; -use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection; +use JoeBocock\LaunchLibrary\Collection\AgencyListCollection; it('has values that can be set', function () { $client = new Client( @@ -78,7 +78,7 @@ totalLaunchCountGTE: 1, totalLaunchCountLT: 1, totalLaunchCountLTE: 1, - ))->toBeInstanceOf(AgencyIndexCollection::class); + ))->toBeInstanceOf(AgencyListCollection::class); $collection->valid(); diff --git a/tests/Feature/Collection/CollectionTest.php b/tests/Feature/Collection/CollectionTest.php index d876e72..5897317 100644 --- a/tests/Feature/Collection/CollectionTest.php +++ b/tests/Feature/Collection/CollectionTest.php @@ -7,7 +7,7 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use JoeBocock\LaunchLibrary\Client; -use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection; +use JoeBocock\LaunchLibrary\Collection\AgencyListCollection; use JoeBocock\LaunchLibrary\Collection\Collection; use JoeBocock\LaunchLibrary\Collection\Config\AgencyTypeCollection; use JoeBocock\LaunchLibrary\Request\Agency\ListAgency; @@ -107,7 +107,7 @@ public function hydrate(array $body, array $headers = null): array client: new GuzzleHttpClient(['handler' => HandlerStack::create($mock)]) ); - expect($collection = $client->agency->list())->toBeInstanceOf(AgencyIndexCollection::class); + expect($collection = $client->agency->list())->toBeInstanceOf(AgencyListCollection::class); $collection->valid(); $collection->next(); @@ -125,7 +125,7 @@ public function hydrate(array $body, array $headers = null): array client: new GuzzleHttpClient(['handler' => HandlerStack::create($mock)]) ); - expect($collection = $client->agency->list())->toBeInstanceOf(AgencyIndexCollection::class); + expect($collection = $client->agency->list())->toBeInstanceOf(AgencyListCollection::class); expect($collection->valid())->toBe(false); }); diff --git a/tests/Feature/ResponseTest.php b/tests/Feature/ResponseTest.php index 03f5f54..1ab191a 100644 --- a/tests/Feature/ResponseTest.php +++ b/tests/Feature/ResponseTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); use JoeBocock\LaunchLibrary\Client; -use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection; +use JoeBocock\LaunchLibrary\Collection\AgencyListCollection; use JoeBocock\LaunchLibrary\Collection\Config\AgencyTypeCollection; use JoeBocock\LaunchLibrary\Entity\ApiThrottle; use JoeBocock\LaunchLibrary\Entity\Config\AgencyType; @@ -16,7 +16,7 @@ expect($callback($client))->toBeInstanceOf($class); })->with([ ['tests/Fixture/ApiThrottle/Get.json', fn (Client $client) => $client->apiThrottle->get(), ApiThrottle::class], - ['tests/Fixture/Agency/Index.json', fn (Client $client) => $client->agency->list(), AgencyIndexCollection::class], + ['tests/Fixture/Agency/Index.json', fn (Client $client) => $client->agency->list(), AgencyListCollection::class], ['tests/Fixture/Config/AgencyType/Index.json', fn (Client $client) => $client->config->agencyType->list(), AgencyTypeCollection::class], ['tests/Fixture/Config/AgencyType/Get.json', fn (Client $client) => $client->config->agencyType->get(1), AgencyType::class], ]);