From 24d70330b4997929b97f57955fcd1b2e0bd74401 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Fri, 16 Oct 2026 17:55:22 +0200 Subject: [PATCH] rename Project::getVersions() to fetchVersions() --- README.md | 8 +++---- src/Client/Project.php | 28 ++++++++++++++++++++++-- tests/Integration/Client/ClientTest.php | 2 +- tests/Integration/Client/ProjectTest.php | 4 ++-- tests/Unit/Client/ProjectTest.php | 20 +++++++++++++++-- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e389e3e..f892883 100644 --- a/README.md +++ b/README.md @@ -161,11 +161,11 @@ use Aternos\SpigotApi\Client\VersionOrder; // get a specific project (by numeric id) $project = $spigotClient->getProject(2); -// get versions as a PaginatedVersionList -$versions = $project->getVersions(); +// fetch the versions from the API as a PaginatedVersionList (sends a request) +$versions = $project->fetchVersions(); -// get the newest versions first -$versions = $project->getVersions(1, VersionOrder::POST_DATE, SortDirection::DESC); +// fetch the newest versions first +$versions = $project->fetchVersions(1, VersionOrder::POST_DATE, SortDirection::DESC); // get the author $author = $project->getAuthor(); diff --git a/src/Client/Project.php b/src/Client/Project.php index 891eefe..f957ae4 100644 --- a/src/Client/Project.php +++ b/src/Client/Project.php @@ -52,14 +52,17 @@ public function getAuthor(): Author } /** - * Get a list of versions for this project. + * Fetch the versions of this project from the API (paginated). + * + * This sends a request to the SpigotMC API every time it is called. The result is not cached. * * @param int $page * @param VersionOrder|null $order Field to order the results by. When null, the API default (id) is used. * @param SortDirection|null $direction Direction to order the results by. When null, the API default (asc) is used. + * @return PaginatedVersionList * @throws ApiException */ - public function getVersions( + public function fetchVersions( int $page = 1, ?VersionOrder $order = null, ?SortDirection $direction = null, @@ -67,4 +70,25 @@ public function getVersions( { return $this->client->getProjectVersions($this->getId(), $page, $order, $direction); } + + /** + * Fetch the versions of this project from the API (paginated). + * + * This sends a request to the SpigotMC API every time it is called. The result is not cached. + * + * @deprecated Use {@see fetchVersions()} instead. Methods that send a request to the API are prefixed with "fetch". + * @param int $page + * @param VersionOrder|null $order Field to order the results by. When null, the API default (id) is used. + * @param SortDirection|null $direction Direction to order the results by. When null, the API default (asc) is used. + * @return PaginatedVersionList + * @throws ApiException + */ + public function getVersions( + int $page = 1, + ?VersionOrder $order = null, + ?SortDirection $direction = null, + ): PaginatedVersionList + { + return $this->fetchVersions($page, $order, $direction); + } } diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index fe8fedb..07c53e6 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -279,7 +279,7 @@ public function testGetVersionsFromProject(): void { $project = $this->apiClient->getProject(2); - $versions = $project->getVersions(); + $versions = $project->fetchVersions(); $this->assertNotNull($versions); $this->assertNotEmpty($versions); foreach ($versions as $version) { diff --git a/tests/Integration/Client/ProjectTest.php b/tests/Integration/Client/ProjectTest.php index 9698c74..d2c28c2 100644 --- a/tests/Integration/Client/ProjectTest.php +++ b/tests/Integration/Client/ProjectTest.php @@ -53,9 +53,9 @@ public function testGetAuthor(): void /** * @throws ApiException */ - public function testGetVersions(): void + public function testFetchVersions(): void { - $versions = $this->project->getVersions(); + $versions = $this->project->fetchVersions(); $this->assertNotNull($versions); $this->assertNotEmpty($versions); diff --git a/tests/Unit/Client/ProjectTest.php b/tests/Unit/Client/ProjectTest.php index 1c65f4c..9bf69fe 100644 --- a/tests/Unit/Client/ProjectTest.php +++ b/tests/Unit/Client/ProjectTest.php @@ -123,7 +123,7 @@ public function testGetAuthor(): void /** * @throws ApiException */ - public function testGetVersions(): void + public function testFetchVersions(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourceUpdates.json")), @@ -131,7 +131,7 @@ public function testGetVersions(): void $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); $project = new Project($this->apiClient, $this->getResourceModel()); - $versions = $project->getVersions(); + $versions = $project->fetchVersions(); $this->assertNotNull($versions); $this->assertNotEmpty($versions); @@ -141,5 +141,21 @@ public function testGetVersions(): void } } + /** + * @throws ApiException + */ + public function testDeprecatedGetVersionsFetchesVersions(): void + { + $handler = new MockHandler([ + new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourceUpdates.json")), + ]); + $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); + $project = new Project($this->apiClient, $this->getResourceModel()); + + $versions = $project->getVersions(); + $this->assertNotEmpty($versions); + $this->assertSame(0, $handler->count()); + } + } \ No newline at end of file