From 5b16d56b850ef5de7bd4b217043945ba25f7bb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 27 Sep 2024 16:18:40 +0000 Subject: [PATCH] Finish fixing phpstan errors --- app/cli.php | 5 +++++ app/controllers/api/account.php | 16 ++++++++++++---- app/controllers/api/avatars.php | 3 --- app/controllers/api/databases.php | 7 ++++--- app/controllers/api/functions.php | 7 +++---- app/controllers/api/health.php | 12 ++++++------ app/controllers/api/locale.php | 2 ++ app/controllers/api/messaging.php | 9 ++++++--- app/controllers/api/project.php | 2 -- app/controllers/api/storage.php | 12 ++++-------- app/controllers/api/teams.php | 4 +++- app/controllers/api/users.php | 2 ++ app/controllers/api/vcs.php | 4 ---- app/controllers/general.php | 7 ++++++- app/controllers/mock.php | 2 ++ app/controllers/shared/api/auth.php | 1 + app/http.php | 6 +++++- app/worker.php | 4 ++-- composer.json | 2 +- composer.lock | 21 ++++++++++----------- src/Appwrite/Promises/Promise.php | 2 +- src/Appwrite/Promises/Swoole.php | 5 ----- src/Appwrite/Utopia/Response.php | 2 +- 23 files changed, 76 insertions(+), 61 deletions(-) diff --git a/app/cli.php b/app/cli.php index ecff5180a2..b384620319 100644 --- a/app/cli.php +++ b/app/cli.php @@ -23,6 +23,8 @@ use Utopia\Queue\Connection; use Utopia\Registry\Registry; use Utopia\System\System; +/** @var Utopia\Registry\Registry $register */ + // overwriting runtimes to be architectur agnostic for CLI Config::setParam('runtimes', (new Runtimes('v4'))->getAll(supported: false)); @@ -57,6 +59,7 @@ CLI::setResource('dbForConsole', function ($pools, $cache) { $maxAttempts = 5; $attempts = 0; $ready = false; + $dbForConsole = null; do { $attempts++; @@ -90,6 +93,8 @@ CLI::setResource('dbForConsole', function ($pools, $cache) { } } while ($attempts < $maxAttempts && !$ready); + /** @var Utopia\Database\Database $dbForConsole */ + if (!$ready) { throw new Exception("Console is not ready yet. Please try again later."); } diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 64441fee5c..72d075ab53 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -144,7 +144,7 @@ function sendSessionAlert(Locale $locale, Document $user, Document $project, Doc ->trigger(); }; - +// @phpstan-ignore class.notFound $createSession = function (string $userId, string $secret, Request $request, Response $response, Document $user, Database $dbForProject, Document $project, Locale $locale, Reader $geodb, Event $queueForEvents, Mail $queueForMails) { $roles = Authorization::getRoles(); $isPrivilegedUser = Auth::isPrivilegedUser($roles); @@ -581,13 +581,14 @@ App::delete('/v1/account/sessions') ->setDocument($session) ->trigger(); } + + $queueForEvents + ->setParam('userId', $user->getId()) + ->setParam('sessionId', $session->getId()); // TODO: Trigger for all sessions } $dbForProject->purgeCachedDocument('users', $user->getId()); - $queueForEvents - ->setParam('userId', $user->getId()) - ->setParam('sessionId', $session->getId()); $response->noContent(); }); @@ -825,6 +826,7 @@ App::post('/v1/account/sessions/email') ->inject('queueForEvents') ->inject('queueForMails') ->inject('hooks') + // @phpstan-ignore class.notFound ->action(function (string $email, string $password, Request $request, Response $response, Document $user, Database $dbForProject, Document $project, Locale $locale, Reader $geodb, Event $queueForEvents, Mail $queueForMails, Hooks $hooks) { $email = \strtolower($email); $protocol = $request->getProtocol(); @@ -955,6 +957,7 @@ App::post('/v1/account/sessions/anonymous') ->inject('dbForProject') ->inject('geodb') ->inject('queueForEvents') + // @phpstan-ignore class.notFound ->action(function (Request $request, Response $response, Locale $locale, Document $user, Document $project, Database $dbForProject, Reader $geodb, Event $queueForEvents) { $protocol = $request->getProtocol(); $roles = Authorization::getRoles(); @@ -1252,6 +1255,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->inject('dbForProject') ->inject('geodb') ->inject('queueForEvents') + // @phpstan-ignore class.notFound ->action(function (string $provider, string $code, string $state, string $error, string $error_description, Request $request, Response $response, Document $project, Document $user, Database $dbForProject, Reader $geodb, Event $queueForEvents) use ($oauthDefaultSuccess) { $protocol = $request->getProtocol(); $callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId(); @@ -1389,6 +1393,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') } $sessions = $user->getAttribute('sessions', []); + $session = null; $current = Auth::sessionVerify($sessions, Auth::$secret); if ($current) { // Delete current session of new one. @@ -1658,6 +1663,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')); } + /** @var Utopia\Database\Document $session */ + if (isset($sessionUpgrade) && $sessionUpgrade) { foreach ($user->getAttribute('targets', []) as $target) { if ($target->getAttribute('providerType') !== MESSAGE_TYPE_PUSH) { @@ -2554,6 +2561,7 @@ App::get('/v1/account/logs') ->inject('locale') ->inject('geodb') ->inject('dbForProject') + // @phpstan-ignore class.notFound ->action(function (array $queries, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) { try { diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index fcff3e4179..8597726c67 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -52,7 +52,6 @@ $avatarCallback = function (string $type, string $code, int $width, int $height, $image = new Image(\file_get_contents($path)); $image->crop((int) $width, (int) $height); - $output = (empty($output)) ? $type : $output; $data = $image->output($output, $quality); $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') @@ -271,7 +270,6 @@ App::get('/v1/avatars/image') } $image->crop((int) $width, (int) $height); - $output = (empty($output)) ? $type : $output; $data = $image->output($output, $quality); $response @@ -416,7 +414,6 @@ App::get('/v1/avatars/favicon') $image = new Image($data); $image->crop((int) $width, (int) $height); - $output = (empty($output)) ? $type : $output; $data = $image->output($output, $quality); $response diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index a9bb58df4b..f2d5afbb68 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -381,7 +381,7 @@ function updateAttribute( size: $size, required: $required, default: $default, - formatOptions: $options ?? null, + formatOptions: $options, newKey: $newKey ?? null ); } catch (TruncateException) { @@ -603,6 +603,7 @@ App::get('/v1/databases/:databaseId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $databaseId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $database = $dbForProject->getDocument('databases', $databaseId); @@ -942,6 +943,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -1067,8 +1069,6 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') // Map aggregate permissions into the multiple permissions they represent. $permissions = Permission::aggregate($permissions); - $enabled ??= $collection->getAttribute('enabled', true); - $collection = $dbForProject->updateDocument('database_' . $database->getInternalId(), $collectionId, $collection ->setAttribute('name', $name) ->setAttribute('$permissions', $permissions) @@ -3296,6 +3296,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $databaseId, string $collectionId, string $documentId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 9c3e6782b4..37842fac21 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -817,8 +817,6 @@ App::put('/v1/functions/:functionId') $runtime = $function->getAttribute('runtime'); } - $enabled ??= $function->getAttribute('enabled', true); - $repositoryId = $function->getAttribute('repositoryId', ''); $repositoryInternalId = $function->getAttribute('repositoryInternalId', ''); @@ -1733,6 +1731,7 @@ App::post('/v1/functions/:functionId/executions') ->inject('queueForUsage') ->inject('queueForFunctions') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $functionId, string $body, mixed $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) { $async = \strval($async) === 'true' || \strval($async) === '1'; @@ -1840,7 +1839,7 @@ App::post('/v1/functions/:functionId/executions') $headers['x-appwrite-key'] = API_KEY_DYNAMIC . '_' . $apiKey; $headers['x-appwrite-trigger'] = 'http'; $headers['x-appwrite-user-id'] = $user->getId() ?? ''; - $headers['x-appwrite-user-jwt'] = $jwt ?? ''; + $headers['x-appwrite-user-jwt'] = $jwt; $headers['x-appwrite-country-code'] = ''; $headers['x-appwrite-continent-code'] = ''; $headers['x-appwrite-continent-eu'] = 'false'; @@ -1957,7 +1956,7 @@ App::post('/v1/functions/:functionId/executions') if ($version === 'v2') { $vars = \array_merge($vars, [ 'APPWRITE_FUNCTION_TRIGGER' => $headers['x-appwrite-trigger'] ?? '', - 'APPWRITE_FUNCTION_DATA' => $body ?? '', + 'APPWRITE_FUNCTION_DATA' => $body, 'APPWRITE_FUNCTION_USER_ID' => $headers['x-appwrite-user-id'] ?? '', 'APPWRITE_FUNCTION_JWT' => $headers['x-appwrite-user-jwt'] ?? '' ]); diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index f4581df8e4..748eeffc99 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -134,11 +134,11 @@ App::get('/v1/health/cache') foreach ($configs as $key => $config) { foreach ($config as $database) { + $checkStart = \microtime(true); + try { $adapter = $pools->get($database)->pop()->getResource(); - $checkStart = \microtime(true); - if ($adapter->ping()) { $output[] = new Document([ 'name' => $key . " ($database)", @@ -191,11 +191,11 @@ App::get('/v1/health/queue') foreach ($configs as $key => $config) { foreach ($config as $database) { + $checkStart = \microtime(true); + try { $adapter = $pools->get($database)->pop()->getResource(); - $checkStart = \microtime(true); - if ($adapter->ping()) { $output[] = new Document([ 'name' => $key . " ($database)", @@ -248,11 +248,11 @@ App::get('/v1/health/pubsub') foreach ($configs as $key => $config) { foreach ($config as $database) { + $checkStart = \microtime(true); + try { $adapter = $pools->get($database)->pop()->getResource(); - $checkStart = \microtime(true); - if ($adapter->ping()) { $output[] = new Document([ 'name' => $key . " ($database)", diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 2917bc8416..4578ad920d 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -25,6 +25,7 @@ App::get('/v1/locale') ->inject('response') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (Request $request, Response $response, Locale $locale, Reader $geodb) { $eu = Config::getParam('locale-eu'); $currencies = Config::getParam('locale-currencies'); @@ -210,6 +211,7 @@ App::get('/v1/locale/continents') ->action(function (Response $response, Locale $locale) { $list = Config::getParam('locale-continents'); + $output = []; foreach ($list as $value) { $output[] = new Document([ 'name' => $locale->getText('continents.' . strtolower($value)), diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 7da0348a8f..e99b5449ad 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -899,6 +899,7 @@ App::get('/v1/messaging/providers/:providerId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $providerId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $provider = $dbForProject->getDocument('providers', $providerId); @@ -2031,6 +2032,7 @@ App::get('/v1/messaging/topics/:topicId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $topicId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $topic = $dbForProject->getDocument('topics', $topicId); @@ -2399,6 +2401,7 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $subscriberId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $subscriber = $dbForProject->getDocument('subscribers', $subscriberId); @@ -2932,9 +2935,8 @@ App::post('/v1/messaging/messages/push') $host = System::getEnv('_APP_DOMAIN', 'localhost'); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; - $scheduleTime = $currentScheduledAt ?? $scheduledAt; - if (!\is_null($scheduleTime)) { - $expiry = (new \DateTime($scheduleTime))->add(new \DateInterval('P15D'))->format('U'); + if (!\is_null($scheduledAt)) { + $expiry = (new \DateTime($scheduledAt))->add(new \DateInterval('P15D'))->format('U'); } else { $expiry = (new \DateTime())->add(new \DateInterval('P15D'))->format('U'); } @@ -3081,6 +3083,7 @@ App::get('/v1/messaging/messages/:messageId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $messageId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $message = $dbForProject->getDocument('messages', $messageId); diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index 62a34bb5ce..f3402ec231 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -276,8 +276,6 @@ App::get('/v1/project/usage') 'buildsStorageTotal' => $total[METRIC_BUILDS_STORAGE], 'deploymentsStorageTotal' => $total[METRIC_DEPLOYMENTS_STORAGE], 'executionsBreakdown' => $executionsBreakdown, - 'executionsMbSecondsBreakdown' => $executionsMbSecondsBreakdown, - 'buildsMbSecondsBreakdown' => $buildsMbSecondsBreakdown, 'bucketsBreakdown' => $bucketsBreakdown, 'executionsMbSecondsBreakdown' => $executionsMbSecondsBreakdown, 'buildsMbSecondsBreakdown' => $buildsMbSecondsBreakdown, diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index ca248c2628..630140c1fd 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -257,10 +257,6 @@ App::put('/v1/storage/buckets/:bucketId') $permissions ??= $bucket->getPermissions(); $maximumFileSize ??= $bucket->getAttribute('maximumFileSize', (int) System::getEnv('_APP_STORAGE_LIMIT', 0)); - $allowedFileExtensions ??= $bucket->getAttribute('allowedFileExtensions', []); - $enabled ??= $bucket->getAttribute('enabled', true); - $encryption ??= $bucket->getAttribute('encryption', true); - $antivirus ??= $bucket->getAttribute('antivirus', true); /** * Map aggregate permissions into the multiple permissions they represent, @@ -581,8 +577,8 @@ App::post('/v1/storage/buckets/:bucketId/files') if ($bucket->getAttribute('encryption', true) && $fileSize <= APP_STORAGE_READ_BUFFER) { $openSSLVersion = '1'; $openSSLCipher = OpenSSL::CIPHER_AES_128_GCM; - $openSSLTag = \bin2hex($tag); - $openSSLIV = \bin2hex($iv); + $openSSLTag = ''; + $openSSLIV = ''; } if ($file->isEmpty()) { @@ -1666,7 +1662,7 @@ App::get('/v1/storage/usage') ]; $total = []; - Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats, &$total) { + Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { foreach ($metrics as $metric) { $result = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), @@ -1751,7 +1747,7 @@ App::get('/v1/storage/:bucketId/usage') ]; - Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats, &$total) { + Authorization::skip(function () use ($dbForProject, $days, $metrics, &$stats) { foreach ($metrics as $metric) { $result = $dbForProject->findOne('stats', [ Query::equal('metric', [$metric]), diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index f98cdd721c..2daf836f7b 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -454,7 +454,7 @@ App::post('/v1/teams/:teamId/memberships') } } elseif (!empty($phone)) { $invitee = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); - if (!empty($invitee) && !empty($email) && $invitee->getAttribute('email', '') !== $email) { + if (!empty($invitee) && $invitee->getAttribute('email', '') !== $email) { throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given phone and email doesn\'t match', 409); } } @@ -950,6 +950,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') ->inject('project') ->inject('geodb') ->inject('queueForEvents') + // @phpstan-ignore class.notFound ->action(function (string $teamId, string $membershipId, string $userId, string $secret, Request $request, Response $response, Document $user, Database $dbForProject, Document $project, Reader $geodb, Event $queueForEvents) { $protocol = $request->getProtocol(); @@ -1145,6 +1146,7 @@ App::get('/v1/teams/:teamId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $teamId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $team = $dbForProject->getDocument('teams', $teamId); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 571df4fdb2..7036a41ca4 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -775,6 +775,7 @@ App::get('/v1/users/:userId/logs') ->inject('dbForProject') ->inject('locale') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (string $userId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $user = $dbForProject->getDocument('users', $userId); @@ -1780,6 +1781,7 @@ App::post('/v1/users/:userId/sessions') ->inject('locale') ->inject('geodb') ->inject('queueForEvents') + // @phpstan-ignore class.notFound ->action(function (string $userId, Request $request, Response $response, Database $dbForProject, Document $project, Locale $locale, Reader $geodb, Event $queueForEvents) { $user = $dbForProject->getDocument('users', $userId); if ($user->isEmpty()) { diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index f3381490ec..2ee7527613 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -82,10 +82,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); } - if (empty($repositoryName)) { - throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); - } - $isAuthorized = !$external; if (!$isAuthorized && !empty($providerPullRequestId)) { diff --git a/app/controllers/general.php b/app/controllers/general.php index 0bbfa2b694..6ccb46d440 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -44,6 +44,7 @@ Config::setParam('domainVerification', false); Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); +// @phpstan-ignore class.notFound function router(App $utopia, Database $dbForConsole, callable $getProjectDB, SwooleRequest $swooleRequest, Request $request, Response $response, Event $queueForEvents, Usage $queueForUsage, Reader $geodb) { $utopia->getRoute()?->label('error', __DIR__ . '/../views/general/error.phtml'); @@ -242,7 +243,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo if ($version === 'v2') { $vars = \array_merge($vars, [ 'APPWRITE_FUNCTION_TRIGGER' => $headers['x-appwrite-trigger'] ?? '', - 'APPWRITE_FUNCTION_DATA' => $body ?? '', + 'APPWRITE_FUNCTION_DATA' => $body, 'APPWRITE_FUNCTION_USER_ID' => $headers['x-appwrite-user-id'] ?? '', 'APPWRITE_FUNCTION_JWT' => $headers['x-appwrite-user-jwt'] ?? '' ]); @@ -450,6 +451,7 @@ App::init() ->inject('queueForUsage') ->inject('queueForEvents') ->inject('queueForCertificates') + // @phpstan-ignore class.notFound ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Document $console, Document $project, Database $dbForConsole, callable $getProjectDB, Locale $locale, array $localeCodes, array $clients, Reader $geodb, Usage $queueForUsage, Event $queueForEvents, Certificate $queueForCertificates) { /* * Appwrite Router @@ -667,6 +669,7 @@ App::options() ->inject('queueForEvents') ->inject('queueForUsage') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Database $dbForConsole, callable $getProjectDB, Event $queueForEvents, Usage $queueForUsage, Reader $geodb) { /* * Appwrite Router @@ -954,6 +957,7 @@ App::get('/robots.txt') ->inject('queueForEvents') ->inject('queueForUsage') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Database $dbForConsole, callable $getProjectDB, Event $queueForEvents, Usage $queueForUsage, Reader $geodb) { $host = $request->getHostname() ?? ''; $mainDomain = System::getEnv('_APP_DOMAIN', ''); @@ -979,6 +983,7 @@ App::get('/humans.txt') ->inject('queueForEvents') ->inject('queueForUsage') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (App $utopia, SwooleRequest $swooleRequest, Request $request, Response $response, Database $dbForConsole, callable $getProjectDB, Event $queueForEvents, Usage $queueForUsage, Reader $geodb) { $host = $request->getHostname() ?? ''; $mainDomain = System::getEnv('_APP_DOMAIN', ''); diff --git a/app/controllers/mock.php b/app/controllers/mock.php index fdb1d80dcc..542e86b923 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -229,6 +229,8 @@ App::get('/v1/mock/github/callback') throw new Exception(Exception::PROJECT_NOT_FOUND, $error); } + $installation = new Document(); + if (!empty($providerInstallationId)) { $privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY'); $githubAppId = System::getEnv('_APP_VCS_GITHUB_APP_ID'); diff --git a/app/controllers/shared/api/auth.php b/app/controllers/shared/api/auth.php index 53aacabe21..149c326c9e 100644 --- a/app/controllers/shared/api/auth.php +++ b/app/controllers/shared/api/auth.php @@ -35,6 +35,7 @@ App::init() ->inject('request') ->inject('project') ->inject('geodb') + // @phpstan-ignore class.notFound ->action(function (App $utopia, Request $request, Document $project, Reader $geodb) { $denylist = System::getEnv('_APP_CONSOLE_COUNTRIES_DENYLIST', ''); if (!empty($denylist && $project->getId() === 'console')) { diff --git a/app/http.php b/app/http.php index 7e1291142b..0456172348 100644 --- a/app/http.php +++ b/app/http.php @@ -26,6 +26,8 @@ use Utopia\Pools\Group; use Utopia\Swoole\Files; use Utopia\System\System; +/** @var Utopia\Registry\Registry $register */ + $http = new Server( host: "0.0.0.0", port: System::getEnv('PORT', 80), @@ -71,12 +73,12 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg $attempts = 0; $max = 10; $sleep = 1; + $dbForConsole = null; do { try { $attempts++; $dbForConsole = $app->getResource('dbForConsole'); - /** @var Utopia\Database\Database $dbForConsole */ break; // leave the do-while if successful } catch (\Throwable $e) { Console::warning("Database not ready. Retrying connection ({$attempts})..."); @@ -87,6 +89,8 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg } } while ($attempts < $max); + /** @var Utopia\Database\Database $dbForConsole */ + Console::success('[Setup] - Server database init started...'); try { diff --git a/app/worker.php b/app/worker.php index 3de106608b..41d902e550 100644 --- a/app/worker.php +++ b/app/worker.php @@ -36,10 +36,11 @@ use Utopia\Queue\Server; use Utopia\Registry\Registry; use Utopia\System\System; +/** @var Utopia\Registry\Registry $register */ + Authorization::disable(); Runtime::enableCoroutine(SWOOLE_HOOK_ALL); - // @phpstan-ignore variable.undefined Server::setResource('register', fn () => $register); Server::setResource('dbForConsole', function (Cache $cache, Registry $register) { @@ -273,7 +274,6 @@ Server::setResource('deviceForCache', function (Document $project) { return getDevice(APP_STORAGE_CACHE . '/app-' . $project->getId()); }, ['project']); -// @phpstan-ignore variable.undefined $pools = $register->get('pools'); $platform = new Appwrite(); $args = $platform->getEnv('argv'); diff --git a/composer.json b/composer.json index 26ac756bbe..9922bc88a5 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,7 @@ "textalk/websocket": "1.5.7", "laravel/pint": "^1.14", "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "1.8.*" + "phpstan/phpstan": "1.12.*" }, "provide": { "ext-phpiredis": "*" diff --git a/composer.lock b/composer.lock index d6b8cd3d49..b7becafb0e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0f051dc943ac8ba7a8777a1442bc64e2", + "content-hash": "95bd5ac66d795d804215b495ba0221e9", "packages": [ { "name": "adhocore/jwt", @@ -4232,16 +4232,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.8.11", + "version": "1.12.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "46e223dd68a620da18855c23046ddb00940b4014" + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", - "reference": "46e223dd68a620da18855c23046ddb00940b4014", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", "shasum": "" }, "require": { @@ -4270,8 +4270,11 @@ "static analysis" ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.8.11" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -4281,13 +4284,9 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2022-10-24T15:45:13+00:00" + "time": "2024-09-26T12:45:22+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Appwrite/Promises/Promise.php b/src/Appwrite/Promises/Promise.php index a6b1aa79d5..f12590dfed 100644 --- a/src/Appwrite/Promises/Promise.php +++ b/src/Appwrite/Promises/Promise.php @@ -12,7 +12,7 @@ abstract class Promise private mixed $result; - public function __construct(?callable $executor = null) + final public function __construct(?callable $executor = null) { if (\is_null($executor)) { return; diff --git a/src/Appwrite/Promises/Swoole.php b/src/Appwrite/Promises/Swoole.php index c258ef6a5e..d0b3eb8855 100644 --- a/src/Appwrite/Promises/Swoole.php +++ b/src/Appwrite/Promises/Swoole.php @@ -6,11 +6,6 @@ use Swoole\Coroutine\Channel; class Swoole extends Promise { - public function __construct(?callable $executor = null) - { - parent::__construct($executor); - } - protected function execute( callable $executor, callable $resolve, diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 537707bb5a..f7859d4971 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -650,7 +650,7 @@ class Response extends SwooleResponse $ruleType = $rule['type']; } - if(!isset($ruleType)) { + if (!isset($ruleType)) { continue; }