Passed
Push — master ( 457125...150b79 )
by Stefano
02:16
created
src/Core/I18nTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function getLocales(): array
45 45
     {
46
-        return (array)Configure::read('I18n.locales', []);
46
+        return (array)Configure::read('I18n.locales', [ ]);
47 47
     }
48 48
 
49 49
     /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function getLanguages(): array
57 57
     {
58
-        return (array)Configure::read('I18n.languages', []);
58
+        return (array)Configure::read('I18n.languages', [ ]);
59 59
     }
60 60
 
61 61
     /**
Please login to merge, or discard this patch.
src/Plugin.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
          */
65 65
         $middlewareQueue->insertBefore(
66 66
             RoutingMiddleware::class,
67
-            new I18nMiddleware((array)Configure::read('I18n', []))
67
+            new I18nMiddleware((array)Configure::read('I18n', [ ]))
68 68
         );
69 69
 
70 70
         return $middlewareQueue;
Please login to merge, or discard this patch.
src/Routing/Route/I18nRoute.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * @inheritDoc
31 31
      */
32
-    public function __construct($template, $defaults = [], array $options = [])
32
+    public function __construct($template, $defaults = [ ], array $options = [ ])
33 33
     {
34 34
         parent::__construct($this->buildTemplate($template), $defaults, $options);
35 35
 
36
-        if (empty($options['lang'])) {
37
-            $this->setPatterns(['lang' => implode('|', array_keys($this->getLanguages()))]);
36
+        if (empty($options[ 'lang' ])) {
37
+            $this->setPatterns([ 'lang' => implode('|', array_keys($this->getLanguages())) ]);
38 38
         }
39 39
     }
40 40
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @inheritDoc
64 64
      */
65
-    public function match(array $url, array $context = []): ?string
65
+    public function match(array $url, array $context = [ ]): ?string
66 66
     {
67 67
         if (!array_key_exists('lang', $url)) {
68
-            $url['lang'] = $this->getLang();
68
+            $url[ 'lang' ] = $this->getLang();
69 69
         }
70 70
 
71 71
         return parent::match($url, $context) ?: null;
Please login to merge, or discard this patch.
src/View/Helper/I18nHelper.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * @inheritDoc
35 35
      */
36
-    public $helpers = ['Html', 'Url'];
36
+    public $helpers = [ 'Html', 'Url' ];
37 37
 
38 38
     /**
39 39
      * Translation data per object and lang (internal cache).
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         string $attribute,
165 165
         ?string $lang = null,
166 166
         bool $defaultNull = false,
167
-        array $included = []
167
+        array $included = [ ]
168 168
     ): ?string {
169 169
         $defaultValue = null;
170 170
         if (!$defaultNull) {
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      * @param array $included The included translations data)
198 198
      * @return bool
199 199
      */
200
-    public function exists(array $object, string $attribute, ?string $lang = null, array &$included = []): bool
200
+    public function exists(array $object, string $attribute, ?string $lang = null, array &$included = [ ]): bool
201 201
     {
202 202
         if (empty($included) && !empty($this->_View->get('included'))) {
203 203
             $included = $this->_View->get('included');
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         // first look if embedded relationships are set
242 242
         if (Hash::check($object, 'relationships.translations.data.0.attributes')) {
243 243
             $translations = Hash::combine(
244
-                $object['relationships']['translations']['data'],
244
+                $object[ 'relationships' ][ 'translations' ][ 'data' ],
245 245
                 '{n}.attributes.lang',
246 246
                 '{n}.attributes.translated_fields'
247 247
             );
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
             return Hash::get($translations, sprintf('%s.%s', $lang, $attribute));
250 250
         }
251 251
 
252
-        if (empty($object['id'])) {
252
+        if (empty($object[ 'id' ])) {
253 253
             return null;
254 254
         }
255 255
 
256
-        $id = $object['id'];
256
+        $id = $object[ 'id' ];
257 257
 
258 258
         if ($this->translation === null) {
259 259
             $translations = Hash::combine($included, '{n}.id', '{n}.attributes', '{n}.type');
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      * @param array $options Array of options.
278 278
      * @return string Full I18n URL.
279 279
      */
280
-    public function buildUrl($path, $options = []): string
280
+    public function buildUrl($path, $options = [ ]): string
281 281
     {
282 282
         if (is_string($path) && !$this->isI18nPath($path)) {
283 283
             $path = sprintf('/%s%s', $this->getLang(), $path);
Please login to merge, or discard this patch.
src/Command/GettextCommand.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @var array
45 45
      */
46
-    protected $poResult = [];
46
+    protected $poResult = [ ];
47 47
 
48 48
     /**
49 49
      * The template paths
50 50
      *
51 51
      * @var array
52 52
      */
53
-    protected $templatePaths = [];
53
+    protected $templatePaths = [ ];
54 54
 
55 55
     /**
56 56
      * The locale path
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function execute(Arguments $args, ConsoleIo $io)
137 137
     {
138
-        $resCmd = [];
138
+        $resCmd = [ ];
139 139
         exec('which msgmerge 2>&1', $resCmd);
140
-        if (empty($resCmd[0])) {
140
+        if (empty($resCmd[ 0 ])) {
141 141
             $io->abort('ERROR: msgmerge not available. Please install gettext utilities.');
142 142
         }
143 143
 
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
         }
197 197
         $app = $args->getOption('app');
198 198
         $basePath = $app ?? getcwd();
199
-        $this->templatePaths = [$basePath . DS . 'src', $basePath . DS . 'config'];
199
+        $this->templatePaths = [ $basePath . DS . 'src', $basePath . DS . 'config' ];
200 200
         $this->templatePaths = array_merge($this->templatePaths, App::path(View::NAME_TEMPLATE));
201
-        $this->templatePaths = array_filter($this->templatePaths, function ($path) {
201
+        $this->templatePaths = array_filter($this->templatePaths, function($path) {
202 202
             return strpos($path, 'plugins') === false;
203 203
         });
204 204
         $this->localePath = (string)Hash::get($localesPaths, 0);
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
             $contents = preg_replace('/^msgid ""\nmsgstr ""/', '', $contents);
226 226
             $contents = trim(preg_replace('/^"([^"]*?)"$/m', '', $contents));
227 227
 
228
-            $lines = [];
228
+            $lines = [ ];
229 229
             ksort($poResult);
230 230
             foreach ($poResult as $res => $contexts) {
231 231
                 sort($contexts);
232 232
                 foreach ($contexts as $ctx) {
233 233
                     if (!empty($ctx)) {
234
-                        $lines[] = sprintf('msgctxt "%s"%smsgid "%s"%smsgstr ""', $ctx, "\n", $res, "\n");
234
+                        $lines[ ] = sprintf('msgctxt "%s"%smsgid "%s"%smsgstr ""', $ctx, "\n", $res, "\n");
235 235
                     } else {
236
-                        $lines[] = sprintf('msgid "%s"%smsgstr ""', $res, "\n");
236
+                        $lines[ ] = sprintf('msgid "%s"%smsgstr ""', $res, "\n");
237 237
                     }
238 238
                 }
239 239
             }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     private function writePoFiles(ConsoleIo $io): void
260 260
     {
261 261
         $header = $this->header('po');
262
-        $locales = array_keys((array)Configure::read('I18n.locales', []));
262
+        $locales = array_keys((array)Configure::read('I18n.locales', [ ]));
263 263
         foreach ($locales as $loc) {
264 264
             $potDir = $this->localePath . DS . $loc;
265 265
             if (!file_exists($potDir)) {
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
                 'Content-Type' => 'text/plain; charset=utf-8',
318 318
             ],
319 319
         ];
320
-        foreach ($contents[$type] as $k => $v) {
320
+        foreach ($contents[ $type ] as $k => $v) {
321 321
             $result .= sprintf('"%s: %s \n"', $k, $v) . "\n";
322 322
         }
323 323
 
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
                 $numItems++;
341 341
             }
342 342
             if (strpos($l, 'msgstr ""') === 0) {
343
-                if (!isset($lines[$k + 1])) {
343
+                if (!isset($lines[ $k + 1 ])) {
344 344
                     $numNotTranslated++;
345
-                } elseif (strpos($lines[$k + 1], '"') !== 0) {
345
+                } elseif (strpos($lines[ $k + 1 ], '"') !== 0) {
346 346
                     $numNotTranslated++;
347 347
                 }
348 348
             }
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      */
392 392
     private function parseFile($file, $extension)
393 393
     {
394
-        if (!in_array($extension, ['php', 'twig'])) {
394
+        if (!in_array($extension, [ 'php', 'twig' ])) {
395 395
             return;
396 396
         }
397 397
         $content = file_get_contents($file);
@@ -422,34 +422,34 @@  discard block
 block discarded – undo
422 422
 
423 423
         foreach ($functions as $fname => $singularPosition) {
424 424
             $capturePath = "'[^']*'";
425
-            $doubleQuoteCapture = str_replace("'", $options['double_quote'], $capturePath);
426
-            $quoteCapture = str_replace("'", $options['quote'], $capturePath);
425
+            $doubleQuoteCapture = str_replace("'", $options[ 'double_quote' ], $capturePath);
426
+            $quoteCapture = str_replace("'", $options[ 'quote' ], $capturePath);
427 427
 
428 428
             // phpcs:disable
429
-            $rgxp = '/' . $fname . '\s*' . $options['open_parenthesis'] . str_repeat('((?:' . $doubleQuoteCapture . ')|(?:' . $quoteCapture . '))\s*[,)]\s*', $singularPosition + 1) . '/';
429
+            $rgxp = '/' . $fname . '\s*' . $options[ 'open_parenthesis' ] . str_repeat('((?:' . $doubleQuoteCapture . ')|(?:' . $quoteCapture . '))\s*[,)]\s*', $singularPosition + 1) . '/';
430 430
             // phpcs:enable
431 431
 
432
-            $matches = [];
432
+            $matches = [ ];
433 433
             preg_match_all($rgxp, $content, $matches);
434 434
 
435
-            $limit = count($matches[0]);
435
+            $limit = count($matches[ 0 ]);
436 436
             for ($i = 0; $i < $limit; $i++) {
437 437
                 $domain = $this->defaultDomain;
438 438
                 $ctx = '';
439
-                $str = $this->unquoteString($matches[1][$i]);
439
+                $str = $this->unquoteString($matches[ 1 ][ $i ]);
440 440
 
441 441
                 if (strpos($fname, '__d') === 0) {
442
-                    $domain = $this->unquoteString($matches[1][$i]);
442
+                    $domain = $this->unquoteString($matches[ 1 ][ $i ]);
443 443
 
444 444
                     if (strpos($fname, '__dx') === 0) {
445
-                        $ctx = $this->unquoteString($matches[2][$i]);
446
-                        $str = $this->unquoteString($matches[3][$i]);
445
+                        $ctx = $this->unquoteString($matches[ 2 ][ $i ]);
446
+                        $str = $this->unquoteString($matches[ 3 ][ $i ]);
447 447
                     } else {
448
-                        $str = $this->unquoteString($matches[2][$i]);
448
+                        $str = $this->unquoteString($matches[ 2 ][ $i ]);
449 449
                     }
450 450
                 } elseif (strpos($fname, '__x') === 0) {
451
-                    $ctx = $this->unquoteString($matches[1][$i]);
452
-                    $str = $this->unquoteString($matches[2][$i]);
451
+                    $ctx = $this->unquoteString($matches[ 1 ][ $i ]);
452
+                    $str = $this->unquoteString($matches[ 2 ][ $i ]);
453 453
                 }
454 454
 
455 455
                 $str = $this->fixString($str);
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
                 }
459 459
 
460 460
                 if (!array_key_exists($domain, $this->poResult)) {
461
-                    $this->poResult[$domain] = [];
461
+                    $this->poResult[ $domain ] = [ ];
462 462
                 }
463 463
 
464
-                if (!array_key_exists($str, $this->poResult[$domain])) {
465
-                    $this->poResult[$domain][$str] = [''];
464
+                if (!array_key_exists($str, $this->poResult[ $domain ])) {
465
+                    $this->poResult[ $domain ][ $str ] = [ '' ];
466 466
                 }
467 467
 
468
-                if (!in_array($ctx, $this->poResult[$domain][$str])) {
469
-                    $this->poResult[$domain][$str][] = $ctx;
468
+                if (!in_array($ctx, $this->poResult[ $domain ][ $str ])) {
469
+                    $this->poResult[ $domain ][ $str ][ ] = $ctx;
470 470
                 }
471 471
             }
472 472
         }
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
                 if (!is_dir($file)) {
488 488
                     $f = new File($file);
489 489
                     $info = $f->info();
490
-                    if (isset($info['extension'])) {
491
-                        $this->parseFile($file, $info['extension']);
490
+                    if (isset($info[ 'extension' ])) {
491
+                        $this->parseFile($file, $info[ 'extension' ]);
492 492
                     }
493 493
                 }
494 494
             }
Please login to merge, or discard this patch.
src/Middleware/I18nMiddleware.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
      * @var array
60 60
      */
61 61
     protected $_defaultConfig = [
62
-        'match' => [],
63
-        'startWith' => [],
62
+        'match' => [ ],
63
+        'startWith' => [ ],
64 64
         'switchLangUrl' => null,
65 65
         'cookie' => [
66 66
             'name' => null,
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      *
76 76
      * @param array $config Configuration.
77 77
      */
78
-    public function __construct(array $config = [])
78
+    public function __construct(array $config = [ ])
79 79
     {
80 80
         $this->setConfig($config);
81 81
     }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
         $locale = array_search($new, $this->getLocales());
245 245
         if ($locale === false) {
246
-            throw new BadRequestException(__('Lang "{0}" not supported', [$new]));
246
+            throw new BadRequestException(__('Lang "{0}" not supported', [ $new ]));
247 247
         }
248 248
 
249 249
         $redirect = (string)$request->getQuery('redirect', $request->referer(false));
Please login to merge, or discard this patch.