diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b74b0c3adc..15c0ff9e97 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -392,7 +392,7 @@ App::post('/v1/account') $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if($existingTarget) { + if ($existingTarget) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 77e70972ad..ada3b785d7 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -296,7 +296,7 @@ App::post('/v1/functions') if (!empty($providerRepositoryId)) { // Deploy VCS $redeployVcs($request, $function, $project, $installation, $dbForProject, $queueForBuilds, $template, $github); - } elseif(!$template->isEmpty()) { + } elseif (!$template->isEmpty()) { // Deploy non-VCS from template $deploymentId = ID::unique(); $deployment = $dbForProject->createDocument('deployments', new Document([ @@ -1581,7 +1581,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/build') } $path = $deployment->getAttribute('path'); - if(empty($path) || !$deviceForFunctions->exists($path)) { + if (empty($path) || !$deviceForFunctions->exists($path)) { throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } @@ -1735,7 +1735,7 @@ App::post('/v1/functions/:functionId/executions') ->inject('geodb') ->action(function (string $functionId, string $body, bool $async, string $path, string $method, mixed $headers, ?string $scheduledAt, Response $response, Request $request, Document $project, Database $dbForProject, Database $dbForConsole, Document $user, Event $queueForEvents, Usage $queueForUsage, Func $queueForFunctions, Reader $geodb) { - if(!$async && !is_null($scheduledAt)) { + if (!$async && !is_null($scheduledAt)) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Scheduled executions must run asynchronously. Set scheduledAt to a future date, or set async to true.'); } @@ -1868,7 +1868,7 @@ App::post('/v1/functions/:functionId/executions') $status = $async ? 'waiting' : 'processing'; - if(!is_null($scheduledAt)) { + if (!is_null($scheduledAt)) { $status = 'scheduled'; } @@ -1898,7 +1898,7 @@ App::post('/v1/functions/:functionId/executions') ->setContext('function', $function); if ($async) { - if(is_null($scheduledAt)) { + if (is_null($scheduledAt)) { $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); $queueForFunctions ->setType('http') @@ -2077,7 +2077,7 @@ App::post('/v1/functions/:functionId/executions') $acceptTypes = \explode(', ', $request->getHeader('accept')); foreach ($acceptTypes as $acceptType) { - if(\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) { + if (\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) { $response->setContentType(Response::CONTENT_TYPE_JSON); break; } elseif (\str_starts_with($acceptType, 'multipart/form-data') || \str_starts_with($acceptType, 'multipart/*')) { diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 78988f525b..081e6a85bd 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$email]), ]); - if($existingTarget) { + if ($existingTarget) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e $existingTarget = $dbForProject->findOne('targets', [ Query::equal('identifier', [$phone]), ]); - if($existingTarget) { + if ($existingTarget) { $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); } } @@ -2124,7 +2124,7 @@ App::post('/v1/users/:userId/jwts') $sessions = $user->getAttribute('sessions', []); $session = new Document(); - if($sessionId === 'recent') { + if ($sessionId === 'recent') { // Get most recent $session = \count($sessions) > 0 ? $sessions[\count($sessions) - 1] : new Document(); } else { diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 299e2836f7..9610f44ace 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -509,7 +509,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro $vcsContents = []; foreach ($contents as $content) { $isDirectory = false; - if($content['type'] === GitHub::CONTENTS_DIRECTORY) { + if ($content['type'] === GitHub::CONTENTS_DIRECTORY) { $isDirectory = true; } diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index eacea06de0..0cb88d31fa 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -207,14 +207,14 @@ App::init() } // Remove after migration - if(!\str_contains($apiKey, '_')) { + if (!\str_contains($apiKey, '_')) { $keyType = API_KEY_STANDARD; $authKey = $apiKey; } else { [ $keyType, $authKey ] = \explode('_', $apiKey, 2); } - if($keyType === API_KEY_DYNAMIC) { + if ($keyType === API_KEY_DYNAMIC) { // Dynamic key $jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 0); @@ -244,7 +244,7 @@ App::init() Authorization::setRole(Auth::USER_ROLE_APPS); Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys. } - } elseif($keyType === API_KEY_STANDARD) { + } elseif ($keyType === API_KEY_STANDARD) { // No underline means no prefix. Backwards compatibility. // Regular key diff --git a/app/init.php b/app/init.php index 08cb09b68b..2a5e29803c 100644 --- a/app/init.php +++ b/app/init.php @@ -791,7 +791,7 @@ $register->set('logger', function () { $adapter = null; } - if($adapter === null) { + if ($adapter === null) { Console::error("Logging provider not supported. Logging is disabled"); return; } @@ -1267,7 +1267,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons } $jwtSessionId = $payload['sessionId'] ?? ''; - if(!empty($jwtSessionId)) { + if (!empty($jwtSessionId)) { if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token $user = new Document([]); } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 884296ff67..e0cf8058c9 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -313,7 +313,7 @@ class Exception extends \Exception $this->code = $code ?? $this->errors[$type]['code']; // Mark string errors like HY001 from PDO as 500 errors - if(\is_string($this->code)) { + if (\is_string($this->code)) { if (\is_numeric($this->code)) { $this->code = (int) $this->code; } else { diff --git a/src/Appwrite/Functions/Validator/Headers.php b/src/Appwrite/Functions/Validator/Headers.php index 6d5b2da5df..04003d535b 100644 --- a/src/Appwrite/Functions/Validator/Headers.php +++ b/src/Appwrite/Functions/Validator/Headers.php @@ -44,7 +44,7 @@ class Headers extends Validator return false; } - if(\count($value) > $this->maxKeys) { + if (\count($value) > $this->maxKeys) { return false; } @@ -57,7 +57,7 @@ class Headers extends Validator } $size += $length + \strlen($val); - if($size >= $this->maxSize) { + if ($size >= $this->maxSize) { return false; } diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index d8359f5f65..2b8acf8177 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -208,7 +208,7 @@ class Builds extends Action } try { - if($isNewBuild && !$isVcsEnabled) { + if ($isNewBuild && !$isVcsEnabled) { // Non-vcs+Template $templateRepositoryName = $template->getAttribute('repositoryName', ''); @@ -279,7 +279,7 @@ class Builds extends Action $cloneVersion = $branchName; $cloneType = GitHub::CLONE_TYPE_BRANCH; - if(!empty($commitHash)) { + if (!empty($commitHash)) { $cloneVersion = $commitHash; $cloneType = GitHub::CLONE_TYPE_COMMIT; } @@ -543,7 +543,7 @@ class Builds extends Action deploymentId: $deployment->getId(), projectId: $project->getId(), callback: function ($logs) use (&$response, &$err, &$build, $dbForProject, $allEvents, $project, &$isCanceled) { - if($isCanceled) { + if ($isCanceled) { return; } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 6f642fabb7..0f0d298e3b 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -669,7 +669,7 @@ class Messaging extends Action private function getLocalDevice($project): Local { - if($this->localDevice === null) { + if ($this->localDevice === null) { $this->localDevice = new Local(APP_STORAGE_UPLOADS . '/app-' . $project->getId()); } diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 4595a4cb6c..2eab7807b3 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -287,7 +287,7 @@ class Swagger2 extends Format } $validatorClass = (!empty($validator)) ? \get_class($validator) : ''; - if($validatorClass === 'Utopia\Validator\AnyOf') { + if ($validatorClass === 'Utopia\Validator\AnyOf') { $validator = $param['validator']->getValidators()[0]; $validatorClass = \get_class($validator); } diff --git a/src/Appwrite/Utopia/Response/Filters/V16.php b/src/Appwrite/Utopia/Response/Filters/V16.php index 2a27715d5e..7eb3ec6eb3 100644 --- a/src/Appwrite/Utopia/Response/Filters/V16.php +++ b/src/Appwrite/Utopia/Response/Filters/V16.php @@ -33,13 +33,13 @@ class V16 extends Filter protected function parseDeployment(array $content) { - if(isset($content['buildLogs'])) { + if (isset($content['buildLogs'])) { $content['buildStderr'] = ''; $content['buildStdout'] = $content['buildLogs']; unset($content['buildLogs']); } - if(isset($content['buildSize'])) { + if (isset($content['buildSize'])) { $content['size'] += + $content['buildSize'] ?? 0; unset($content['buildSize']); } diff --git a/src/Appwrite/Utopia/Response/Filters/V18.php b/src/Appwrite/Utopia/Response/Filters/V18.php index 0a74a2afed..fc1624a289 100644 --- a/src/Appwrite/Utopia/Response/Filters/V18.php +++ b/src/Appwrite/Utopia/Response/Filters/V18.php @@ -25,8 +25,8 @@ class V18 extends Filter protected function parseExecution(array $content) { - if(!empty($content['status']) && !empty($content['statusCode'])) { - if($content['status'] === 'completed' && $content['statusCode'] >= 400 && $content['statusCode'] < 500) { + if (!empty($content['status']) && !empty($content['statusCode'])) { + if ($content['status'] === 'completed' && $content['statusCode'] >= 400 && $content['statusCode'] < 500) { $content['status'] = 'failed'; } } diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index 242af6926f..41a10cee89 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -72,7 +72,8 @@ class Document extends Any public function filter(DatabaseDocument $document): DatabaseDocument { $document->removeAttribute('$internalId'); - $document->removeAttribute('$collection'); // $collection is the internal collection ID + $document->removeAttribute('$collection'); + $document->removeAttribute('$tenant'); foreach ($document->getAttributes() as $attribute) { if (\is_array($attribute)) { diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 7cd239623c..c230cfb664 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -217,7 +217,7 @@ class Executor 'restartPolicy' => 'always' // Once utopia/orchestration has it, use DockerAPI::ALWAYS (0.13+) ]; - if(!empty($body)) { + if (!empty($body)) { $params['body'] = $body; } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 6ebd95aa5d..04f2dbd8c8 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1593,6 +1593,7 @@ trait DatabasesBase $this->assertEquals($response['body']['$permissions'], $document['$permissions']); $this->assertEquals($response['body']['birthDay'], $document['birthDay']); $this->assertFalse(array_key_exists('$internalId', $response['body'])); + $this->assertFalse(array_key_exists('$tenant', $response['body'])); } } diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index abefb5c9a3..2d94b9f0e3 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -34,7 +34,7 @@ trait FunctionsBase \sleep(1); } - if($checkForSuccess) { + if ($checkForSuccess) { $this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body'])); } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0607f40924..912a7a3f2c 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1072,7 +1072,7 @@ class FunctionsCustomServerTest extends Scope $found = false; foreach ($response['body']['deployments'] as $deployment) { - if($deployment['$id'] === $deploymentId) { + if ($deployment['$id'] === $deploymentId) { $found = true; $this->assertEquals($deploymentSize, $deployment['size']); break; diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index 6f6b36c520..6be3e16c1f 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -31,7 +31,7 @@ trait WebhooksBase \sleep(1); } - if($checkForSuccess) { + if ($checkForSuccess) { $this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body'])); } diff --git a/tests/unit/Functions/Validator/HeadersBench.php b/tests/unit/Functions/Validator/HeadersBench.php index e1f9fcc5ff..f95fa65f9b 100644 --- a/tests/unit/Functions/Validator/HeadersBench.php +++ b/tests/unit/Functions/Validator/HeadersBench.php @@ -27,19 +27,19 @@ final class HeadersBench yield 'empty' => [ 'value' => [] ]; $value = []; - for($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; $i++) { $value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8)); } yield 'items_10-size_320' => [ 'value' => $value ]; $value = []; - for($i = 0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8)); } yield 'items_100-size_3200' => [ 'value' => $value ]; $value = []; - for($i = 0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $value[bin2hex(random_bytes(32))] = bin2hex(random_bytes(32)); } yield 'items_100-size_12800' => [ 'value' => $value ]; @@ -53,7 +53,7 @@ final class HeadersBench public function benchHeadersValidator(array $data): void { $assertion = $this->validator->isValid($data['value']); - if(!$assertion) { + if (!$assertion) { exit(1); } } diff --git a/tests/unit/Functions/Validator/HeadersTest.php b/tests/unit/Functions/Validator/HeadersTest.php index c9373c5991..4a45f57427 100644 --- a/tests/unit/Functions/Validator/HeadersTest.php +++ b/tests/unit/Functions/Validator/HeadersTest.php @@ -109,7 +109,7 @@ class HeadersTest extends TestCase $this->assertTrue($this->object->isValid($headers)); $headers = []; - for($i = 0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $headers['key-' . $i] = 'value_' . $i; } $this->assertTrue($this->object->isValid($headers));