Updated coding standards

This commit is contained in:
Eldad Fux 2020-06-24 23:59:04 +03:00
parent 8e484d32d8
commit c7366c7453
11 changed files with 45 additions and 60 deletions

View file

@ -45,7 +45,6 @@ $utopia->init(function() use (&$oauth2Keys) {
$oauth2Keys[] = 'oauth2'.\ucfirst($key);
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
}
});
$utopia->post('/v1/account')
@ -223,7 +222,7 @@ $utopia->post('/v1/account/sessions')
->setParam('resource', 'users/'.$profile->getId())
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)]))
;
@ -500,13 +499,13 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
->setParam('data', ['provider' => $provider])
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
;
}
if($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms
if ($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms
$state['success'] = URLParser::parse($state['success']);
$query = URLParser::parseQuery($state['success']['query']);
$query['project'] = $project->getId();
@ -920,7 +919,7 @@ $utopia->delete('/v1/account')
])
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([]))
;
@ -972,7 +971,7 @@ $utopia->delete('/v1/account/sessions/:sessionId')
])
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([]))
;
@ -1025,7 +1024,7 @@ $utopia->delete('/v1/account/sessions')
])
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([]))
;

View file

@ -100,7 +100,8 @@ $utopia->get('/v1/avatars/credit-cards/:code')
->label('sdk.method', 'getCreditCard')
->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-credit-card.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('credit-cards', $code, $width, $height, $quality);
->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('credit-cards', $code, $width, $height, $quality);
});
$utopia->get('/v1/avatars/browsers/:code')
@ -115,7 +116,8 @@ $utopia->get('/v1/avatars/browsers/:code')
->label('sdk.method', 'getBrowser')
->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-browser.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('browsers', $code, $width, $height, $quality);
->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('browsers', $code, $width, $height, $quality);
});
$utopia->get('/v1/avatars/flags/:code')
@ -130,7 +132,8 @@ $utopia->get('/v1/avatars/flags/:code')
->label('sdk.method', 'getFlag')
->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-flag.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('flags', $code, $width, $height, $quality);
->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('flags', $code, $width, $height, $quality);
});
$utopia->get('/v1/avatars/image')
@ -424,7 +427,7 @@ $utopia->get('/v1/avatars/initials')
$initials .= (isset($w[0])) ? $w[0] : '';
$code += (isset($w[0])) ? \ord($w[0]) : 0;
if($key == 1) {
if ($key == 1) {
break;
}
}

View file

@ -425,7 +425,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
$key = (isset($rule['key'])) ? $rule['key'] : '';
$default = (isset($rule['default'])) ? $rule['default'] : null;
if(!isset($data[$key])) {
if (!isset($data[$key])) {
$data[$key] = $default;
}
}

View file

@ -193,7 +193,6 @@ $utopia->get('/v1/health/storage/local')
->label('sdk.description', '/docs/references/health/get-storage-local.md')
->action(
function () use ($response) {
foreach ([
'Uploads' => APP_STORAGE_UPLOADS,
'Cache' => APP_STORAGE_CACHE,
@ -224,7 +223,7 @@ $utopia->get('/v1/health/anti-virus')
->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md')
->action(
function () use ($request, $response) {
if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled
if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled
throw new Exception('Anitvirus is disabled');
}

View file

@ -415,7 +415,7 @@ $utopia->delete('/v1/projects/:projectId')
$deletes->setParam('document', $project->getArrayCopy());
foreach(['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
$list = $project->getAttribute('webhooks', []);
foreach ($list as $document) { /* @var $document Document */
@ -1250,7 +1250,7 @@ $utopia->post('/v1/projects/:projectId/domains')
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
if(!$target->isKnown() || $target->isTest()) {
if (!$target->isKnown() || $target->isTest()) {
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
}
@ -1357,18 +1357,18 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
if(!$target->isKnown() || $target->isTest()) {
if (!$target->isKnown() || $target->isTest()) {
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
}
if($domain->getAttribute('verification') === true) {
if ($domain->getAttribute('verification') === true) {
return $response->json($domain->getArrayCopy());
}
// Verify Domain with DNS records
$validator = new CNAME($target->get());
if(!$validator->isValid($domain->getAttribute('domain', ''))) {
if (!$validator->isValid($domain->getAttribute('domain', ''))) {
throw new Exception('Failed to verify domain', 401);
}

View file

@ -198,7 +198,7 @@ $utopia->post('/v1/storage/files')
$mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption
if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
$antiVirus = new Network('clamav', 3310);
// Check if file size is exceeding allowed limit
@ -216,7 +216,7 @@ $utopia->post('/v1/storage/files')
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
$data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
if(!$device->write($path, $data)) {
if (!$device->write($path, $data)) {
throw new Exception('Failed to save file', 500);
}
@ -370,7 +370,7 @@ $utopia->get('/v1/storage/files/:fileId/preview')
$cipher = $file->getAttribute('fileOpenSSLCipher');
$mime = $file->getAttribute('mimeType');
if(!\in_array($mime, $inputs)) {
if (!\in_array($mime, $inputs)) {
$path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default'];
$algorithm = null;
$cipher = null;

View file

@ -306,12 +306,11 @@ $utopia->post('/v1/teams/:teamId/memberships')
'secret' => Auth::hash($secret),
]);
if(APP_MODE_ADMIN === $mode) { // Allow admin to create membership
if (APP_MODE_ADMIN === $mode) { // Allow admin to create membership
Authorization::disable();
$membership = $projectDB->createDocument($membership->getArrayCopy());
Authorization::reset();
}
else {
} else {
$membership = $projectDB->createDocument($membership->getArrayCopy());
}
@ -344,7 +343,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
->setParam('{{text-cta}}', '#ffffff')
;
if(APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode
if (APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode
$mail
->setParam('event', 'teams.membership.create')
->setParam('recipient', $email)
@ -433,7 +432,6 @@ $utopia->get('/v1/teams/:teamId/memberships')
}
$response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]);
}
);
@ -544,7 +542,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
->setParam('resource', 'teams/'.$teamId)
;
if(!Config::getParam('domainVerification')) {
if (!Config::getParam('domainVerification')) {
$response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
;

View file

@ -22,7 +22,6 @@ $utopia->get('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -37,7 +36,6 @@ $utopia->post('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -52,7 +50,6 @@ $utopia->patch('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -67,7 +64,6 @@ $utopia->put('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -82,7 +78,6 @@ $utopia->delete('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -97,7 +92,6 @@ $utopia->get('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -112,7 +106,6 @@ $utopia->post('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -127,7 +120,6 @@ $utopia->patch('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -142,7 +134,6 @@ $utopia->put('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -157,7 +148,6 @@ $utopia->delete('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action(
function ($x, $y, $z) {
}
);
@ -180,19 +170,19 @@ $utopia->post('/v1/mock/tests/general/upload')
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']];
foreach ($file['name'] as $i => $name) {
if($name !== 'file.png') {
if ($name !== 'file.png') {
throw new Exception('Wrong file name', 400);
}
}
foreach ($file['size'] as $i => $size) {
if($size !== 38756) {
if ($size !== 38756) {
throw new Exception('Wrong file size', 400);
}
}
foreach ($file['tmp_name'] as $i => $tmpName) {
if(\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400);
}
}
@ -242,7 +232,7 @@ $utopia->get('/v1/mock/tests/general/get-cookie')
->label('sdk.description', 'Mock a get cookie request for SDK tests')
->action(
function () use ($request) {
if($request->getCookie('cookieName', '') !== 'cookieValue') {
if ($request->getCookie('cookieName', '') !== 'cookieValue') {
throw new Exception('Missing cookie value', 400);
}
}
@ -285,15 +275,15 @@ $utopia->get('/v1/mock/tests/general/oauth2/token')
->param('code', '', function () { return new Text(100); }, 'OAuth2 state.')
->action(
function ($clientId, $redirectURI, $clientSecret, $code) use ($response) {
if($clientId != '1') {
if ($clientId != '1') {
throw new Exception('Invalid client ID');
}
if($clientSecret != '123456') {
if ($clientSecret != '123456') {
throw new Exception('Invalid client secret');
}
if($code != 'abcdef') {
if ($code != 'abcdef') {
throw new Exception('Invalid token');
}
@ -308,7 +298,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/user')
->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.')
->action(
function ($token) use ($response) {
if($token != '123456') {
if ($token != '123456') {
throw new Exception('Invalid token');
}
@ -345,12 +335,11 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure')
);
$utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
$route = $utopia->match($request);
$path = APP_STORAGE_CACHE.'/tests.json';
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
if(!\is_array($tests)) {
if (!\is_array($tests)) {
throw new Exception('Failed to read results', 500);
}
@ -358,7 +347,7 @@ $utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
$tests = \array_merge($tests, $result);
if(!\file_put_contents($path, \json_encode($tests), LOCK_EX)) {
if (!\file_put_contents($path, \json_encode($tests), LOCK_EX)) {
throw new Exception('Failed to save resutls', 500);
}

View file

@ -7,10 +7,9 @@ use Utopia\Abuse\Adapters\TimeLimit;
global $utopia, $request, $response, $register, $user, $project;
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
$route = $utopia->match($request);
if(empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope
if (empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope
throw new Exception('Missing or unknown project ID', 400);
}
@ -37,7 +36,6 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $
$abuse = new Abuse($timeLimit);
if ($timeLimit->limit()) {
$response
->addHeader('X-RateLimit-Limit', $timeLimit->limit())
->addHeader('X-RateLimit-Remaining', $timeLimit->remaining())

View file

@ -213,7 +213,6 @@ $utopia->get('/console/database/collection')
->addHeader('Expires', 0)
->addHeader('Pragma', 'no-cache')
;
});
$utopia->get('/console/database/document')

View file

@ -183,11 +183,11 @@ $utopia->get('/open-api-2.json')
}
foreach ($services as $service) { /* @noinspection PhpIncludeInspection */
if($tests && !isset($service['tests'])) {
if ($tests && !isset($service['tests'])) {
continue;
}
if($tests && !$service['tests']) {
if ($tests && !$service['tests']) {
continue;
}
@ -347,19 +347,19 @@ $utopia->get('/open-api-2.json')
];
if ($extensions) {
if(isset($output['securityDefinitions']['Project'])) {
if (isset($output['securityDefinitions']['Project'])) {
$output['securityDefinitions']['Project']['extensions'] = ['demo' => '5df5acd0d48c2'];
}
if(isset($output['securityDefinitions']['Key'])) {
if (isset($output['securityDefinitions']['Key'])) {
$output['securityDefinitions']['Key']['extensions'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2'];
}
if(isset($output['securityDefinitions']['Locale'])) {
if (isset($output['securityDefinitions']['Locale'])) {
$output['securityDefinitions']['Locale']['extensions'] = ['demo' => 'en'];
}
if(isset($output['securityDefinitions']['Mode'])) {
if (isset($output['securityDefinitions']['Mode'])) {
$output['securityDefinitions']['Mode']['extensions'] = ['demo' => ''];
}
}
@ -374,7 +374,7 @@ $utopia->get('/open-api-2.json')
continue;
}
if($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) {
if ($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) {
continue;
}