From 0ecc61fe9efabc05d3b7fe674417e39cea8bf409 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:26:26 -0400 Subject: [PATCH] refactor: import instead of FQDN --- src/Appwrite/GraphQL/Schema.php | 4 ++-- src/Appwrite/Platform/Tasks/Specs.php | 3 ++- src/Appwrite/Utopia/Response.php | 7 ++++--- tests/unit/GraphQL/BuilderTest.php | 7 ++++--- tests/unit/Utopia/ResponseTest.php | 7 ++++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/GraphQL/Schema.php b/src/Appwrite/GraphQL/Schema.php index 1ffd6edf91..2b05f08aee 100644 --- a/src/Appwrite/GraphQL/Schema.php +++ b/src/Appwrite/GraphQL/Schema.php @@ -3,7 +3,7 @@ namespace Appwrite\GraphQL; use Appwrite\GraphQL\Types\Mapper; -use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Models; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use GraphQL\Type\Schema as GQLSchema; @@ -98,7 +98,7 @@ class Schema */ protected function api(Http $http, Request $request, UtopiaHttpResponse $response, Container $container, callable $complexity): array { - Mapper::init(Response\Models::getModels()); + Mapper::init(Models::getModels()); $mapper = new Mapper(); diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 7dfbb25786..77ae26ec95 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -6,6 +6,7 @@ use Appwrite\Specification\Format\OpenAPI3; use Appwrite\Specification\Format\Swagger2; use Appwrite\Specification\Specification; use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Models; use Exception; use Swoole\Http\Request as SwooleHttpRequest; use Swoole\Http\Response as SwooleHttpResponse; @@ -256,7 +257,7 @@ class Specs extends Action ]; } - $models = Response\Models::getModels(); + $models = Models::getModels(); foreach ($models as $key => $value) { if ($platform !== APP_PLATFORM_CONSOLE && !$value->isPublic()) { diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 7a3ab850a3..3808b1e9f8 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -4,6 +4,7 @@ namespace Appwrite\Utopia; use Appwrite\Utopia\Fetch\BodyMultipart; use Appwrite\Utopia\Response\Filter; +use Appwrite\Utopia\Response\Models; use Exception; use JsonException; // Keep last @@ -306,7 +307,7 @@ class Response extends HttpResponse public function output(Document $document, string $model): array { $data = clone $document; - $model = Response\Models::getModel($model); + $model = Models::getModel($model); $output = []; $data = $model->filter($data); @@ -336,7 +337,7 @@ class Response extends HttpResponse if (\is_array($rule['type'])) { foreach ($rule['type'] as $type) { $condition = false; - foreach (Response\Models::getModel($type)->conditions as $attribute => $val) { + foreach (Models::getModel($type)->conditions as $attribute => $val) { $condition = $item->getAttribute($attribute) === $val; if (!$condition) { break; @@ -351,7 +352,7 @@ class Response extends HttpResponse $ruleType = $rule['type']; } - if (!array_key_exists($ruleType, Response\Models::getModels())) { + if (!array_key_exists($ruleType, Models::getModels())) { throw new Exception('Missing model for rule: ' . $ruleType); } diff --git a/tests/unit/GraphQL/BuilderTest.php b/tests/unit/GraphQL/BuilderTest.php index 348b7ac4a4..f11045f318 100644 --- a/tests/unit/GraphQL/BuilderTest.php +++ b/tests/unit/GraphQL/BuilderTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\GraphQL; use Appwrite\GraphQL\Types\Mapper; use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Models; use PHPUnit\Framework\TestCase; use Swoole\Http\Response as SwooleResponse; use Utopia\Http\Adapter\Swoole\Response as UtopiaSwooleResponse; @@ -14,9 +15,9 @@ class BuilderTest extends TestCase public function setUp(): void { - Response\Models::init(); + Models::init(); $this->response = new Response(new UtopiaSwooleResponse(new SwooleResponse())); - Mapper::init(Response\Models::getModels()); + Mapper::init(Models::getModels()); } /** @@ -24,7 +25,7 @@ class BuilderTest extends TestCase */ public function testCreateTypeMapping() { - $model = Response\Models::getModel(Response::MODEL_COLLECTION); + $model = Models::getModel(Response::MODEL_COLLECTION); $type = Mapper::model(\ucfirst($model->getType())); $this->assertEquals('Collection', $type->name); } diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index 9ab61cb4f0..1cd02beb2c 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\Utopia; use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Models; use Exception; use PHPUnit\Framework\TestCase; use Swoole\Http\Response as SwooleResponse; @@ -18,9 +19,9 @@ class ResponseTest extends TestCase public function setUp(): void { $this->response = new Response(new UtopiaSwooleResponse(new SwooleResponse())); - Response\Models::setModel(new Single()); - Response\Models::setModel(new Lists()); - Response\Models::setModel(new Nested()); + Models::setModel(new Single()); + Models::setModel(new Lists()); + Models::setModel(new Nested()); } public function testFilters(): void