From 49000ca587590dbc4ca6f5e59697163f2ff8ce88 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Sat, 29 Apr 2023 20:08:36 +0200 Subject: phpstan level 9 for check.translation.php (#5353) * phpstan level 7 for check.translation.php * Fixes --------- Co-authored-by: Luc Co-authored-by: Alexandre Alapetite --- cli/check.translation.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'cli/check.translation.php') diff --git a/cli/check.translation.php b/cli/check.translation.php index 59f59f94b..34b43244f 100755 --- a/cli/check.translation.php +++ b/cli/check.translation.php @@ -9,11 +9,13 @@ require_once __DIR__ . '/i18n/I18nUsageValidator.php'; $i18nFile = new I18nFile(); $i18nData = new I18nData($i18nFile->load()); -$options = getopt("dhl:r"); +/** @var array|false $options */ +$options = getopt('dhl:r'); -if (array_key_exists('h', $options)) { +if (!is_array($options) || array_key_exists('h', $options)) { checkHelp(); } + if (array_key_exists('l', $options)) { $languages = array($options['l']); } else { @@ -23,17 +25,16 @@ $displayResults = array_key_exists('d', $options); $displayReport = array_key_exists('r', $options); $isValidated = true; -$result = array(); -$report = array(); +$result = []; +$report = []; foreach ($languages as $language) { if ($language === $i18nData::REFERENCE_LANGUAGE) { $i18nValidator = new I18nUsageValidator($i18nData->getReferenceLanguage(), findUsedTranslations()); - $isValidated = $i18nValidator->validate() && $isValidated; } else { $i18nValidator = new I18nCompletionValidator($i18nData->getReferenceLanguage(), $i18nData->getLanguage($language)); - $isValidated = $i18nValidator->validate() && $isValidated; } + $isValidated = $i18nValidator->validate() && $isValidated; $report[$language] = sprintf('%-5s - %s', $language, $i18nValidator->displayReport()); $result[$language] = $i18nValidator->displayResult(); @@ -69,9 +70,12 @@ function findUsedTranslations(): array { $directory = new RecursiveDirectoryIterator(__DIR__ . '/..'); $iterator = new RecursiveIteratorIterator($directory); $regex = new RegexIterator($iterator, '/^.+\.(php|phtml)$/i', RecursiveRegexIterator::GET_MATCH); - $usedI18n = array(); + $usedI18n = []; foreach (array_keys(iterator_to_array($regex)) as $file) { $fileContent = file_get_contents($file); + if ($fileContent === false) { + continue; + } preg_match_all('/_t\([\'"](?P[^\'"]+)[\'"]/', $fileContent, $matches); $usedI18n = array_merge($usedI18n, $matches['strings']); } -- cgit v1.2.3