@@ -20,7 +20,7 @@ |
||
| 20 | 20 | // Update retour widget type |
| 21 | 21 | $this->update('{{%widgets}}', [ |
| 22 | 22 | 'type' => RetourWidget::class |
| 23 | - ], ['type' => 'Retour']); |
|
| 23 | + ], [ 'type' => 'Retour' ]); |
|
| 24 | 24 | |
| 25 | 25 | return true; |
| 26 | 26 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | // Update retour widget type |
| 21 | 21 | $this->update('{{%widgets}}', [ |
| 22 | 22 | 'type' => RetourWidget::class |
| 23 | - ], ['type' => 'Retour']); |
|
| 23 | + ], [ 'type' => 'Retour' ]); |
|
| 24 | 24 | |
| 25 | 25 | return true; |
| 26 | 26 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | // Query the db table |
| 62 | 62 | $stats = (new Query()) |
| 63 | - ->from(['{{%retour_stats}}']) |
|
| 63 | + ->from([ '{{%retour_stats}}' ]) |
|
| 64 | 64 | ->orderBy('hitCount DESC') |
| 65 | 65 | ->limit(Retour::$settings->statsDisplayLimit) |
| 66 | 66 | ->all(); |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | public function getRecentStatistics($days = 1, $handled = false): array |
| 80 | 80 | { |
| 81 | 81 | // Ensure is an int |
| 82 | - $handledInt = (int)$handled; |
|
| 83 | - $stats = []; |
|
| 82 | + $handledInt = (int) $handled; |
|
| 83 | + $stats = [ ]; |
|
| 84 | 84 | $db = Craft::$app->getDb(); |
| 85 | 85 | if ($db->getIsMysql()) { |
| 86 | 86 | // Query the db table |
| 87 | 87 | $stats = (new Query()) |
| 88 | - ->from(['{{%retour_stats}}']) |
|
| 88 | + ->from([ '{{%retour_stats}}' ]) |
|
| 89 | 89 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )") |
| 90 | 90 | ->andWhere("handledByRetour = {$handledInt}") |
| 91 | 91 | ->orderBy('hitLastTime DESC') |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | if ($db->getIsPgsql()) { |
| 95 | 95 | // Query the db table |
| 96 | 96 | $stats = (new Query()) |
| 97 | - ->from(['{{%retour_stats}}']) |
|
| 97 | + ->from([ '{{%retour_stats}}' ]) |
|
| 98 | 98 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )") |
| 99 | - ->andWhere(['handledByRetour' => $handledInt]) |
|
| 99 | + ->andWhere([ 'handledByRetour' => $handledInt ]) |
|
| 100 | 100 | ->orderBy('hitLastTime DESC') |
| 101 | 101 | ->all(); |
| 102 | 102 | } |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | $stats->validate(); |
| 164 | 164 | // Find any existing retour_stats record |
| 165 | 165 | $statsConfig = (new Query()) |
| 166 | - ->from(['{{%retour_stats}}']) |
|
| 167 | - ->where(['redirectSrcUrl' => $stats->redirectSrcUrl]) |
|
| 166 | + ->from([ '{{%retour_stats}}' ]) |
|
| 167 | + ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ]) |
|
| 168 | 168 | ->one(); |
| 169 | 169 | // If no record is found, initialize some values |
| 170 | 170 | if ($statsConfig === null) { |
| 171 | 171 | $stats->id = 0; |
| 172 | 172 | $stats->hitCount = 0; |
| 173 | 173 | } else { |
| 174 | - $stats->id = $statsConfig['id']; |
|
| 175 | - $stats->hitCount = $statsConfig['hitCount']; |
|
| 174 | + $stats->id = $statsConfig[ 'id' ]; |
|
| 175 | + $stats->hitCount = $statsConfig[ 'hitCount' ]; |
|
| 176 | 176 | } |
| 177 | 177 | // Merge in the updated info |
| 178 | 178 | $stats->siteId = $siteId; |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | $stats->userAgent = $userAgent; |
| 182 | 182 | $stats->exceptionMessage = $exceptionMessage; |
| 183 | 183 | $stats->exceptionFilePath = $exceptionFilePath; |
| 184 | - $stats->exceptionFileLine = (int)$exceptionFileLine; |
|
| 184 | + $stats->exceptionFileLine = (int) $exceptionFileLine; |
|
| 185 | 185 | $stats->hitLastTime = Db::prepareDateForDb(new \DateTime()); |
| 186 | - $stats->handledByRetour = (int)$handled; |
|
| 186 | + $stats->handledByRetour = (int) $handled; |
|
| 187 | 187 | $stats->hitCount++; |
| 188 | 188 | $statsConfig = $stats->getAttributes(); |
| 189 | 189 | // Record the updated statistics |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | Craft::t( |
| 254 | 254 | 'retour', |
| 255 | 255 | 'Trimmed {rows} from retour_stats table', |
| 256 | - ['rows' => $affectedRows] |
|
| 256 | + [ 'rows' => $affectedRows ] |
|
| 257 | 257 | ), |
| 258 | 258 | __METHOD__ |
| 259 | 259 | ); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | Craft::t( |
| 275 | 275 | 'retour', |
| 276 | 276 | 'Error validating statistics {id}: {errors}', |
| 277 | - ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)] |
|
| 277 | + [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ] |
|
| 278 | 278 | ), |
| 279 | 279 | __METHOD__ |
| 280 | 280 | ); |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | // Get the validated model attributes and save them to the db |
| 285 | 285 | $statsConfig = $stats->getAttributes(); |
| 286 | 286 | $db = Craft::$app->getDb(); |
| 287 | - if ($statsConfig['id'] !== 0) { |
|
| 287 | + if ($statsConfig[ 'id' ] !== 0) { |
|
| 288 | 288 | // Update the existing record |
| 289 | 289 | try { |
| 290 | 290 | $result = $db->createCommand()->update( |
| 291 | 291 | '{{%retour_stats}}', |
| 292 | 292 | $statsConfig, |
| 293 | 293 | [ |
| 294 | - 'id' => $statsConfig['id'], |
|
| 294 | + 'id' => $statsConfig[ 'id' ], |
|
| 295 | 295 | ] |
| 296 | 296 | )->execute(); |
| 297 | 297 | } catch (Exception $e) { |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | // Craft::error($e->getMessage(), __METHOD__); |
| 301 | 301 | } |
| 302 | 302 | } else { |
| 303 | - unset($statsConfig['id']); |
|
| 303 | + unset($statsConfig[ 'id' ]); |
|
| 304 | 304 | // Create a new record |
| 305 | 305 | try { |
| 306 | 306 | $db->createCommand()->insert( |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $now = round(microtime(true) * 1000); |
| 328 | 328 | $cache = Craft::$app->getCache(); |
| 329 | 329 | $then = $cache->get(self::LAST_STATISTICS_TRIM_CACHE_KEY); |
| 330 | - if (($then !== false) && ($now - (int)$then < Retour::$settings->statisticsRateLimitMs)) { |
|
| 330 | + if (($then !== false) && ($now - (int) $then < Retour::$settings->statisticsRateLimitMs)) { |
|
| 331 | 331 | $limited = true; |
| 332 | 332 | } |
| 333 | 333 | $cache->set(self::LAST_STATISTICS_TRIM_CACHE_KEY, $now, 0); |
@@ -62,36 +62,36 @@ discard block |
||
| 62 | 62 | // Boolean field |
| 63 | 63 | $retourField |
| 64 | 64 | ->addBooleanField($field) |
| 65 | - ->resolve(function ($redirect) use ($field) { |
|
| 66 | - $result = $redirect[$field] ?? null; |
|
| 67 | - return $result === null ? $result : (bool)$result; |
|
| 65 | + ->resolve(function($redirect) use ($field) { |
|
| 66 | + $result = $redirect[ $field ] ?? null; |
|
| 67 | + return $result === null ? $result : (bool) $result; |
|
| 68 | 68 | }); |
| 69 | 69 | } elseif (in_array($field, self::INT_FIELDS, true)) { |
| 70 | 70 | // Integer field |
| 71 | 71 | $retourField |
| 72 | 72 | ->addIntField($field) |
| 73 | - ->resolve(function ($redirect) use ($field) { |
|
| 74 | - $result = $redirect[$field] ?? null; |
|
| 75 | - return $result === null ? $result : (int)$result; |
|
| 73 | + ->resolve(function($redirect) use ($field) { |
|
| 74 | + $result = $redirect[ $field ] ?? null; |
|
| 75 | + return $result === null ? $result : (int) $result; |
|
| 76 | 76 | }); |
| 77 | 77 | } else { |
| 78 | 78 | // String field |
| 79 | 79 | $retourField |
| 80 | 80 | ->addStringField($field) |
| 81 | - ->resolve(function ($redirect) use ($field) { |
|
| 82 | - $result = $redirect[$field] ?? null; |
|
| 83 | - return $result === null ? $result : (string)$result; |
|
| 81 | + ->resolve(function($redirect) use ($field) { |
|
| 82 | + $result = $redirect[ $field ] ?? null; |
|
| 83 | + return $result === null ? $result : (string) $result; |
|
| 84 | 84 | }); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | // Add the root |
| 88 | 88 | $event->schema->addField('retour') |
| 89 | - ->arguments(function (FieldBuilder $field) { |
|
| 89 | + ->arguments(function(FieldBuilder $field) { |
|
| 90 | 90 | $field->addStringArgument('uri'); |
| 91 | 91 | $field->addIntArgument('siteId'); |
| 92 | 92 | }) |
| 93 | 93 | ->type($retourField) |
| 94 | - ->resolve(function ($root, $args, $context, $info) { |
|
| 94 | + ->resolve(function($root, $args, $context, $info) { |
|
| 95 | 95 | // If our root is an Element, extract the URI and siteId from it |
| 96 | 96 | if ($root instanceof Element) { |
| 97 | 97 | /** Element $root */ |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | $siteId = $root->siteId; |
| 100 | 100 | } else { |
| 101 | 101 | // Otherwise use the passed in arguments, or defaults |
| 102 | - $uri = $args['uri'] ?? '/'; |
|
| 103 | - $siteId = $args['siteId'] ?? null; |
|
| 102 | + $uri = $args[ 'uri' ] ?? '/'; |
|
| 103 | + $siteId = $args[ 'siteId' ] ?? null; |
|
| 104 | 104 | } |
| 105 | 105 | $uri = trim($uri === '/' ? '__home__' : $uri); |
| 106 | 106 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function __construct(array $config) |
| 33 | 33 | { |
| 34 | - $config['interfaces'] = [ |
|
| 34 | + $config[ 'interfaces' ] = [ |
|
| 35 | 35 | RetourInterface::getType(), |
| 36 | 36 | ]; |
| 37 | 37 | |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $fieldName = $resolveInfo->fieldName; |
| 47 | 47 | |
| 48 | - return $source[$fieldName]; |
|
| 48 | + return $source[ $fieldName ]; |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -48,9 +48,9 @@ |
||
| 48 | 48 | |
| 49 | 49 | $type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([ |
| 50 | 50 | 'name' => static::getName(), |
| 51 | - 'fields' => self::class.'::getFieldDefinitions', |
|
| 51 | + 'fields' => self::class . '::getFieldDefinitions', |
|
| 52 | 52 | 'description' => 'This is the interface implemented by Retour.', |
| 53 | - 'resolveType' => function (array $value) { |
|
| 53 | + 'resolveType' => function(array $value) { |
|
| 54 | 54 | return GqlEntityRegistry::getEntity(RetourGenerator::getName()); |
| 55 | 55 | }, |
| 56 | 56 | ])); |
@@ -34,24 +34,24 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public static function generateTypes($context = null): array |
| 36 | 36 | { |
| 37 | - $gqlTypes = []; |
|
| 37 | + $gqlTypes = [ ]; |
|
| 38 | 38 | $retourFields = RetourInterface::getFieldDefinitions(); |
| 39 | 39 | $retourArgs = RetourArguments::getArguments(); |
| 40 | 40 | $typeName = self::getName(); |
| 41 | 41 | $retourType = GqlEntityRegistry::getEntity($typeName) |
| 42 | 42 | ?: GqlEntityRegistry::createEntity($typeName, new RetourType([ |
| 43 | 43 | 'name' => $typeName, |
| 44 | - 'args' => function () use ($retourArgs) { |
|
| 44 | + 'args' => function() use ($retourArgs) { |
|
| 45 | 45 | return $retourArgs; |
| 46 | 46 | }, |
| 47 | - 'fields' => function () use ($retourFields) { |
|
| 47 | + 'fields' => function() use ($retourFields) { |
|
| 48 | 48 | return $retourFields; |
| 49 | 49 | }, |
| 50 | 50 | 'description' => 'This entity has all the Retour fields', |
| 51 | 51 | ])); |
| 52 | 52 | |
| 53 | - $gqlTypes[$typeName] = $retourType; |
|
| 54 | - TypeLoader::registerType($typeName, function () use ($retourType) { |
|
| 53 | + $gqlTypes[ $typeName ] = $retourType; |
|
| 54 | + TypeLoader::registerType($typeName, function() use ($retourType) { |
|
| 55 | 55 | return $retourType; |
| 56 | 56 | }); |
| 57 | 57 | |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | /** @noinspection CallableParameterUseCaseInTypeContextInspection */ |
| 40 | 40 | $url = preg_replace('/{.*}/', '', $url); |
| 41 | 41 | // Remove any linebreaks that may be errantly in the URL |
| 42 | - $url = (string)str_replace([ |
|
| 42 | + $url = (string) str_replace([ |
|
| 43 | 43 | PHP_EOL, |
| 44 | 44 | "\r", |
| 45 | 45 | "\n", |
@@ -57,6 +57,6 @@ |
||
| 57 | 57 | { |
| 58 | 58 | $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId); |
| 59 | 59 | |
| 60 | - return $this->asJson($redirects ?? []); |
|
| 60 | + return $this->asJson($redirects ?? [ ]); |
|
| 61 | 61 | } |
| 62 | 62 | } |