Repository: appwrite/appwrite
File: app/controllers/general.php (PHP)

Code before:
            'site' => 'v5',
        };

        $runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
        $spec = Config::getParam('specifications')[$resource->getAttribute('specification', APP_COMPUTE_SPECIFICATION_DEFAULT)];

        $runtime = match ($type) {
            'function' => $runtimes[$resource->getAttribute('runtime')] ?? null,
            'site' => $runtimes[$resource->getAttribute('buildRuntime')] ?? null,
            default => null
        };

        // Static site enforced runtime
        if ($resource->getAttribute('adapter', '') === 'static') {
            $runtime = $runtimes['static-1'] ?? null;
        }

        if (\is_null($runtime)) {
            throw new AppwriteException(AppwriteException::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported');
        }

        if ($deployment->getAttribute('status') === 'waiting' || $deployment->getAttribute('status') === 'processing' || $deployment->getAttribute('status') === 'building') {
            throw new AppwriteException(AppwriteException::BUILD_NOT_READY);
        }

        if ($deployment->getAttribute('status') === 'failed') {
            throw new AppwriteException(AppwriteException::BUILD_FAILED);
        }

        if ($type === 'function') {
            $permissions = $resource->getAttribute('execute');
            if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) {
                throw new AppwriteException(AppwriteException::USER_UNAUTHORIZED, 'To execute function using domain, execute permissions must include "any" or "guests"');
            }
        }

        $headers = \array_merge([], $requestHeaders);
        $headers['x-appwrite-user-id'] = '';
        $headers['x-appwrite-country-code'] = '';
        $headers['x-appwrite-continent-code'] = '';
        $headers['x-appwrite-continent-eu'] = 'false';

        $jwtExpiry = $resource->getAttribute('timeout', 900);
        $jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $jwtExpiry, 0);
        $jwtKey = $jwtObj->encode([
            'projectId' => $project->getId(),
            'scopes' => $resource->getAttribute('scopes', [])
        ]);
        $headers['x-appwrite-key'] = API_KEY_DYNAMIC . '_' . $jwtKey;
        $headers['x-appwrite-trigger'] = 'http';
        $headers['x-appwrite-user-jwt'] = '';

Review comment (bug):
Let's rewrite to:
```
if status is not ready
  if status is fauled -> build_failed
  else: build_not_ready

Code after:
            'site' => 'v5',
        };

        $runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
        $spec = Config::getParam('specifications')[$resource->getAttribute('specification', APP_COMPUTE_SPECIFICATION_DEFAULT)];

        $runtime = match ($type) {
            'function' => $runtimes[$resource->getAttribute('runtime')] ?? null,
            'site' => $runtimes[$resource->getAttribute('buildRuntime')] ?? null,
            default => null
        };

        // Static site enforced runtime
        if ($deployment->getAttribute('adapter', '') === 'static') {
            $runtime = $runtimes['static-1'] ?? null;
        }

        if (\is_null($runtime)) {
            throw new AppwriteException(AppwriteException::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported');
        }

        if ($deployment->getAttribute('status') !== 'ready') {
            if ($deployment->getAttribute('status') === 'failed') {
                throw new AppwriteException(AppwriteException::BUILD_FAILED);
            } else {
                throw new AppwriteException(AppwriteException::BUILD_NOT_READY);
            }
        }

        if ($type === 'function') {
            $permissions = $resource->getAttribute('execute');
            if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) {
                throw new AppwriteException(AppwriteException::USER_UNAUTHORIZED, 'To execute function using domain, execute permissions must include "any" or "guests"');
            }
        }

        $headers = \array_merge([], $requestHeaders);
        $headers['x-appwrite-user-id'] = '';
        $headers['x-appwrite-country-code'] = '';
        $headers['x-appwrite-continent-code'] = '';
        $headers['x-appwrite-continent-eu'] = 'false';

        $jwtExpiry = $resource->getAttribute('timeout', 900);
        $jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $jwtExpiry, 0);
        $jwtKey = $jwtObj->encode([
            'projectId' => $project->getId(),
            'scopes' => $resource->getAttribute('scopes', [])
        ]);
        $headers['x-appwrite-key'] = API_KEY_DYNAMIC . '_' . $jwtKey;
        $headers['x-appwrite-trigger'] = 'http';
        $headers['x-appwrite-user-jwt'] = '';