diff --git a/README.md b/README.md index 0b22d3f..a427fd8 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ $hangarClient = new HangarAPIClient( $hangarClient->setHttpClient(new Client(["timeout" => 10])); ``` -## Result Lists -Most methods return a paginated result list which contains a list of results on the current page and methods to -navigate to the next and previous page. The result list implements `Iterator`, `ArrayAccess` and `Countable` so -you can use it like an array. It also has a `getResults()` method which returns the underlying array of results. +## Paginated Lists +Most methods return a paginated list (`Aternos\HangarApi\Client\List\PaginatedList`) which contains the results +on the current page and methods to navigate to the next and previous page. The list implements `Iterator`, +`ArrayAccess` and `Countable` so you can use it like an array. It also has a `getResults()` method which returns the underlying array of results. ```php $projects = $hangarClient->getProjects(); diff --git a/src/Client/List/CompactProjectList.php b/src/Client/List/CompactProjectList.php index d785fba..6e0ab79 100644 --- a/src/Client/List/CompactProjectList.php +++ b/src/Client/List/CompactProjectList.php @@ -14,9 +14,9 @@ * * @package Aternos\HangarApi\Client\List * @description A paginated list of compact projects - * @extends ResultList + * @extends PaginatedList */ -abstract class CompactProjectList extends ResultList +abstract class CompactProjectList extends PaginatedList { public function __construct( protected HangarAPIClient $client, diff --git a/src/Client/List/ResultList.php b/src/Client/List/PaginatedList.php similarity index 97% rename from src/Client/List/ResultList.php rename to src/Client/List/PaginatedList.php index 91b92fc..4a182d4 100644 --- a/src/Client/List/ResultList.php +++ b/src/Client/List/PaginatedList.php @@ -9,13 +9,13 @@ use Iterator; /** - * Class ResultList + * Class PaginatedList * * @package Aternos\HangarApi\Client\List * @description A paginated list of results * @template T */ -abstract class ResultList implements Iterator, ArrayAccess, Countable +abstract class PaginatedList implements Iterator, ArrayAccess, Countable { protected int $iterator = 0; diff --git a/src/Client/List/ProjectList.php b/src/Client/List/ProjectList.php index 11a143f..7eedcd9 100644 --- a/src/Client/List/ProjectList.php +++ b/src/Client/List/ProjectList.php @@ -14,9 +14,9 @@ * * @package Aternos\HangarApi\Client\List * @description A paginated list of projects - * @extends ResultList + * @extends PaginatedList */ -class ProjectList extends ResultList +class ProjectList extends PaginatedList { public function __construct( protected HangarAPIClient $client, diff --git a/src/Client/List/ProjectMemberList.php b/src/Client/List/ProjectMemberList.php index 3fdd828..69d544b 100644 --- a/src/Client/List/ProjectMemberList.php +++ b/src/Client/List/ProjectMemberList.php @@ -12,9 +12,9 @@ * * @package Aternos\HangarApi\Client\List * @description A paginated list of project members - * @extends ResultList + * @extends PaginatedList */ -class ProjectMemberList extends ResultList +class ProjectMemberList extends PaginatedList { public function __construct( protected HangarAPIClient $client, diff --git a/src/Client/List/ProjectVersionList.php b/src/Client/List/ProjectVersionList.php index 980335b..6a90b46 100644 --- a/src/Client/List/ProjectVersionList.php +++ b/src/Client/List/ProjectVersionList.php @@ -13,9 +13,9 @@ * * @package Aternos\HangarApi\Client\List * @description A paginated list of versions - * @extends ResultList + * @extends PaginatedList */ -class ProjectVersionList extends ResultList +class ProjectVersionList extends PaginatedList { public function __construct( protected HangarAPIClient $client, diff --git a/src/Client/List/UserList.php b/src/Client/List/UserList.php index 3a6c43a..27203e7 100644 --- a/src/Client/List/UserList.php +++ b/src/Client/List/UserList.php @@ -13,9 +13,9 @@ * * @package Aternos\HangarApi\Client\List * @description A paginated list of users - * @extends ResultList + * @extends PaginatedList */ -class UserList extends ResultList +class UserList extends PaginatedList { public function __construct( protected HangarAPIClient $client, diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index 6605bfd..debe25c 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -4,7 +4,7 @@ use Aternos\HangarApi\ApiException; use Aternos\HangarApi\Client\HangarAPIClient; -use Aternos\HangarApi\Client\List\ResultList; +use Aternos\HangarApi\Client\List\PaginatedList; use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSearchOptions; use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSortField; use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSortOrder; @@ -97,10 +97,10 @@ protected function assertValidCompactProject($project): void $this->assertNotNull($project->getVisibility()); } - protected function assertValidResultList($list): void + protected function assertValidPaginatedList($list): void { $this->assertNotNull($list); - $this->assertInstanceOf(ResultList::class, $list); + $this->assertInstanceOf(PaginatedList::class, $list); $this->assertNotEmpty($list); $this->assertNotNull($list->getResults()); $this->assertNotEmpty($list->getResults()); @@ -139,7 +139,7 @@ public function testGetProjects(): void $firstProjectOfPages = []; for ($i = 0; $i < 3; $i++) { - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $firstProjectOfPages[$i] = $projectList[0]; foreach ($projectList as $project) { @@ -154,7 +154,7 @@ public function testGetProjects(): void $this->assertTrue($projectList->hasPreviousPage()); $projectList = $projectList->getPreviousPage(); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $this->assertTrue($this->isSameProject($firstProjectOfPages[$i], $projectList[0])); foreach ($projectList as $project) { @@ -179,7 +179,7 @@ public function testGetProjectsInCategory(): void $firstProjectOfPages = []; for ($i = 0; $i < 3; $i++) { - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $firstProjectOfPages[$i] = $projectList[0]; foreach ($projectList as $project) { @@ -195,7 +195,7 @@ public function testGetProjectsInCategory(): void $this->assertTrue($projectList->hasPreviousPage()); $projectList = $projectList->getPreviousPage(); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $this->assertTrue($this->isSameProject($firstProjectOfPages[$i], $projectList[0])); foreach ($projectList as $project) { @@ -217,7 +217,7 @@ public function testGetProjectsByOwner(): void $options->setOwner("Aternos"); $options->setLimit(10); $projectList = $this->apiClient->getProjects($options); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); foreach ($projectList as $project) { $this->assertValidProject($project); @@ -241,7 +241,7 @@ public function testGetRecentlyUpdatedProjects(): void $options->setSortField(ProjectSortField::UPDATED); $options->setSortOrder(ProjectSortOrder::DESC); $projectList = $this->apiClient->getProjects($options); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $lastUpdated = time(); foreach ($projectList as $project) { @@ -263,7 +263,7 @@ public function testGetNotRecentlyUpdatedProjects(): void $options->setSortField(ProjectSortField::UPDATED); $options->setSortOrder(ProjectSortOrder::ASC); $projectList = $this->apiClient->getProjects($options); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $lastUpdated = 0; foreach ($projectList as $project) { @@ -285,7 +285,7 @@ public function testGetProjectsSortedBySlug(): void $options->setSortField(ProjectSortField::SLUG); $options->setSortOrder(ProjectSortOrder::ASC); $projectList = $this->apiClient->getProjects($options); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); $lastSlug = null; foreach ($projectList as $project) { @@ -325,7 +325,7 @@ public function testProjectSortIsSupported(ProjectSortField $sortField, ProjectS $options->setSortField($sortField); $options->setSortOrder($sortOrder); $projectList = $this->apiClient->getProjects($options); - $this->assertValidResultList($projectList); + $this->assertValidPaginatedList($projectList); } /** @@ -361,7 +361,7 @@ public function testGetProjectMembers(): void $this->assertEquals("Aternos", $project->getNamespace()->getOwner()); $members = $project->fetchMembers(); - $this->assertValidResultList($members); + $this->assertValidPaginatedList($members); $this->assertNotEmpty(array_filter($members->getResults(), function ($member) { return $member->getUser() === "Aternos"; })); @@ -379,14 +379,14 @@ public function testGetProjectWatchers(): void $this->assertEquals("Aternos", $project->getNamespace()->getOwner()); $watchers = $project->fetchWatchers(); - $this->assertValidResultList($watchers); + $this->assertValidPaginatedList($watchers); $this->assertNotEmpty(array_filter($watchers->getResults(), function ($watcher) { return $watcher->getName() === "Julian"; })); foreach ($watchers as $watcher) { $projects = $watcher->fetchWatchedProjects(); - $this->assertValidResultList($projects); + $this->assertValidPaginatedList($projects); if ($projects->hasNextPage()) { // let's ignore people watching hundreds of projects to not spam the api @@ -443,7 +443,7 @@ public function testGetDailyProjectVersionStats(): void $this->assertValidProject($project); $versions = $project->fetchVersions(); - $this->assertValidResultList($versions); + $this->assertValidPaginatedList($versions); foreach ($versions as $version) { foreach ($version->getStats()->getPlatformDownloads() as $downloads) { if ($downloads > 0) { @@ -474,7 +474,7 @@ public function testGetUsers(): void $firstUserOfPage = []; for ($i = 0; $i < 3; $i++) { - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $firstUserOfPage[$i] = $users[0]; foreach ($users as $user) { @@ -490,7 +490,7 @@ public function testGetUsers(): void $this->assertTrue($users->hasPreviousPage()); $users = $users->getPreviousPage(); - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName()); foreach ($users as $user) { @@ -524,7 +524,7 @@ public function testGetProjectsWatchedByUser(): void $this->assertEquals("Julian", $user->getName()); $watched = $user->fetchWatchedProjects(); - $this->assertValidResultList($watched); + $this->assertValidPaginatedList($watched); foreach ($watched as $project) { $this->assertValidCompactProject($project); @@ -542,7 +542,7 @@ public function testGetProjectsStarredByUser(): void $this->assertEquals("Julian", $user->getName()); $starred = $user->fetchStarredProjects(); - $this->assertValidResultList($starred); + $this->assertValidPaginatedList($starred); foreach ($starred as $project) { $this->assertValidCompactProject($project); @@ -558,7 +558,7 @@ public function testGetProjectsStarredByUserSortedByStarsKeepsSortOnNextPage(): $starred = $this->apiClient->getProjectsStarredByUser("kennytv", ProjectSortField::STARS, ProjectSortOrder::DESC, 3); $stars = []; for ($i = 0; $i < 2; $i++) { - $this->assertValidResultList($starred); + $this->assertValidPaginatedList($starred); foreach ($starred as $project) { $this->assertValidCompactProject($project); $stars[] = $project->getStats()->getStars(); @@ -583,7 +583,7 @@ public function testProjectsStarredByUserSortIsSupported(ProjectSortField $sortF } $starred = $this->apiClient->getProjectsStarredByUser("kennytv", $sortField, $sortOrder, 1); - $this->assertValidResultList($starred); + $this->assertValidPaginatedList($starred); } /** @@ -598,7 +598,7 @@ public function testProjectsWatchedByUserSortIsSupported(ProjectSortField $sortF } $watched = $this->apiClient->getProjectsWatchedByUser("kennytv", $sortField, $sortOrder, 1); - $this->assertValidResultList($watched); + $this->assertValidPaginatedList($watched); } /** @@ -612,7 +612,7 @@ public function testGetProjectsOfUser(): void $this->assertEquals("Aternos", $user->getName()); $projects = $user->fetchProjects(); - $this->assertValidResultList($projects); + $this->assertValidPaginatedList($projects); foreach ($projects as $project) { $this->assertValidProject($project); @@ -633,7 +633,7 @@ public function testGetStaff(): void $firstUserOfPage = []; for ($i = 0; $i < 3; $i++) { - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $firstUserOfPage[$i] = $users[0]; foreach ($users as $user) { @@ -649,7 +649,7 @@ public function testGetStaff(): void $this->assertTrue($users->hasPreviousPage()); $users = $users->getPreviousPage(); - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName()); foreach ($users as $user) { @@ -672,7 +672,7 @@ public function testGetAuthors(): void $firstUserOfPage = []; for ($i = 0; $i < 3; $i++) { - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $firstUserOfPage[$i] = $users[0]; foreach ($users as $user) { @@ -688,7 +688,7 @@ public function testGetAuthors(): void $this->assertTrue($users->hasPreviousPage()); $users = $users->getPreviousPage(); - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); $this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName()); foreach ($users as $user) { @@ -721,7 +721,7 @@ public static function staffSortProvider(): array public function testStaffSortIsSupported(StaffSortField $sortField): void { $users = $this->apiClient->getStaff(sort: $sortField, limit: 1); - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); } /** @@ -745,7 +745,7 @@ public static function authorSortProvider(): array public function testAuthorSortIsSupported(AuthorSortField $sortField): void { $users = $this->apiClient->getAuthors(sort: $sortField, limit: 1); - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); } /** @@ -757,7 +757,7 @@ public function testGetAuthorsSortedByNameKeepsSortOnNextPage(): void $users = $this->apiClient->getAuthors(sort: AuthorSortField::NAME, limit: 5); $names = []; for ($i = 0; $i < 2; $i++) { - $this->assertValidResultList($users); + $this->assertValidPaginatedList($users); foreach ($users as $user) { $names[] = $user->getName(); } diff --git a/tests/Unit/Client/ClientTestCase.php b/tests/Unit/Client/ClientTestCase.php index 4cb3cf9..4e87c32 100644 --- a/tests/Unit/Client/ClientTestCase.php +++ b/tests/Unit/Client/ClientTestCase.php @@ -52,7 +52,7 @@ protected function createClient( } /** - * Create an empty paginated result model, e.g. to create a result list without sending a request + * Create an empty paginated result model, e.g. to create a paginated list without sending a request * @template T * @param class-string $class generated model class, e.g. PaginatedResultUser * @param int $offset diff --git a/tests/Unit/Client/List/ResultListTest.php b/tests/Unit/Client/List/PaginatedListTest.php similarity index 96% rename from tests/Unit/Client/List/ResultListTest.php rename to tests/Unit/Client/List/PaginatedListTest.php index 67c855a..42bc2fc 100644 --- a/tests/Unit/Client/List/ResultListTest.php +++ b/tests/Unit/Client/List/PaginatedListTest.php @@ -3,16 +3,16 @@ namespace Aternos\HangarApi\Tests\Unit\Client\List; use Aternos\HangarApi\ApiException; -use Aternos\HangarApi\Client\List\ResultList; +use Aternos\HangarApi\Client\List\PaginatedList; use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSearchOptions; use Aternos\HangarApi\Client\Project; use Aternos\HangarApi\Tests\Unit\Client\ClientTestCase; use GuzzleHttp\Psr7\Response; /** - * Tests the behavior that all lists share through {@see ResultList} using a project list + * Tests the behavior that all lists share through {@see PaginatedList} using a project list */ -class ResultListTest extends ClientTestCase +class PaginatedListTest extends ClientTestCase { /** * Response with the projects from the getProjects fixture and the given pagination