diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index cfc0fb5..dc82278 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,3 +29,10 @@ jobs: php_versions: '["8.3","8.4"]' bedita_version: '5' coverage_min_percentage: 99 + + unit-6: + uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2 + with: + php_versions: '["8.4"]' + bedita_version: '6' + coverage_min_percentage: 99 diff --git a/composer.json b/composer.json index 2e7aac3..41d0db2 100644 --- a/composer.json +++ b/composer.json @@ -40,10 +40,16 @@ "@test", "@cs-check" ], + "cs-setup": [ + "vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer", + "vendor/bin/phpcs --config-set default_standard CakePHP", + "vendor/bin/phpcs --config-set colors 1" + ], + "cs-check": "vendor/bin/phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", + "cs-fix": "vendor/bin/phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "stan": "vendor/bin/phpstan analyse", - "cs-check": "vendor/bin/phpcs", - "cs-fix": "vendor/bin/phpcbf", "test": "vendor/bin/phpunit --colors=always", + "coverage": "vendor/bin/phpunit --colors=always --coverage-html coverage", "update-dev": [ "@composer update", "@cs-setup" diff --git a/src/Command/GettextCommand.php b/src/Command/GettextCommand.php index c7c4683..a51f52e 100644 --- a/src/Command/GettextCommand.php +++ b/src/Command/GettextCommand.php @@ -106,7 +106,8 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar 'boolean' => true, ]) ->addOption('locales', [ - 'help' => 'Comma separated list of locales to generate. Leave empty to use configuration `I18n.locales`', + 'help' => 'Comma separated list of locales to generate. ' . + 'Leave empty to use configuration `I18n.locales`', 'short' => 'l', 'default' => implode(',', array_keys((array)Configure::read('I18n.locales'))), ]); @@ -125,7 +126,8 @@ public function execute(Arguments $args, ConsoleIo $io): int $resCmd = []; exec('which msgmerge 2>&1', $resCmd); - $msg = empty($resCmd[0]) ? 'ERROR: msgmerge not available. Please install gettext utilities.' : 'OK: msgmerge found'; + $errorMsg = 'ERROR: msgmerge not available. Please install gettext utilities.'; + $msg = empty($resCmd[0]) ? $errorMsg : 'OK: msgmerge found'; $method = empty($resCmd[0]) ? 'abort' : 'out'; $io->{$method}($msg); diff --git a/src/Filesystem/File.php b/src/Filesystem/File.php index 2d078b6..6006eec 100644 --- a/src/Filesystem/File.php +++ b/src/Filesystem/File.php @@ -44,8 +44,8 @@ public static function parseDir(string $dir, string $defaultDomain, array &$tran new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, - RecursiveDirectoryIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::CURRENT_AS_PATHNAME - ) + RecursiveDirectoryIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::CURRENT_AS_PATHNAME, + ), ), '/.*\.(php|ctp|thtml|inc|tpl|twig)/i', ); diff --git a/src/Filesystem/Gettext.php b/src/Filesystem/Gettext.php index e597f93..f4d7cce 100644 --- a/src/Filesystem/Gettext.php +++ b/src/Filesystem/Gettext.php @@ -180,7 +180,7 @@ public static function writePoFiles(array $locales, string $localePath, array &$ 'Translated %d of %d items - %s %%', $analysis['translated'], $analysis['numItems'], - $analysis['percent'] + $analysis['percent'], ); $info[] = '---------------------'; } diff --git a/src/Filesystem/Paths.php b/src/Filesystem/Paths.php index 0474e39..ca195dc 100644 --- a/src/Filesystem/Paths.php +++ b/src/Filesystem/Paths.php @@ -43,7 +43,7 @@ public static function setup( array &$templatePaths, string &$localePath, string &$defaultDomain, - array $options + array $options, ): void { if (Hash::get($options, 'plugins') === true) { self::setupPlugins($templatePaths, $localePath); @@ -78,14 +78,14 @@ public static function setupPlugin( array &$templatePaths, string &$localePath, string &$defaultDomain, - string $plugin + string $plugin, ): void { $templatePaths = array_merge( [ Plugin::classPath($plugin), Plugin::configPath($plugin), ], - App::path(View::NAME_TEMPLATE, $plugin) + App::path(View::NAME_TEMPLATE, $plugin), ); $defaultDomain = $plugin; $localePath = (string)Hash::get((array)App::path('locales', $plugin), '0'); @@ -103,21 +103,23 @@ public static function setupPlugins(array &$templatePaths, string &$localePath): $pluginsPaths = App::path('plugins'); $plugins = array_reduce( $pluginsPaths, - fn (array $acc, string $path) => array_merge( + fn(array $acc, string $path) => array_merge( $acc, array_filter( (array)scandir($path), - fn ($file) => is_string($file) && !in_array($file, ['.', '..']) && Plugin::getCollection()->has($file) - ) + fn($file) => is_string($file) + && !in_array($file, ['.', '..']) + && Plugin::getCollection()->has($file), + ), ), - [] + [], ); $templatePathsTmp = App::path('templates'); $templatePathsTmp[] = APP; $templatePathsTmp[] = dirname(APP) . DS . 'config'; $templatePathsTmp = array_reduce( $plugins, - fn (array $acc, string $plugin) => array_merge( + fn(array $acc, string $plugin) => array_merge( $acc, App::path('templates', $plugin), [ @@ -125,7 +127,7 @@ public static function setupPlugins(array &$templatePaths, string &$localePath): dirname(Plugin::classPath($plugin)) . DS . 'config', ], ), - $templatePathsTmp + $templatePathsTmp, ); $templatePaths = $templatePathsTmp; $localesPaths = (array)App::path('locales'); diff --git a/src/Filesystem/Ttag.php b/src/Filesystem/Ttag.php index 41ad7e4..19f1f91 100644 --- a/src/Filesystem/Ttag.php +++ b/src/Filesystem/Ttag.php @@ -84,7 +84,7 @@ public static function doExtract( string $appDir, string $localePath, array $locales, - ?string $plugin = null + ?string $plugin = null, ): bool { $result = true; try { diff --git a/src/I18nPlugin.php b/src/I18nPlugin.php index 46b41ac..136b174 100644 --- a/src/I18nPlugin.php +++ b/src/I18nPlugin.php @@ -96,7 +96,7 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue */ $middlewareQueue->insertBefore( RoutingMiddleware::class, - new I18nMiddleware((array)Configure::read('I18n', [])) + new I18nMiddleware((array)Configure::read('I18n', [])), ); return $middlewareQueue; diff --git a/src/Middleware/I18nMiddleware.php b/src/Middleware/I18nMiddleware.php index f6abf0b..fb22e14 100644 --- a/src/Middleware/I18nMiddleware.php +++ b/src/Middleware/I18nMiddleware.php @@ -191,7 +191,7 @@ protected function setupLocale(?string $locale): void if (empty($lang) || $locale === false) { throw new InternalErrorException( - 'Something was wrong with I18n configuration. Check "I18n.locales" and "I18n.default"' + 'Something was wrong with I18n configuration. Check "I18n.locales" and "I18n.default"', ); } @@ -235,7 +235,7 @@ protected function changeLangAndRedirect(ServerRequest $request): ResponseInterf { if (!$this->getConfig('cookie.name') && !$this->getSessionKey()) { throw new LogicException( - 'I18nMiddleware misconfigured. `switchLangUrl` requires `cookie.name` or `sessionKey`' + 'I18nMiddleware misconfigured. `switchLangUrl` requires `cookie.name` or `sessionKey`', ); } diff --git a/src/View/Helper/I18nHelper.php b/src/View/Helper/I18nHelper.php index 15d4e11..fb2b5b8 100644 --- a/src/View/Helper/I18nHelper.php +++ b/src/View/Helper/I18nHelper.php @@ -164,14 +164,14 @@ public function field( string $attribute, ?string $lang = null, bool $defaultNull = false, - array $included = [] + array $included = [], ): ?string { $defaultValue = null; if (!$defaultNull) { $defaultValue = Hash::get( $object, sprintf('attributes.%s', $attribute), - Hash::get($object, sprintf('%s', $attribute)) + Hash::get($object, sprintf('%s', $attribute)), ); } if (empty($included) && !empty($this->_View->get('included'))) { @@ -243,7 +243,7 @@ private function getTranslatedField(array $object, string $attribute, string $la $translations = Hash::combine( $object['relationships']['translations']['data'], '{n}.attributes.lang', - '{n}.attributes.translated_fields' + '{n}.attributes.translated_fields', ); return Hash::get($translations, sprintf('%s.%s', $lang, $attribute)); @@ -261,7 +261,7 @@ private function getTranslatedField(array $object, string $attribute, string $la $translations, 'translations.{n}.lang', 'translations.{n}.translated_fields', - 'translations.{n}.object_id' + 'translations.{n}.object_id', ); } diff --git a/tests/TestCase/Routing/Route/I18nRouteTest.php b/tests/TestCase/Routing/Route/I18nRouteTest.php index 5a41e2d..6b4f07c 100644 --- a/tests/TestCase/Routing/Route/I18nRouteTest.php +++ b/tests/TestCase/Routing/Route/I18nRouteTest.php @@ -177,7 +177,7 @@ public function testMatchUseCurrentLang(): void { $route = new I18nRoute( '/gustavo/help', - ['controller' => 'GustavoSupporto', 'action' => 'help'] + ['controller' => 'GustavoSupporto', 'action' => 'help'], ); $result = $route->match([ @@ -197,7 +197,7 @@ public function testMatchUseCustomLang(): void { $route = new I18nRoute( '/gustavo/help', - ['controller' => 'GustavoSupporto', 'action' => 'help'] + ['controller' => 'GustavoSupporto', 'action' => 'help'], ); $result = $route->match([ @@ -219,7 +219,7 @@ public function testMatchInvalidLang(): void { $route = new I18nRoute( '/gustavo/help', - ['controller' => 'GustavoSupporto', 'action' => 'help'] + ['controller' => 'GustavoSupporto', 'action' => 'help'], ); $result = $route->match([ diff --git a/tests/TestCase/View/Helper/I18nHelperTest.php b/tests/TestCase/View/Helper/I18nHelperTest.php index e69108d..b7e6a89 100644 --- a/tests/TestCase/View/Helper/I18nHelperTest.php +++ b/tests/TestCase/View/Helper/I18nHelperTest.php @@ -103,7 +103,7 @@ public function setUp(): void $routeBuilder->connect( '/test', ['controller' => 'TestApp', 'action' => 'test'], - ['_name' => 'test'] + ['_name' => 'test'], ); Router::setRouteCollection(Router::getRouteCollection()); } diff --git a/tests/test_dir/sample.php b/tests/test_dir/sample.php index 852759e..ae4c9f0 100644 --- a/tests/test_dir/sample.php +++ b/tests/test_dir/sample.php @@ -1,3 +1,4 @@