From c3a7543e1e3e50f12ac1e834b31ee8977f642466 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Fri, 16 Oct 2026 18:01:48 +0200 Subject: [PATCH] rename Version::getProjects() to fetchProjects() --- README.md | 4 ++-- src/Client/Version.php | 22 +++++++++++++++++++--- tests/Integration/Client/ClientTest.php | 2 +- tests/Integration/Client/VersionTest.php | 4 ++-- tests/Unit/Client/VersionTest.php | 20 ++++++++++++++++++-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e389e3e..6c41594 100644 --- a/README.md +++ b/README.md @@ -291,8 +291,8 @@ $version = $spigotClient->getVersion(352711); // get the ID of the project this version belongs to $projectId = $version->getProjectId(); -// get the project as a Project wrapper -$project = $version->getProject(); +// fetch the project from the API as a Project wrapper (sends a request) +$project = $version->fetchProject(); ``` ## Updating the generated code diff --git a/src/Client/Version.php b/src/Client/Version.php index 9e7a9f3..852118d 100644 --- a/src/Client/Version.php +++ b/src/Client/Version.php @@ -41,13 +41,29 @@ public function getProjectId(): int } /** - * Get the project this version belongs to. + * Fetch the project this version belongs to from the API. + * + * This sends a request to the SpigotMC API every time it is called. The result is not cached. * * @return Project * @throws ApiException */ - public function getProject(): Project + public function fetchProject(): Project { return $this->client->getProject($this->getProjectId()); } -} \ No newline at end of file + + /** + * Fetch the project this version belongs to from the API. + * + * This sends a request to the SpigotMC API every time it is called. The result is not cached. + * + * @deprecated Use {@see fetchProject()} instead. Methods that send a request to the API are prefixed with "fetch". + * @return Project + * @throws ApiException + */ + public function getProject(): Project + { + return $this->fetchProject(); + } +} diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index fe8fedb..456a7ba 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -285,7 +285,7 @@ public function testGetVersionsFromProject(): void foreach ($versions as $version) { $this->assertNotNull($version); $this->assertInstanceOf(Version::class, $version); - $this->assertEquals($project, $version->getProject()); + $this->assertEquals($project, $version->fetchProject()); } } diff --git a/tests/Integration/Client/VersionTest.php b/tests/Integration/Client/VersionTest.php index 720ce31..12f1f64 100644 --- a/tests/Integration/Client/VersionTest.php +++ b/tests/Integration/Client/VersionTest.php @@ -29,10 +29,10 @@ public function testGetProjectId(): void /** * @throws ApiException */ - public function testGetProject(): void + public function testFetchProject(): void { $project = $this->apiClient->getProject(6245); - $this->assertEquals($project, $this->version->getProject()); + $this->assertEquals($project, $this->version->fetchProject()); } } \ No newline at end of file diff --git a/tests/Unit/Client/VersionTest.php b/tests/Unit/Client/VersionTest.php index 0d02361..2c554fe 100644 --- a/tests/Unit/Client/VersionTest.php +++ b/tests/Unit/Client/VersionTest.php @@ -52,7 +52,7 @@ public function testGetProjectId(): void /** * @throws ApiException */ - public function testGetProject(): void + public function testFetchProject(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResource.json")), @@ -60,10 +60,26 @@ public function testGetProject(): void $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); $version = new Version($this->apiClient, $this->getResourceUpdateModel()); - $project = $version->getProject(); + $project = $version->fetchProject(); $this->assertNotNull($project); $this->assertEquals(57242, $project->getData()->getId()); $this->assertEquals("spark", $project->getData()->getTitle()); } + /** + * @throws ApiException + */ + public function testDeprecatedGetProjectFetchesProject(): void + { + $handler = new MockHandler([ + new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResource.json")), + ]); + $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); + $version = new Version($this->apiClient, $this->getResourceUpdateModel()); + + $project = $version->getProject(); + $this->assertEquals(57242, $project->getId()); + $this->assertSame(0, $handler->count()); + } + } \ No newline at end of file