From b8662f88995df2cbae655d4efe8f414eb3872e5e Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Fri, 14 Apr 2023 23:08:38 +0200 Subject: PHPstan level 6 for I18nFile.php (#5291) * PHPstan level 6 for I18nFile.php * Minor syntax * PHPstan level 6 for I18nFiles * PHPstan level 6 for I18nFiles * PHPstan level 6 for I18n Files * PHPstan level 6 for I18n Files * Fix several type errors --------- Co-authored-by: Luc Co-authored-by: Alexandre Alapetite --- cli/i18n/I18nFile.php | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'cli/i18n/I18nFile.php') diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php index 12a04c6a2..1c8987c64 100644 --- a/cli/i18n/I18nFile.php +++ b/cli/i18n/I18nFile.php @@ -3,7 +3,10 @@ require_once __DIR__ . '/I18nValue.php'; class I18nFile { - public function load() { + /** + * @return array>> + */ + public function load(): array { $i18n = array(); $dirs = new DirectoryIterator(I18N_PATH); foreach ($dirs as $dir) { @@ -23,7 +26,10 @@ class I18nFile { return $i18n; } - public function dump(array $i18n) { + /** + * @param array>> $i18n + */ + public function dump(array $i18n): void { foreach ($i18n as $language => $file) { $dir = I18N_PATH . DIRECTORY_SEPARATOR . $language; if (!file_exists($dir)) { @@ -38,13 +44,11 @@ class I18nFile { /** * Process the content of an i18n file - * - * @param string $filename - * @return array + * @return array> */ - private function process(string $filename) { - $content = file_get_contents($filename); - $content = str_replace('> $translation * @param string $prefix - * @return array + * @return array */ - private function flatten(array $translation, string $prefix = '') { + private function flatten(array $translation, string $prefix = ''): array { $a = array(); if ('' !== $prefix) { @@ -104,10 +108,10 @@ class I18nFile { * The first key is dropped since it represents the filename and we have * no use of it. * - * @param array $translation - * @return array + * @param array $translation + * @return array> */ - private function unflatten(array $translation) { + private function unflatten(array $translation): array { $a = array(); ksort($translation, SORT_NATURAL); @@ -127,10 +131,9 @@ class I18nFile { * translation file. The array is first converted to a string then some * formatting regexes are applied to match the original content. * - * @param array $translation - * @return string + * @param array $translation */ - private function format(array $translation) { + private function format(array $translation): string { $translation = var_export($this->unflatten($translation), true); $patterns = array( '/ -> todo\',/', -- cgit v1.2.3