From 374ae6d73e59d55aeb8ba76b6cdd73b1fc2d91c6 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Mon, 19 Oct 2026 13:37:36 +0200 Subject: [PATCH 1/2] extend the generated models in the wrappers --- README.md | 12 +-- src/Client/Category.php | 18 +++-- src/Client/CurseForgeAPIClient.php | 2 +- src/Client/File.php | 16 ++-- src/Client/Game.php | 22 +++--- src/Client/GameVersionType.php | 12 +-- src/Client/Mod.php | 24 +++--- tests/Integration/Client/ClientTest.php | 74 +++++++++--------- tests/Unit/Client/CurseForgeAPIClientTest.php | 78 +++++++++++++------ 9 files changed, 150 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 89bd600..43d8fdc 100644 --- a/README.md +++ b/README.md @@ -39,20 +39,20 @@ $games = $client->getGames(); foreach ($games as $game) { // like most other methods, this method returns a wrapper - // you can use the getData() method to get the game data - echo $game->getData()->getName() . PHP_EOL; + // wrappers extend the generated models, so all getters can be used directly + echo $game->getName() . PHP_EOL; } $games = $games->getNextPage(); foreach ($games as $game) { - echo $game->getData()->getName() . PHP_EOL; + echo $game->getName() . PHP_EOL; } ``` You can also call `getGame` with the ID of a game to get a specific game. For example, 432 is the ID for Minecraft. ```php $game = $client->getGame(432); -echo $game->getData()->getSlug() . PHP_EOL; +echo $game->getSlug() . PHP_EOL; ``` ### Game Versions @@ -146,7 +146,7 @@ $files = $mod->getFiles(); ``` It optionally takes a ModFilesOptions object as a parameter: ```php -$options = new ModFilesOptions($mod->getData()->getId()); +$options = new ModFilesOptions($mod->getId()); $options->setGameVersion("1.19.2"); use \Aternos\CurseForgeApi\Client\Options\ModSearch\ModLoaderType; @@ -173,7 +173,7 @@ Note that the bulk endpoint doesn't require a mod id. #### File Download URLs You can get the download URL for a file like this: ```php -$url = $file->getData()->getDownloadUrl(); +$url = $file->getDownloadUrl(); // or if you don't already have the file object $url = $client->getModFileDownloadUrl(420561, 3787455); ``` diff --git a/src/Client/Category.php b/src/Client/Category.php index 2116979..2251496 100644 --- a/src/Client/Category.php +++ b/src/Client/Category.php @@ -7,21 +7,23 @@ use Aternos\CurseForgeApi\Client\Options\ModSearchOptions; use Aternos\CurseForgeApi\Model\Category as CategoryModel; -class Category +class Category extends CategoryModel { public function __construct( protected CurseForgeAPIClient $client, - protected CategoryModel $category, + CategoryModel $data ) { + parent::__construct($data->container); } /** + * @deprecated The category extends the generated model now, so its getters can be used directly. * @return CategoryModel */ public function getData(): CategoryModel { - return $this->category; + return $this; } /** @@ -33,13 +35,13 @@ public function getData(): CategoryModel public function getMods(?ModSearchOptions $options = null): PaginatedModList { if ($options === null) { - $options = new ModSearchOptions($this->category->getGameId()); + $options = new ModSearchOptions($this->getGameId()); } - if ($this->category->getIsClass()) { - $options->setClassId($this->category->getId()); + if ($this->getIsClass()) { + $options->setClassId($this->getId()); } else { - $options->setCategoryIds([$this->category->getId()]); + $options->setCategoryIds([$this->getId()]); } return $this->client->searchMods($options); @@ -52,6 +54,6 @@ public function getMods(?ModSearchOptions $options = null): PaginatedModList */ public function getGame(): Game { - return $this->client->getGame($this->category->getGameId()); + return $this->client->getGame($this->getGameId()); } } diff --git a/src/Client/CurseForgeAPIClient.php b/src/Client/CurseForgeAPIClient.php index 0301e0e..a528900 100644 --- a/src/Client/CurseForgeAPIClient.php +++ b/src/Client/CurseForgeAPIClient.php @@ -255,7 +255,7 @@ public function getCategories(int $gameId, ?int $classId = null, ?bool $classesO public function getCategory(int $gameId, int $categoryId): ?Category { foreach ($this->getCategories($gameId) as $category) { - if ($category->getData()->getId() === $categoryId) { + if ($category->getId() === $categoryId) { return $category; } } diff --git a/src/Client/File.php b/src/Client/File.php index f716f2b..583572e 100644 --- a/src/Client/File.php +++ b/src/Client/File.php @@ -5,21 +5,23 @@ use Aternos\CurseForgeApi\ApiException; use Aternos\CurseForgeApi\Model\File as FileModel; -class File +class File extends FileModel { public function __construct( protected CurseForgeAPIClient $client, - protected FileModel $file, + FileModel $data ) { + parent::__construct($data->container); } /** + * @deprecated The file extends the generated model now, so its getters can be used directly. * @return FileModel */ public function getData(): FileModel { - return $this->file; + return $this; } /** @@ -29,11 +31,11 @@ public function getData(): FileModel */ public function getServerPack(): ?File { - if (!$this->file->getServerPackFileId()) { + if (!$this->getServerPackFileId()) { return null; } - return $this->client->getModFile($this->file->getModId(), $this->file->getServerPackFileId()); + return $this->client->getModFile($this->getModId(), $this->getServerPackFileId()); } /** @@ -46,7 +48,7 @@ public function getServerPack(): ?File */ public function getChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $markup = null): string { - return $this->client->getModFileChangelog($this->file->getModId(), $this->file->getId(), $raw, $stripped, $markup); + return $this->client->getModFileChangelog($this->getModId(), $this->getId(), $raw, $stripped, $markup); } /** @@ -56,6 +58,6 @@ public function getChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $m */ public function getMod(): Mod { - return $this->client->getMod($this->file->getModId()); + return $this->client->getMod($this->getModId()); } } \ No newline at end of file diff --git a/src/Client/Game.php b/src/Client/Game.php index d064c85..049d804 100644 --- a/src/Client/Game.php +++ b/src/Client/Game.php @@ -8,26 +8,28 @@ use Aternos\CurseForgeApi\Model\Game as GameModel; use Aternos\CurseForgeApi\Model\GameVersionsByTypeV2; -class Game +class Game extends GameModel { /** * @param CurseForgeAPIClient $client - * @param GameModel $game + * @param GameModel $data */ public function __construct( protected CurseForgeAPIClient $client, - protected GameModel $game + GameModel $data ) { + parent::__construct($data->container); } /** + * @deprecated The game extends the generated model now, so its getters can be used directly. * @return GameModel */ public function getData(): GameModel { - return $this->game; + return $this; } /** @@ -37,7 +39,7 @@ public function getData(): GameModel */ public function getVersionTypes(): array { - return $this->client->getGameVersionTypes($this->game->getId()); + return $this->client->getGameVersionTypes($this->getId()); } /** @@ -47,7 +49,7 @@ public function getVersionTypes(): array */ public function getVersions(): array { - return $this->client->getGameVersions($this->game->getId()); + return $this->client->getGameVersions($this->getId()); } /** @@ -58,7 +60,7 @@ public function getVersions(): array */ public function getGameVersionsByType(int $versionTypeId): array { - return $this->client->getGameVersionsByType($this->game->getId(), $versionTypeId); + return $this->client->getGameVersionsByType($this->getId(), $versionTypeId); } /** @@ -69,7 +71,7 @@ public function getGameVersionsByType(int $versionTypeId): array */ public function getCategories(?int $classId = null, ?bool $classesOnly = null): array { - return $this->client->getCategories($this->game->getId(), $classId, $classesOnly); + return $this->client->getCategories($this->getId(), $classId, $classesOnly); } /** @@ -80,7 +82,7 @@ public function getCategories(?int $classId = null, ?bool $classesOnly = null): */ public function searchMods(?ModSearchOptions $options = null): PaginatedModList { - return $this->client->searchMods($options ?? new ModSearchOptions($this->game->getId())); + return $this->client->searchMods($options ?? new ModSearchOptions($this->getId())); } /** @@ -93,6 +95,6 @@ public function searchMods(?ModSearchOptions $options = null): PaginatedModList */ public function getFeaturedMods(array $excludedModIds = [], ?int $gameVersionTypeId = null, ?bool $clientCompatible = null): FeaturedMods { - return $this->client->getFeaturedMods($this->game->getId(), $excludedModIds, $gameVersionTypeId, $clientCompatible); + return $this->client->getFeaturedMods($this->getId(), $excludedModIds, $gameVersionTypeId, $clientCompatible); } } diff --git a/src/Client/GameVersionType.php b/src/Client/GameVersionType.php index 5aa6f4d..2c14865 100644 --- a/src/Client/GameVersionType.php +++ b/src/Client/GameVersionType.php @@ -6,21 +6,23 @@ use Aternos\CurseForgeApi\Model\GameVersionsByTypeV2; use Aternos\CurseForgeApi\Model\GameVersionType as GameVersionTypeModel; -class GameVersionType +class GameVersionType extends GameVersionTypeModel { public function __construct( protected CurseForgeAPIClient $client, - protected GameVersionTypeModel $gameVersion, + GameVersionTypeModel $data ) { + parent::__construct($data->container); } /** + * @deprecated The game version type extends the generated model now, so its getters can be used directly. * @return GameVersionTypeModel */ public function getData(): GameVersionTypeModel { - return $this->gameVersion; + return $this; } /** @@ -30,7 +32,7 @@ public function getData(): GameVersionTypeModel */ public function getVersions(): array { - return $this->client->getGameVersionsByType($this->gameVersion->getGameId(), $this->gameVersion->getId()); + return $this->client->getGameVersionsByType($this->getGameId(), $this->getId()); } /** @@ -40,6 +42,6 @@ public function getVersions(): array */ public function getGame(): Game { - return $this->client->getGame($this->gameVersion->getGameId()); + return $this->client->getGame($this->getGameId()); } } \ No newline at end of file diff --git a/src/Client/Mod.php b/src/Client/Mod.php index 34e17da..665140a 100644 --- a/src/Client/Mod.php +++ b/src/Client/Mod.php @@ -7,13 +7,14 @@ use Aternos\CurseForgeApi\Client\Options\ModFilesOptions; use Aternos\CurseForgeApi\Model\Mod as ModModel; -class Mod +class Mod extends ModModel { public function __construct( protected CurseForgeAPIClient $client, - protected ModModel $mod, + ModModel $data ) { + parent::__construct($data->container); } /** @@ -27,11 +28,12 @@ public static function fromModels(CurseForgeAPIClient $client, array $models): a } /** + * @deprecated The mod extends the generated model now, so its getters can be used directly. * @return ModModel */ public function getData(): ModModel { - return $this->mod; + return $this; } /** @@ -42,7 +44,7 @@ public function getData(): ModModel */ public function getDescription(?string $lang = null): ?string { - return $this->client->getModDescription($this->mod->getId(), $lang); + return $this->client->getModDescription($this->getId(), $lang); } /** @@ -53,7 +55,7 @@ public function getDescription(?string $lang = null): ?string */ public function getFiles(?ModFilesOptions $options = null): PaginatedFilesList { - return $this->client->getModFiles($options ?? new ModFilesOptions($this->mod->getId())); + return $this->client->getModFiles($options ?? new ModFilesOptions($this->getId())); } /** @@ -63,7 +65,7 @@ public function getFiles(?ModFilesOptions $options = null): PaginatedFilesList */ public function getGame(): Game { - return $this->client->getGame($this->mod->getGameId()); + return $this->client->getGame($this->getGameId()); } /** @@ -72,8 +74,8 @@ public function getGame(): Game */ public function getPrimaryCategory(): ?Category { - foreach ($this->mod->getCategories() as $category) { - if ($category->getId() === $this->mod->getPrimaryCategoryId()) { + foreach ($this->getCategories() as $category) { + if ($category->getId() === $this->getPrimaryCategoryId()) { return new Category($this->client, $category); } } @@ -87,7 +89,7 @@ public function getPrimaryCategory(): ?Category */ public function getCategoryClass(): Category { - return $this->client->getCategory($this->mod->getGameId(), $this->mod->getClassId()); + return $this->client->getCategory($this->getGameId(), $this->getClassId()); } /** @@ -97,7 +99,7 @@ public function getCategoryClass(): Category */ public function getMainFile(): File { - return $this->getFile($this->mod->getMainFileId()); + return $this->getFile($this->getMainFileId()); } /** @@ -107,6 +109,6 @@ public function getMainFile(): File */ public function getFile(int $fileId): File { - return $this->client->getModFile($this->mod->getId(), $fileId); + return $this->client->getModFile($this->getId(), $fileId); } } diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index 57dc420..3cf8c2e 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -74,7 +74,7 @@ public function testGetGames() $firstGameOfPage = []; while ($games->hasNextPage()) { - $firstGameOfPage[] = $games->getResults()[0]->getData()->getId(); + $firstGameOfPage[] = $games->getResults()[0]->getId(); $games = $games->getNextPage(); } $this->assertTrue($games->hasPreviousPage()); @@ -82,7 +82,7 @@ public function testGetGames() while ($games->hasPreviousPage()) { $games = $games->getPreviousPage(); - $this->assertEquals($firstGameOfPage[array_key_last($firstGameOfPage)], $games->getResults()[0]->getData()->getId()); + $this->assertEquals($firstGameOfPage[array_key_last($firstGameOfPage)], $games->getResults()[0]->getId()); array_pop($firstGameOfPage); } $this->assertFalse($games->hasPreviousPage()); @@ -97,8 +97,8 @@ public function testGetGames() public function testGetGame() { $game = $this->apiClient->getGame(static::MINECRAFT_GAME_ID); - $this->assertEquals(static::MINECRAFT_GAME_ID, $game->getData()->getId()); - $this->assertEquals("Minecraft", $game->getData()->getName()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $game->getId()); + $this->assertEquals("Minecraft", $game->getName()); $versions = $game->getVersions(); $this->assertNotEmpty($versions); @@ -126,13 +126,13 @@ public function testGetGameVersions() public function testGetGameVersionTypes() { $game = $this->apiClient->getGame(static::MINECRAFT_GAME_ID); - $this->assertEquals(static::MINECRAFT_GAME_ID, $game->getData()->getId()); - $this->assertEquals("Minecraft", $game->getData()->getName()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $game->getId()); + $this->assertEquals("Minecraft", $game->getName()); $types = $game->getVersionTypes(); $this->assertNotEmpty($types); foreach ($types as $type) { $this->assertEquals($game, $type->getGame()); - $gameVersions = $game->getGameVersionsByType($type->getData()->getId()); + $gameVersions = $game->getGameVersionsByType($type->getId()); $this->assertEquals($gameVersions, $type->getVersions()); } } @@ -149,16 +149,16 @@ public function testGetCategories() for ($i = 0; $i < 3; $i++) { $category = $categories[$i]; - $this->assertEquals(static::MINECRAFT_GAME_ID, $category->getGame()->getData()->getId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $category->getGame()->getId()); $mods = $category->getMods(); $this->assertNotEmpty($mods); foreach ($mods->getResults() as $mod) { - if ($category->getData()->getIsClass()) { - $this->assertEquals($category->getData()->getId(), $mod->getData()->getClassId()); + if ($category->getIsClass()) { + $this->assertEquals($category->getId(), $mod->getClassId()); } else { - $this->assertContains($category->getData()->getId(), - array_map(fn($category) => $category->getId(), $mod->getData()->getCategories())); + $this->assertContains($category->getId(), + array_map(fn($category) => $category->getId(), $mod->getCategories())); } } } @@ -174,21 +174,21 @@ public function testGetCategoriesOnlyClasses() $categories = $this->apiClient->getCategories(static::MINECRAFT_GAME_ID, null, true); $this->assertNotEmpty($categories); foreach ($categories as $category) { - $this->assertTrue($category->getData()->getIsClass()); + $this->assertTrue($category->getIsClass()); } for ($i = 0; $i < 3; $i++) { $category = $categories[$i]; - $this->assertEquals(static::MINECRAFT_GAME_ID, $category->getGame()->getData()->getId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $category->getGame()->getId()); $mods = $category->getMods(); $this->assertNotEmpty($mods); foreach ($mods->getResults() as $mod) { - if ($category->getData()->getIsClass()) { - $this->assertEquals($category->getData()->getId(), $mod->getData()->getClassId()); + if ($category->getIsClass()) { + $this->assertEquals($category->getId(), $mod->getClassId()); } else { - $this->assertContains($category->getData()->getId(), - array_map(fn($category) => $category->getId(), $mod->getData()->getCategories())); + $this->assertContains($category->getId(), + array_map(fn($category) => $category->getId(), $mod->getCategories())); } } } @@ -199,7 +199,7 @@ public function testGetCategory() $category = $this->apiClient->getCategory(static::MINECRAFT_GAME_ID, static::MCLOGS_PRIMARY_CATEGORY_ID); $this->assertNotNull($category); - $this->assertEquals(static::MCLOGS_PRIMARY_CATEGORY_ID, $category->getData()->getId()); + $this->assertEquals(static::MCLOGS_PRIMARY_CATEGORY_ID, $category->getId()); $category = $this->apiClient->getCategory(static::MINECRAFT_GAME_ID, -1); $this->assertNull($category); @@ -215,8 +215,8 @@ public function testGetCategoriesInClass() $categories = $this->apiClient->getCategories(static::MINECRAFT_GAME_ID, static::MODS_CATEGORY_ID); $this->assertNotEmpty($categories); foreach ($categories as $category) { - $this->assertNotTrue($category->getData()->getIsClass()); - $this->assertEquals(static::MODS_CATEGORY_ID, $category->getData()->getClassId()); + $this->assertNotTrue($category->getIsClass()); + $this->assertEquals(static::MODS_CATEGORY_ID, $category->getClassId()); } } @@ -231,21 +231,21 @@ public function testSearchMods() $mods = $this->apiClient->searchMods($options); $this->assertNotEmpty($mods); foreach ($mods as $mod) { - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getData()->getGameId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGameId()); } $this->assertNull($mods->getPreviousPage()); $mods = $mods->getNextPage(); foreach ($mods as $mod) { - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getData()->getGameId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGameId()); } $game = $this->apiClient->getGame(static::MINECRAFT_GAME_ID); $mods = $game->searchMods(); $this->assertNotEmpty($mods); foreach ($mods as $mod) { - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getData()->getGameId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGameId()); } } @@ -270,7 +270,7 @@ public function testSearchModsLastPageNext() $mods = $this->apiClient->searchMods($options); $this->assertNotEmpty($mods); foreach ($mods as $mod) { - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getData()->getGameId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGameId()); } $this->assertTrue($mods->hasNextPage()); @@ -293,8 +293,8 @@ public function testSearchModsInClass() $mods = $this->apiClient->searchMods($options); $this->assertNotEmpty($mods); foreach ($mods as $mod) { - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getData()->getGameId()); - $this->assertEquals(static::MODS_CATEGORY_ID, $mod->getData()->getClassId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGameId()); + $this->assertEquals(static::MODS_CATEGORY_ID, $mod->getClassId()); } } @@ -307,10 +307,10 @@ public function testGetMod() { $mod = $this->apiClient->getMod(static::MCLOGS_MOD_ID); - $this->assertEquals(static::MCLOGS_MOD_ID, $mod->getData()->getId()); - $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGame()->getData()->getId()); - $this->assertEquals(static::MCLOGS_PRIMARY_CATEGORY_ID, $mod->getPrimaryCategory()->getData()->getId()); - $this->assertEquals(static::MODS_CATEGORY_ID, $mod->getCategoryClass()->getData()->getId()); + $this->assertEquals(static::MCLOGS_MOD_ID, $mod->getId()); + $this->assertEquals(static::MINECRAFT_GAME_ID, $mod->getGame()->getId()); + $this->assertEquals(static::MCLOGS_PRIMARY_CATEGORY_ID, $mod->getPrimaryCategory()->getId()); + $this->assertEquals(static::MODS_CATEGORY_ID, $mod->getCategoryClass()->getId()); } /** @@ -324,7 +324,7 @@ public function testGetMods() $mods = $this->apiClient->getMods($ids); $this->assertSameSize($ids, $mods); foreach ($ids as $id) { - $this->assertNotEmpty(array_filter($mods, fn($mod) => $mod->getData()->getId() === $id)); + $this->assertNotEmpty(array_filter($mods, fn($mod) => $mod->getId() === $id)); } } @@ -370,11 +370,11 @@ public function testGetModFile() $this->assertEquals($mod, $file->getMod()); - $this->assertEquals($mod->getData()->getMainFileId(), $file->getData()->getId()); + $this->assertEquals($mod->getMainFileId(), $file->getId()); $this->assertNotNull($file->getChangelog()); - $this->assertTrue($mod->getData()->getAllowModDistribution()); - $this->assertNotEmpty($this->apiClient->getModFileDownloadURL($mod->getData()->getId(), $file->getData()->getId())); + $this->assertTrue($mod->getAllowModDistribution()); + $this->assertNotEmpty($this->apiClient->getModFileDownloadURL($mod->getId(), $file->getId())); $this->assertNull($file->getServerPack()); } @@ -388,12 +388,12 @@ public function testGetModFiles() { $mod = $this->apiClient->getMod(static::MCLOGS_MOD_ID); - $fileIds = array_map(fn($file) => $file->getData()->getId(), $mod->getFiles()->getResults()); + $fileIds = array_map(fn($file) => $file->getId(), $mod->getFiles()->getResults()); $this->assertNotEmpty($fileIds); $files = $this->apiClient->getFiles($fileIds); $this->assertSameSize($fileIds, $files); foreach ($fileIds as $id) { - $this->assertNotEmpty(array_filter($files, fn($file) => $file->getData()->getId() === $id)); + $this->assertNotEmpty(array_filter($files, fn($file) => $file->getId() === $id)); } } diff --git a/tests/Unit/Client/CurseForgeAPIClientTest.php b/tests/Unit/Client/CurseForgeAPIClientTest.php index 6fe663e..7225d2b 100644 --- a/tests/Unit/Client/CurseForgeAPIClientTest.php +++ b/tests/Unit/Client/CurseForgeAPIClientTest.php @@ -12,9 +12,14 @@ use Aternos\CurseForgeApi\Client\Options\ModFilesOptions; use Aternos\CurseForgeApi\Client\Options\ModSearchOptions; use Aternos\CurseForgeApi\Configuration; +use Aternos\CurseForgeApi\Model\Category as CategoryModel; +use Aternos\CurseForgeApi\Model\File as FileModel; use Aternos\CurseForgeApi\Model\FileReleaseType; +use Aternos\CurseForgeApi\Model\Game as GameModel; use Aternos\CurseForgeApi\Model\GameVersion; use Aternos\CurseForgeApi\Model\GameVersionsByTypeV2; +use Aternos\CurseForgeApi\Model\GameVersionType as GameVersionTypeModel; +use Aternos\CurseForgeApi\Model\Mod as ModModel; use Aternos\CurseForgeApi\Model\ModLoaderType; use Aternos\CurseForgeApi\Model\ModSearchSortField; use Aternos\CurseForgeApi\Model\PlatformType; @@ -157,7 +162,7 @@ public function testGetGames(): void $this->assertGetRequest("/v1/games", ["index" => "0", "pageSize" => "50"]); $this->assertCount(2, $games); $this->assertContainsOnlyInstancesOf(Game::class, $games->getResults()); - $this->assertSame("final-fantasy-v", $games[0]->getData()->getSlug()); + $this->assertSame("final-fantasy-v", $games[0]->getSlug()); } /** @@ -182,8 +187,10 @@ public function testGetGame(): void $game = $client->getGame(432); $this->assertGetRequest("/v1/games/432"); - $this->assertSame(432, $game->getData()->getId()); - $this->assertSame("Minecraft", $game->getData()->getName()); + $this->assertInstanceOf(GameModel::class, $game); + $this->assertSame($game, $game->getData()); + $this->assertSame(432, $game->getId()); + $this->assertSame("Minecraft", $game->getName()); } /** @@ -198,7 +205,9 @@ public function testGetGameVersionTypes(): void $this->assertGetRequest("/v1/games/432/version-types"); $this->assertCount(3, $versionTypes); $this->assertContainsOnlyInstancesOf(GameVersionType::class, $versionTypes); - $this->assertSame("Minecraft 1.1", $versionTypes[0]->getData()->getName()); + $this->assertInstanceOf(GameVersionTypeModel::class, $versionTypes[0]); + $this->assertSame($versionTypes[0], $versionTypes[0]->getData()); + $this->assertSame("Minecraft 1.1", $versionTypes[0]->getName()); } /** @@ -278,7 +287,9 @@ public function testGetCategory(): void $category = $client->getCategory(432, 435); $this->assertGetRequest("/v1/categories", ["gameId" => "432"]); - $this->assertSame("Server Utility", $category->getData()->getName()); + $this->assertInstanceOf(CategoryModel::class, $category); + $this->assertSame($category, $category->getData()); + $this->assertSame("Server Utility", $category->getName()); } /** @@ -304,8 +315,8 @@ public function testSearchMods(): void $this->assertCount(2, $mods); $this->assertContainsOnlyInstancesOf(Mod::class, $mods->getResults()); $this->assertSame(2, $mods->getPagination()->getTotalCount()); - $this->assertSame("mclo-gs", $mods[0]->getData()->getSlug()); - $this->assertSame("mclogs", $mods[1]->getData()->getSlug()); + $this->assertSame("mclo-gs", $mods[0]->getSlug()); + $this->assertSame("mclogs", $mods[1]->getSlug()); } /** @@ -380,11 +391,30 @@ public function testGetMod(): void $mod = $client->getMod(420561); $this->assertGetRequest("/v1/mods/420561"); - $this->assertSame(420561, $mod->getData()->getId()); - $this->assertSame("mclo-gs", $mod->getData()->getSlug()); - $this->assertSame("Mclogs - mclo.gs", $mod->getData()->getName()); - $this->assertSame(6, $mod->getData()->getClassId()); - $this->assertSame(435, $mod->getData()->getPrimaryCategoryId()); + $this->assertInstanceOf(ModModel::class, $mod); + $this->assertSame($mod, $mod->getData()); + $this->assertSame(420561, $mod->getId()); + $this->assertSame("mclo-gs", $mod->getSlug()); + $this->assertSame("Mclogs - mclo.gs", $mod->getName()); + $this->assertSame(6, $mod->getClassId()); + $this->assertSame(435, $mod->getPrimaryCategoryId()); + } + + /** + * Wrappers are serialized like the generated model, without the client. + * + * @throws ApiException + */ + public function testWrapperIsSerializedLikeModel(): void + { + $client = $this->createClient([new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getMod.json"))]); + + $mod = $client->getMod(420561); + + $json = json_decode(json_encode($mod), true); + $this->assertSame(420561, $json["id"]); + $this->assertSame("mclo-gs", $json["slug"]); + $this->assertArrayNotHasKey("client", $json); } /** @@ -399,7 +429,7 @@ public function testGetMods(): void $this->assertPostRequest("/v1/mods", ["modIds" => [420561, 278568, 715033], "devModIds" => [], "filterPcOnly" => null]); $this->assertCount(3, $mods); $this->assertContainsOnlyInstancesOf(Mod::class, $mods); - $this->assertSame(["mclo-gs", "mclogs", "motd-gg"], array_map(fn(Mod $mod) => $mod->getData()->getSlug(), $mods)); + $this->assertSame(["mclo-gs", "mclogs", "motd-gg"], array_map(fn(Mod $mod) => $mod->getSlug(), $mods)); } /** @@ -424,7 +454,7 @@ public function testGetFeaturedMods(): void $featuredMods = $client->getFeaturedMods(432); $this->assertPostRequest("/v1/mods/featured", ["gameId" => 432, "excludedModIds" => [], "gameVersionTypeId" => null]); - $slugs = fn(array $mods) => array_map(fn(Mod $mod) => $mod->getData()->getSlug(), $mods); + $slugs = fn(array $mods) => array_map(fn(Mod $mod) => $mod->getSlug(), $mods); $this->assertSame(["complex-cobblemon", "cobblemon-gg"], $slugs($featuredMods->getFeatured())); $this->assertSame(["geckolib", "jei"], $slugs($featuredMods->getPopular())); $this->assertSame(["aspects-reclaimed", "pixelcrystaloptimizer"], $slugs($featuredMods->getRecentlyUpdated())); @@ -487,8 +517,8 @@ public function testGetModFiles(): void $this->assertCount(2, $files); $this->assertContainsOnlyInstancesOf(File::class, $files->getResults()); $this->assertSame(117, $files->getPagination()->getTotalCount()); - $this->assertSame("mclogs-neoforge-26.1-3.3.4.jar", $files[0]->getData()->getFileName()); - $this->assertSame("mclogs-fabric-26.1-3.3.4.jar", $files[1]->getData()->getFileName()); + $this->assertSame("mclogs-neoforge-26.1-3.3.4.jar", $files[0]->getFileName()); + $this->assertSame("mclogs-fabric-26.1-3.3.4.jar", $files[1]->getFileName()); } /** @@ -547,12 +577,14 @@ public function testGetModFile(): void $file = $client->getModFile(420561, 8946029); $this->assertGetRequest("/v1/mods/420561/files/8946029"); - $this->assertSame(8946029, $file->getData()->getId()); - $this->assertSame(420561, $file->getData()->getModId()); - $this->assertSame("mclogs-integration 3.3.4", $file->getData()->getDisplayName()); - $this->assertSame("mclogs-neoforge-26.1-3.3.4.jar", $file->getData()->getFileName()); - $this->assertSame(FileReleaseType::RELEASE, $file->getData()->getReleaseType()); - $this->assertSame(317339, $file->getData()->getFileLength()); + $this->assertInstanceOf(FileModel::class, $file); + $this->assertSame($file, $file->getData()); + $this->assertSame(8946029, $file->getId()); + $this->assertSame(420561, $file->getModId()); + $this->assertSame("mclogs-integration 3.3.4", $file->getDisplayName()); + $this->assertSame("mclogs-neoforge-26.1-3.3.4.jar", $file->getFileName()); + $this->assertSame(FileReleaseType::RELEASE, $file->getReleaseType()); + $this->assertSame(317339, $file->getFileLength()); } /** @@ -567,7 +599,7 @@ public function testGetFiles(): void $this->assertPostRequest("/v1/mods/files", ["fileIds" => [8946029, 8946028]]); $this->assertCount(2, $files); $this->assertContainsOnlyInstancesOf(File::class, $files); - $this->assertSame([8946029, 8946028], array_map(fn(File $file) => $file->getData()->getId(), $files)); + $this->assertSame([8946029, 8946028], array_map(fn(File $file) => $file->getId(), $files)); } /** From 42958329adb196c9883b045803272924bb9777c0 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Mon, 19 Oct 2026 13:47:19 +0200 Subject: [PATCH 2/2] remove getData() from the wrappers --- src/Client/Category.php | 9 --------- src/Client/File.php | 9 --------- src/Client/Game.php | 9 --------- src/Client/GameVersionType.php | 9 --------- src/Client/Mod.php | 9 --------- tests/Unit/Client/CurseForgeAPIClientTest.php | 5 ----- 6 files changed, 50 deletions(-) diff --git a/src/Client/Category.php b/src/Client/Category.php index 2251496..22c852c 100644 --- a/src/Client/Category.php +++ b/src/Client/Category.php @@ -17,15 +17,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The category extends the generated model now, so its getters can be used directly. - * @return CategoryModel - */ - public function getData(): CategoryModel - { - return $this; - } - /** * Search mods in this category * @param ModSearchOptions|null $options diff --git a/src/Client/File.php b/src/Client/File.php index 583572e..63a4fca 100644 --- a/src/Client/File.php +++ b/src/Client/File.php @@ -15,15 +15,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The file extends the generated model now, so its getters can be used directly. - * @return FileModel - */ - public function getData(): FileModel - { - return $this; - } - /** * Get the server pack file for this version (if it exists) * @return File|null diff --git a/src/Client/Game.php b/src/Client/Game.php index 049d804..a6f36a4 100644 --- a/src/Client/Game.php +++ b/src/Client/Game.php @@ -23,15 +23,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The game extends the generated model now, so its getters can be used directly. - * @return GameModel - */ - public function getData(): GameModel - { - return $this; - } - /** * Get all version types for this game * @return GameVersionType[] diff --git a/src/Client/GameVersionType.php b/src/Client/GameVersionType.php index 2c14865..e6da35d 100644 --- a/src/Client/GameVersionType.php +++ b/src/Client/GameVersionType.php @@ -16,15 +16,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The game version type extends the generated model now, so its getters can be used directly. - * @return GameVersionTypeModel - */ - public function getData(): GameVersionTypeModel - { - return $this; - } - /** * Get all versions of this type * @return GameVersionsByTypeV2[] diff --git a/src/Client/Mod.php b/src/Client/Mod.php index 665140a..c4923ea 100644 --- a/src/Client/Mod.php +++ b/src/Client/Mod.php @@ -27,15 +27,6 @@ public static function fromModels(CurseForgeAPIClient $client, array $models): a return array_map(fn($mod) => new Mod($client, $mod), $models); } - /** - * @deprecated The mod extends the generated model now, so its getters can be used directly. - * @return ModModel - */ - public function getData(): ModModel - { - return $this; - } - /** * Fetch the description of this mod as html * @param string|null $lang diff --git a/tests/Unit/Client/CurseForgeAPIClientTest.php b/tests/Unit/Client/CurseForgeAPIClientTest.php index 7225d2b..4173355 100644 --- a/tests/Unit/Client/CurseForgeAPIClientTest.php +++ b/tests/Unit/Client/CurseForgeAPIClientTest.php @@ -188,7 +188,6 @@ public function testGetGame(): void $this->assertGetRequest("/v1/games/432"); $this->assertInstanceOf(GameModel::class, $game); - $this->assertSame($game, $game->getData()); $this->assertSame(432, $game->getId()); $this->assertSame("Minecraft", $game->getName()); } @@ -206,7 +205,6 @@ public function testGetGameVersionTypes(): void $this->assertCount(3, $versionTypes); $this->assertContainsOnlyInstancesOf(GameVersionType::class, $versionTypes); $this->assertInstanceOf(GameVersionTypeModel::class, $versionTypes[0]); - $this->assertSame($versionTypes[0], $versionTypes[0]->getData()); $this->assertSame("Minecraft 1.1", $versionTypes[0]->getName()); } @@ -288,7 +286,6 @@ public function testGetCategory(): void $this->assertGetRequest("/v1/categories", ["gameId" => "432"]); $this->assertInstanceOf(CategoryModel::class, $category); - $this->assertSame($category, $category->getData()); $this->assertSame("Server Utility", $category->getName()); } @@ -392,7 +389,6 @@ public function testGetMod(): void $this->assertGetRequest("/v1/mods/420561"); $this->assertInstanceOf(ModModel::class, $mod); - $this->assertSame($mod, $mod->getData()); $this->assertSame(420561, $mod->getId()); $this->assertSame("mclo-gs", $mod->getSlug()); $this->assertSame("Mclogs - mclo.gs", $mod->getName()); @@ -578,7 +574,6 @@ public function testGetModFile(): void $this->assertGetRequest("/v1/mods/420561/files/8946029"); $this->assertInstanceOf(FileModel::class, $file); - $this->assertSame($file, $file->getData()); $this->assertSame(8946029, $file->getId()); $this->assertSame(420561, $file->getModId()); $this->assertSame("mclogs-integration 3.3.4", $file->getDisplayName());