From c86ee67f58d1481d8b705d922ebf704bd65f60a4 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Fri, 16 Oct 2026 17:58:55 +0200 Subject: [PATCH] rename Author::getProjects() to fetchProjects() --- README.md | 4 ++-- src/Client/Author.php | 23 ++++++++++++++++++++--- tests/Integration/Client/AuthorTest.php | 4 ++-- tests/Unit/Client/AuthorTest.php | 20 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e389e3e..96b79a5 100644 --- a/README.md +++ b/README.md @@ -220,8 +220,8 @@ To request more information about an author from the API, use the methods on the // get a specific author (by numeric id) $author = $spigotClient->getAuthor(1); -// get projects as a PaginatedProjectList -$projects = $author->getProjects(); +// fetch the projects from the API as a PaginatedAuthorProjectList (sends a request) +$projects = $author->fetchProjects(); ``` ### getAuthorProjects() diff --git a/src/Client/Author.php b/src/Client/Author.php index 3338196..e8f649c 100644 --- a/src/Client/Author.php +++ b/src/Client/Author.php @@ -32,12 +32,29 @@ public function getId(): int } /** - * Get a list of projects by this author. + * Fetch the projects of this author from the API (paginated). * + * This sends a request to the SpigotMC API every time it is called. The result is not cached. + * + * @return PaginatedAuthorProjectList * @throws ApiException */ - public function getProjects(): PaginatedAuthorProjectList + public function fetchProjects(): PaginatedAuthorProjectList { return $this->client->getAuthorProjects($this->getId()); } -} \ No newline at end of file + + /** + * Fetch the projects of this author 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 fetchProjects()} instead. Methods that send a request to the API are prefixed with "fetch". + * @return PaginatedAuthorProjectList + * @throws ApiException + */ + public function getProjects(): PaginatedAuthorProjectList + { + return $this->fetchProjects(); + } +} diff --git a/tests/Integration/Client/AuthorTest.php b/tests/Integration/Client/AuthorTest.php index bf3f97f..8f04d08 100644 --- a/tests/Integration/Client/AuthorTest.php +++ b/tests/Integration/Client/AuthorTest.php @@ -23,9 +23,9 @@ public function setUp(): void /** * @throws ApiException */ - public function testGetProjects(): void + public function testFetchProjects(): void { - $projects = $this->author->getProjects(); + $projects = $this->author->fetchProjects(); $this->assertNotNull($projects); $this->assertNotEmpty($projects); diff --git a/tests/Unit/Client/AuthorTest.php b/tests/Unit/Client/AuthorTest.php index 251d67e..cb6ca3f 100644 --- a/tests/Unit/Client/AuthorTest.php +++ b/tests/Unit/Client/AuthorTest.php @@ -27,7 +27,7 @@ protected function getAuthorModel(): \Aternos\SpigotApi\Model\Author /** * @throws ApiException */ - public function testGetProjects(): void + public function testFetchProjects(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourcesByAuthor.json")), @@ -35,7 +35,7 @@ public function testGetProjects(): void $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); $author = new Author($this->apiClient, $this->getAuthorModel()); - $projects = $author->getProjects(); + $projects = $author->fetchProjects(); $this->assertNotNull($projects); $this->assertNotEmpty($projects); @@ -45,4 +45,20 @@ public function testGetProjects(): void } } + /** + * @throws ApiException + */ + public function testDeprecatedGetProjectsFetchesProjects(): void + { + $handler = new MockHandler([ + new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourcesByAuthor.json")), + ]); + $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); + $author = new Author($this->apiClient, $this->getAuthorModel()); + + $projects = $author->getProjects(); + $this->assertNotEmpty($projects); + $this->assertSame(0, $handler->count()); + } + } \ No newline at end of file