Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/Command/GettextCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))),
]);
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Filesystem/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
2 changes: 1 addition & 1 deletion src/Filesystem/Gettext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '---------------------';
}
Expand Down
20 changes: 11 additions & 9 deletions src/Filesystem/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -103,29 +103,31 @@ 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),
[
Plugin::classPath($plugin),
dirname(Plugin::classPath($plugin)) . DS . 'config',
],
),
$templatePathsTmp
$templatePathsTmp,
);
$templatePaths = $templatePathsTmp;
$localesPaths = (array)App::path('locales');
Expand Down
2 changes: 1 addition & 1 deletion src/Filesystem/Ttag.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function doExtract(
string $appDir,
string $localePath,
array $locales,
?string $plugin = null
?string $plugin = null,
): bool {
$result = true;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/I18nPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/I18nMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
);
}

Expand Down Expand Up @@ -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`',
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/View/Helper/I18nHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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));
Expand All @@ -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',
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Routing/Route/I18nRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testMatchUseCurrentLang(): void
{
$route = new I18nRoute(
'/gustavo/help',
['controller' => 'GustavoSupporto', 'action' => 'help']
['controller' => 'GustavoSupporto', 'action' => 'help'],
);

$result = $route->match([
Expand All @@ -197,7 +197,7 @@ public function testMatchUseCustomLang(): void
{
$route = new I18nRoute(
'/gustavo/help',
['controller' => 'GustavoSupporto', 'action' => 'help']
['controller' => 'GustavoSupporto', 'action' => 'help'],
);

$result = $route->match([
Expand All @@ -219,7 +219,7 @@ public function testMatchInvalidLang(): void
{
$route = new I18nRoute(
'/gustavo/help',
['controller' => 'GustavoSupporto', 'action' => 'help']
['controller' => 'GustavoSupporto', 'action' => 'help'],
);

$result = $route->match([
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/I18nHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function setUp(): void
$routeBuilder->connect(
'/test',
['controller' => 'TestApp', 'action' => 'test'],
['_name' => 'test']
['_name' => 'test'],
);
Router::setRouteCollection(Router::getRouteCollection());
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_dir/sample.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php
declare(strict_types=1);

echo __('Sample php');