From 39f2d249078b9e6bccd5561619f73242596ace6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 23 Mar 2026 16:10:12 +0100 Subject: [PATCH] AI code review fixes --- app/config/errors.php | 5 +++++ src/Appwrite/Extend/Exception.php | 1 + .../Project/Http/Project/Platforms/App/Create.php | 4 ++-- .../Project/Http/Project/Platforms/App/Update.php | 10 ++++++++-- .../Project/Http/Project/Platforms/Web/Create.php | 4 ++-- .../Project/Http/Project/Platforms/Web/Update.php | 8 +++++++- src/Appwrite/Utopia/Response/Model/PlatformApp.php | 2 +- src/Appwrite/Utopia/Response/Model/PlatformList.php | 2 +- src/Appwrite/Utopia/Response/Model/PlatformWeb.php | 2 +- src/Appwrite/Utopia/Response/Model/Project.php | 5 ++++- 10 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 3af9d9b4a7..cb63737af8 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -1164,6 +1164,11 @@ return [ 'description' => 'Platform with the requested ID could not be found.', 'code' => 404, ], + Exception::PLATFORM_METHOD_UNSUPPORTED => [ + 'name' => Exception::PLATFORM_METHOD_UNSUPPORTED, + 'description' => 'The requested platform has invalid type. Please use coresponding update method for the platform type.', + 'code' => 400, + ], Exception::PLATFORM_ALREADY_EXISTS => [ 'name' => Exception::PLATFORM_ALREADY_EXISTS, 'description' => 'Platform with the same ID already exists in this project. Try again with a different ID.', diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 91f9e94341..591fbfb936 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -330,6 +330,7 @@ class Exception extends \Exception /** Platform */ public const string PLATFORM_NOT_FOUND = 'platform_not_found'; + public const string PLATFORM_METHOD_UNSUPPORTED = 'platform_method_unsupported'; public const string PLATFORM_ALREADY_EXISTS = 'platform_already_exists'; /** GraphqQL */ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Create.php index 860f080b93..7fdd8adcff 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Create.php @@ -86,7 +86,7 @@ class Create extends Base new WhiteList($this->getSupportedTypes(), true), 'Platform type. Possible values are: ' . implode(', ', $this->getSupportedTypes()) ) - ->param('identifier', '', new Text(256), 'Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.', true) + ->param('identifier', '', new Text(256), 'Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.') ->inject('response') ->inject('queueForEvents') ->inject('project') @@ -109,7 +109,7 @@ class Create extends Base $platformId = ($platformId == 'unique()') ? ID::unique() : $platformId; $platform = new Document([ - '$id' => ID::unique(), + '$id' => $platformId, '$permissions' => [], 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Update.php index e84d750401..19a1b501aa 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/App/Update.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Project\Http\Project\Platforms\App; use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; +use Appwrite\Platform\Modules\Project\Http\Project\Platforms\App\Create as AppPlatformCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -54,7 +55,7 @@ class Update extends Base )) ->param('platformId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Platform ID.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Platform name. Max length: 128 chars.') - ->param('identifier', '', new Text(256), 'Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.', true) + ->param('identifier', '', new Text(256), 'Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.') ->inject('response') ->inject('queueForEvents') ->inject('dbForPlatform') @@ -79,9 +80,14 @@ class Update extends Base throw new Exception(Exception::PLATFORM_NOT_FOUND); } + $appPlatforms = AppPlatformCreate::getSupportedTypes(); + if (!\in_array($platform->getAttribute('type', ''), $appPlatforms)) { + throw new Exception(Exception::PLATFORM_METHOD_UNSUPPORTED); + } + $updates = new Document([ 'name' => $name, - 'identifier' => $identifier, + 'key' => $identifier, ]); try { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php index 2b68164deb..851dfc5d19 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Create.php @@ -77,7 +77,7 @@ class Create extends Base new WhiteList($this->getSupportedTypes(), true), 'Platform type. Possible values are: ' . implode(', ', $this->getSupportedTypes()) ) - ->param('hostname', '', new Hostname(), 'Platform web hostname. Max length: 256 chars.', true) + ->param('hostname', '', new Hostname(), 'Platform web hostname. Max length: 256 chars.') ->inject('response') ->inject('queueForEvents') ->inject('project') @@ -100,7 +100,7 @@ class Create extends Base $platformId = ($platformId == 'unique()') ? ID::unique() : $platformId; $platform = new Document([ - '$id' => ID::unique(), + '$id' => $platformId, '$permissions' => [], 'projectInternalId' => $project->getSequence(), 'projectId' => $project->getId(), diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php index dcc91f73df..0176f1e440 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Platforms/Web/Update.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Project\Http\Project\Platforms\Web; use Appwrite\Event\Event as QueueEvent; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Compute\Base; +use Appwrite\Platform\Modules\Project\Http\Project\Platforms\Web\Create as WebPlatformCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -55,7 +56,7 @@ class Update extends Base )) ->param('platformId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Platform ID.', false, ['dbForPlatform']) ->param('name', null, new Text(128), 'Platform name. Max length: 128 chars.') - ->param('hostname', '', new Hostname(), 'Platform client hostname. Max length: 256 chars.', true) + ->param('hostname', '', new Hostname(), 'Platform client hostname. Max length: 256 chars.') ->inject('response') ->inject('queueForEvents') ->inject('dbForPlatform') @@ -80,6 +81,11 @@ class Update extends Base throw new Exception(Exception::PLATFORM_NOT_FOUND); } + $webPlatforms = WebPlatformCreate::getSupportedTypes(); + if (!\in_array($platform->getAttribute('type', ''), $webPlatforms)) { + throw new Exception(Exception::PLATFORM_METHOD_UNSUPPORTED); + } + $updates = new Document([ 'name' => $name, 'hostname' => $hostname, diff --git a/src/Appwrite/Utopia/Response/Model/PlatformApp.php b/src/Appwrite/Utopia/Response/Model/PlatformApp.php index 941ab214a7..6256849f2f 100644 --- a/src/Appwrite/Utopia/Response/Model/PlatformApp.php +++ b/src/Appwrite/Utopia/Response/Model/PlatformApp.php @@ -40,7 +40,7 @@ class PlatformApp extends PlatformBase 'description' => 'Platform type. Possible values are: ' . implode(', ', $this->getSupportedTypes()) . '.', 'default' => '', 'example' => NetworkPlatform::TYPE_APPLE_IOS, - 'enum' => [$this->getSupportedTypes()], + 'enum' => $this->getSupportedTypes(), ]) ->addRule('identifier', [ 'type' => self::TYPE_STRING, diff --git a/src/Appwrite/Utopia/Response/Model/PlatformList.php b/src/Appwrite/Utopia/Response/Model/PlatformList.php index 5f9b6bcd95..91a4d98fb6 100644 --- a/src/Appwrite/Utopia/Response/Model/PlatformList.php +++ b/src/Appwrite/Utopia/Response/Model/PlatformList.php @@ -12,7 +12,7 @@ class PlatformList extends Model $this ->addRule('total', [ 'type' => self::TYPE_INTEGER, - 'description' => 'Total number of platforms in the given table.', + 'description' => 'Total number of platforms in the given project.', 'default' => 0, 'example' => 5, ]) diff --git a/src/Appwrite/Utopia/Response/Model/PlatformWeb.php b/src/Appwrite/Utopia/Response/Model/PlatformWeb.php index 1bd28fb15a..9de4f8e245 100644 --- a/src/Appwrite/Utopia/Response/Model/PlatformWeb.php +++ b/src/Appwrite/Utopia/Response/Model/PlatformWeb.php @@ -29,7 +29,7 @@ class PlatformWeb extends PlatformBase 'description' => 'Platform type. Possible values are: ' . implode(', ', $this->getSupportedTypes()) . '.', 'default' => '', 'example' => NetworkPlatform::TYPE_WEB, - 'enum' => [$this->getSupportedTypes()], + 'enum' => $this->getSupportedTypes(), ]) ->addRule('hostname', [ 'type' => self::TYPE_STRING, diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index cd33a29685..e515a7ae1b 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -182,7 +182,10 @@ class Project extends Model 'array' => true, ]) ->addRule('platforms', [ - 'type' => Response::MODEL_PLATFORM, + 'type' => [ + Response::MODEL_PLATFORM_WEB, + Response::MODEL_PLATFORM_APP, + ], 'description' => 'List of Platforms.', 'default' => [], 'example' => new \stdClass(),