@@ -43,7 +43,7 @@ discard block |
||
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 |
||
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 | /** |
@@ -64,7 +64,7 @@ |
||
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; |
@@ -29,12 +29,12 @@ discard block |
||
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 |
||
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; |
@@ -33,7 +33,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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); |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @var array |
59 | 59 | */ |
60 | 60 | protected $_defaultConfig = [ |
61 | - 'match' => [], |
|
62 | - 'startWith' => [], |
|
61 | + 'match' => [ ], |
|
62 | + 'startWith' => [ ], |
|
63 | 63 | 'switchLangUrl' => null, |
64 | 64 | 'cookie' => [ |
65 | 65 | 'name' => null, |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param array $config Configuration. |
76 | 76 | */ |
77 | - public function __construct(array $config = []) |
|
77 | + public function __construct(array $config = [ ]) |
|
78 | 78 | { |
79 | 79 | $this->setConfig($config); |
80 | 80 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $locale = array_search($new, $this->getLocales()); |
244 | 244 | if ($locale === false) { |
245 | - throw new BadRequestException(__('Lang "{0}" not supported', [$new])); |
|
245 | + throw new BadRequestException(__('Lang "{0}" not supported', [ $new ])); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | $this->updateSession($request, $locale); |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @var array |
70 | 70 | */ |
71 | - protected $poResult = []; |
|
71 | + protected $poResult = [ ]; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * The template paths |
75 | 75 | * |
76 | 76 | * @var array |
77 | 77 | */ |
78 | - protected $templatePaths = []; |
|
78 | + protected $templatePaths = [ ]; |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * The locale path |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function update(): void |
100 | 100 | { |
101 | - $resCmd = []; |
|
101 | + $resCmd = [ ]; |
|
102 | 102 | exec('which msgmerge 2>&1', $resCmd); |
103 | - if (empty($resCmd[0])) { |
|
103 | + if (empty($resCmd[ 0 ])) { |
|
104 | 104 | $this->out('ERROR: msgmerge not available. Please install gettext utilities.'); |
105 | 105 | |
106 | 106 | return; |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | private function setupPaths(): void |
136 | 136 | { |
137 | 137 | $basePath = getcwd(); |
138 | - if (isset($this->params['app'])) { |
|
139 | - $f = new Folder($this->params['app']); |
|
138 | + if (isset($this->params[ 'app' ])) { |
|
139 | + $f = new Folder($this->params[ 'app' ]); |
|
140 | 140 | $basePath = $f->path; |
141 | - } elseif (isset($this->params['plugin'])) { |
|
142 | - $startPath = !empty($this->params['startPath']) ? $this->params['startPath'] : getcwd(); |
|
143 | - $f = new Folder(sprintf('%s/plugins/%s', $startPath, $this->params['plugin'])); |
|
141 | + } elseif (isset($this->params[ 'plugin' ])) { |
|
142 | + $startPath = !empty($this->params[ 'startPath' ]) ? $this->params[ 'startPath' ] : getcwd(); |
|
143 | + $f = new Folder(sprintf('%s/plugins/%s', $startPath, $this->params[ 'plugin' ])); |
|
144 | 144 | $basePath = $f->path; |
145 | - $this->poName = $this->params['plugin'] . '.po'; |
|
145 | + $this->poName = $this->params[ 'plugin' ] . '.po'; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $this->templatePaths = [ |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | $header = $this->header('po'); |
184 | 184 | $potFilename = sprintf('%s/master.pot', $this->localePath); |
185 | - $locales = array_keys((array)Configure::read('I18n.locales', [])); |
|
185 | + $locales = array_keys((array)Configure::read('I18n.locales', [ ])); |
|
186 | 186 | foreach ($locales as $loc) { |
187 | 187 | $potDir = $this->localePath . DS . $loc; |
188 | 188 | if (!file_exists($potDir)) { |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | 'Content-Type' => 'text/plain; charset=utf-8', |
237 | 237 | ], |
238 | 238 | ]; |
239 | - foreach ($contents[$type] as $k => $v) { |
|
239 | + foreach ($contents[ $type ] as $k => $v) { |
|
240 | 240 | $result .= sprintf('"%s: %s \n"', $k, $v) . "\n"; |
241 | 241 | } |
242 | 242 | |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | $numItems++; |
259 | 259 | } |
260 | 260 | if (strpos($l, 'msgstr ""') === 0) { |
261 | - if (!isset($lines[$k + 1])) { |
|
261 | + if (!isset($lines[ $k + 1 ])) { |
|
262 | 262 | $numNotTranslated++; |
263 | - } elseif (strpos($lines[$k + 1], '"') !== 0) { |
|
263 | + } elseif (strpos($lines[ $k + 1 ], '"') !== 0) { |
|
264 | 264 | $numNotTranslated++; |
265 | 265 | } |
266 | 266 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | */ |
299 | 299 | private function parseFile($file, $extension) |
300 | 300 | { |
301 | - if (!in_array($extension, ['php', 'twig'])) { |
|
301 | + if (!in_array($extension, [ 'php', 'twig' ])) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | $content = file_get_contents($file); |
@@ -350,22 +350,22 @@ discard block |
||
350 | 350 | { |
351 | 351 | // phpcs:disable |
352 | 352 | $rgxp = '/' . |
353 | - "${start}\s*{$options['open_parenthesis']}\s*{$options['double_quote']}" . "([^{$options['double_quote']}]*)" . "{$options['double_quote']}" . |
|
353 | + "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'double_quote' ]}" . "([^{$options[ 'double_quote' ]}]*)" . "{$options[ 'double_quote' ]}" . |
|
354 | 354 | '|' . |
355 | - "${start}\s*{$options['open_parenthesis']}\s*{$options['quote']}" . "([^{$options['quote']}]*)" . "{$options['quote']}" . |
|
355 | + "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'quote' ]}" . "([^{$options[ 'quote' ]}]*)" . "{$options[ 'quote' ]}" . |
|
356 | 356 | '/'; |
357 | 357 | // phpcs:enable |
358 | - $matches = []; |
|
358 | + $matches = [ ]; |
|
359 | 359 | preg_match_all($rgxp, $content, $matches); |
360 | 360 | |
361 | - $limit = count($matches[0]); |
|
361 | + $limit = count($matches[ 0 ]); |
|
362 | 362 | for ($i = 0; $i < $limit; $i++) { |
363 | - $item = $this->fixString($matches[1][$i]); |
|
363 | + $item = $this->fixString($matches[ 1 ][ $i ]); |
|
364 | 364 | if (empty($item)) { |
365 | - $item = $this->fixString($matches[2][$i]); |
|
365 | + $item = $this->fixString($matches[ 2 ][ $i ]); |
|
366 | 366 | } |
367 | 367 | if (!in_array($item, $this->poResult)) { |
368 | - $this->poResult[] = $item; |
|
368 | + $this->poResult[ ] = $item; |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | } |
@@ -382,26 +382,26 @@ discard block |
||
382 | 382 | { |
383 | 383 | // phpcs:disable |
384 | 384 | $rgxp = |
385 | - '/' . "${start}\s*{$options['open_parenthesis']}\s*{$options['double_quote']}" . '([^{)}]*)' . "{$options['double_quote']}" . |
|
386 | - '|' . "${start}\s*{$options['open_parenthesis']}\s*{$options['quote']}" . '([^{)}]*)' . "{$options['quote']}" . |
|
385 | + '/' . "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'double_quote' ]}" . '([^{)}]*)' . "{$options[ 'double_quote' ]}" . |
|
386 | + '|' . "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'quote' ]}" . '([^{)}]*)' . "{$options[ 'quote' ]}" . |
|
387 | 387 | '/'; |
388 | 388 | // phpcs:enable |
389 | - $matches = []; |
|
389 | + $matches = [ ]; |
|
390 | 390 | preg_match_all($rgxp, $content, $matches); |
391 | 391 | |
392 | - $limit = count($matches[0]); |
|
392 | + $limit = count($matches[ 0 ]); |
|
393 | 393 | for ($i = 0; $i < $limit; $i++) { |
394 | - $str = $matches[2][$i]; |
|
395 | - if (substr_count($matches[2][0], ',') === 1) { |
|
394 | + $str = $matches[ 2 ][ $i ]; |
|
395 | + if (substr_count($matches[ 2 ][ 0 ], ',') === 1) { |
|
396 | 396 | $str = substr(trim(substr($str, strpos($str, ',') + 1)), 1); |
397 | - } elseif (substr_count($matches[2][0], ',') === 2) { |
|
397 | + } elseif (substr_count($matches[ 2 ][ 0 ], ',') === 2) { |
|
398 | 398 | $str = trim(substr($str, strpos($str, ',') + 1)); |
399 | 399 | $str = trim(substr($str, 0, strpos($str, ','))); |
400 | 400 | $str = substr($str, 1, -1); |
401 | 401 | } |
402 | 402 | $item = $this->fixString($str); |
403 | 403 | if (!in_array($item, $this->poResult)) { |
404 | - $this->poResult[] = $item; |
|
404 | + $this->poResult[ ] = $item; |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
@@ -418,16 +418,16 @@ discard block |
||
418 | 418 | { |
419 | 419 | // phpcs:disable |
420 | 420 | $rgxp = |
421 | - '/' . "${start}\s*{$options['open_parenthesis']}\s*{$options['double_quote']}" . '([^{)}]*)' . "{$options['double_quote']}" . |
|
422 | - '|' . "${start}\s*{$options['open_parenthesis']}\s*{$options['quote']}" . '([^{)}]*)' . "{$options['quote']}" . |
|
421 | + '/' . "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'double_quote' ]}" . '([^{)}]*)' . "{$options[ 'double_quote' ]}" . |
|
422 | + '|' . "${start}\s*{$options[ 'open_parenthesis' ]}\s*{$options[ 'quote' ]}" . '([^{)}]*)' . "{$options[ 'quote' ]}" . |
|
423 | 423 | '/'; |
424 | 424 | // phpcs:enable |
425 | - $matches = []; |
|
425 | + $matches = [ ]; |
|
426 | 426 | preg_match_all($rgxp, $content, $matches); |
427 | 427 | |
428 | - $limit = count($matches[0]); |
|
428 | + $limit = count($matches[ 0 ]); |
|
429 | 429 | for ($i = 0; $i < $limit; $i++) { |
430 | - $str = $matches[2][$i]; |
|
430 | + $str = $matches[ 2 ][ $i ]; |
|
431 | 431 | $pos = $this->strposX($str, ',', 2); |
432 | 432 | $str = trim(substr($str, $pos + 1)); |
433 | 433 | if (strpos($str, ',') > 0) { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | } |
438 | 438 | $item = $this->fixString($str); |
439 | 439 | if (!in_array($item, $this->poResult)) { |
440 | - $this->poResult[] = $item; |
|
440 | + $this->poResult[ ] = $item; |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | } |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | if (!is_dir($file)) { |
476 | 476 | $f = new File($file); |
477 | 477 | $info = $f->info(); |
478 | - if (isset($info['extension'])) { |
|
479 | - $this->parseFile($file, $info['extension']); |
|
478 | + if (isset($info[ 'extension' ])) { |
|
479 | + $this->parseFile($file, $info[ 'extension' ]); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | } |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | } |
501 | 501 | // check template folder exists |
502 | 502 | $appDir = 'src/Template'; |
503 | - if (!empty($this->params['plugin'])) { |
|
504 | - $startPath = !empty($this->params['startPath']) ? $this->params['startPath'] : getcwd(); |
|
505 | - $appDir = sprintf('%s/plugins/%s/src/Template', $startPath, $this->params['plugin']); |
|
503 | + if (!empty($this->params[ 'plugin' ])) { |
|
504 | + $startPath = !empty($this->params[ 'startPath' ]) ? $this->params[ 'startPath' ] : getcwd(); |
|
505 | + $appDir = sprintf('%s/plugins/%s/src/Template', $startPath, $this->params[ 'plugin' ]); |
|
506 | 506 | } |
507 | 507 | if (!file_exists($appDir)) { |
508 | 508 | $this->out(sprintf('Skip javascript parsing - %s folder not found', $appDir)); |