From 541056f6c284953a0435d180b8620b55e344a5f4 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 21 Feb 2018 14:32:04 +0100 Subject: [PATCH 1/4] Make OCP\IL10N strict Signed-off-by: Roeland Jago Douma --- lib/private/L10N/L10N.php | 38 +++++++++++++++++++------------------- lib/public/IL10N.php | 9 +++++---- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index e9e720a376..5e74b25a1c 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -1,4 +1,5 @@ app = $app; $this->lang = $lang; - $this->translations = []; foreach ($files as $languageFile) { $this->load($languageFile); } @@ -71,7 +71,7 @@ class L10N implements IL10N { * * @return string language */ - public function getLanguageCode() { + public function getLanguageCode(): string { return $this->lang; } @@ -84,7 +84,7 @@ class L10N implements IL10N { * Returns the translation. If no translation is found, $text will be * returned. */ - public function t($text, $parameters = array()) { + public function t(string $text, array $parameters = []): string { return (string) new L10NString($this, $text, $parameters); } @@ -103,17 +103,17 @@ class L10N implements IL10N { * provided by the po file. * */ - public function n($text_singular, $text_plural, $count, $parameters = array()) { + public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string { $identifier = "_${text_singular}_::_${text_plural}_"; if (isset($this->translations[$identifier])) { return (string) new L10NString($this, $identifier, $parameters, $count); - } else { - if ($count === 1) { - return (string) new L10NString($this, $text_singular, $parameters, $count); - } else { - return (string) new L10NString($this, $text_plural, $parameters, $count); - } } + + if ($count === 1) { + return (string) new L10NString($this, $text_singular, $parameters, $count); + } + + return (string) new L10NString($this, $text_plural, $parameters, $count); } /** @@ -138,7 +138,7 @@ class L10N implements IL10N { * - firstday: Returns the first day of the week (0 sunday - 6 saturday) * - jsdate: Returns the short JS date format */ - public function l($type, $data = null, $options = array()) { + public function l(string $type, $data = null, array $options = []) { // Use the language of the instance $locale = $this->getLanguageCode(); if ($locale === 'sr@latin') { @@ -155,14 +155,14 @@ class L10N implements IL10N { $value = new \DateTime(); if ($data instanceof \DateTime) { $value = $data; - } else if (is_string($data) && !is_numeric($data)) { + } else if (\is_string($data) && !is_numeric($data)) { $data = strtotime($data); $value->setTimestamp($data); } else if ($data !== null) { $value->setTimestamp($data); } - $options = array_merge(array('width' => 'long'), $options); + $options = array_merge(['width' => 'long'], $options); $width = $options['width']; switch ($type) { case 'date': @@ -184,7 +184,7 @@ class L10N implements IL10N { * Called by \OC_L10N_String * @return array */ - public function getTranslations() { + public function getTranslations(): array { return $this->translations; } @@ -194,8 +194,8 @@ class L10N implements IL10N { * Called by \OC_L10N_String * @return string the plural form function */ - public function getPluralFormFunction() { - if (is_null($this->pluralFormFunction)) { + public function getPluralFormFunction(): string { + if (\is_null($this->pluralFormFunction)) { $lang = $this->getLanguageCode(); $this->pluralFormFunction = function($n) use ($lang) { return PluralizationRules::get($n, $lang); @@ -206,12 +206,12 @@ class L10N implements IL10N { } /** - * @param $translationFile + * @param string $translationFile * @return bool */ - protected function load($translationFile) { + protected function load(string $translationFile): bool { $json = json_decode(file_get_contents($translationFile), true); - if (!is_array($json)) { + if (!\is_array($json)) { $jsonError = json_last_error(); \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); return false; diff --git a/lib/public/IL10N.php b/lib/public/IL10N.php index 7af5008b81..158e0cb156 100644 --- a/lib/public/IL10N.php +++ b/lib/public/IL10N.php @@ -1,4 +1,5 @@ Date: Wed, 21 Feb 2018 19:46:29 +0100 Subject: [PATCH 2/4] Proper closure for function Signed-off-by: Roeland Jago Douma --- lib/private/L10N/L10N.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index 5e74b25a1c..f771a99e5d 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -192,9 +192,9 @@ class L10N implements IL10N { * Returnsed function accepts the argument $n * * Called by \OC_L10N_String - * @return string the plural form function + * @return \Closure the plural form function */ - public function getPluralFormFunction(): string { + public function getPluralFormFunction(): \Closure { if (\is_null($this->pluralFormFunction)) { $lang = $this->getLanguageCode(); $this->pluralFormFunction = function($n) use ($lang) { From 8b17f0d2244c4703b142838cfe94dd63503c8d3f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 21 Feb 2018 19:53:44 +0100 Subject: [PATCH 3/4] Fix other tests Signed-off-by: Roeland Jago Douma --- lib/private/App/DependencyAnalyzer.php | 10 +++++----- lib/private/L10N/L10N.php | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/private/App/DependencyAnalyzer.php b/lib/private/App/DependencyAnalyzer.php index 4193ee5083..e8da5a0b63 100644 --- a/lib/private/App/DependencyAnalyzer.php +++ b/lib/private/App/DependencyAnalyzer.php @@ -140,19 +140,19 @@ class DependencyAnalyzer { if (isset($dependencies['php']['@attributes']['min-version'])) { $minVersion = $dependencies['php']['@attributes']['min-version']; if ($this->compareSmaller($this->platform->getPhpVersion(), $minVersion)) { - $missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); + $missing[] = (string)$this->l->t('PHP %s or higher is required.', [$minVersion]); } } if (isset($dependencies['php']['@attributes']['max-version'])) { $maxVersion = $dependencies['php']['@attributes']['max-version']; if ($this->compareBigger($this->platform->getPhpVersion(), $maxVersion)) { - $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion); + $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', [$maxVersion]); } } if (isset($dependencies['php']['@attributes']['min-int-size'])) { $intSize = $dependencies['php']['@attributes']['min-int-size']; if ($intSize > $this->platform->getIntSize()*8) { - $missing[] = (string)$this->l->t('%sbit or higher PHP required.', $intSize); + $missing[] = (string)$this->l->t('%sbit or higher PHP required.', [$intSize]); } } return $missing; @@ -209,7 +209,7 @@ class DependencyAnalyzer { } $commandName = $this->getValue($command); if (!$this->platform->isCommandKnown($commandName)) { - $missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName); + $missing[] = (string)$this->l->t('The command line tool %s could not be found', [$commandName]); } } return $missing; @@ -236,7 +236,7 @@ class DependencyAnalyzer { $libName = $this->getValue($lib); $libVersion = $this->platform->getLibraryVersion($libName); if (is_null($libVersion)) { - $missing[] = (string)$this->l->t('The library %s is not available.', $libName); + $missing[] = (string)$this->l->t('The library %s is not available.', [$libName]); continue; } diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index f771a99e5d..f0e37ca1a5 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -159,6 +159,7 @@ class L10N implements IL10N { $data = strtotime($data); $value->setTimestamp($data); } else if ($data !== null) { + $data = (int)$data; $value->setTimestamp($data); } From cacfe3a360988a3fd7bef57706674ea4a007f047 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 21 Feb 2018 20:30:44 +0100 Subject: [PATCH 4/4] Fix more templates Signed-off-by: Roeland Jago Douma --- core/templates/installation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/templates/installation.php b/core/templates/installation.php index 0d274f0f88..616ca1f47d 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -31,7 +31,7 @@ script('core', [

t('Your data directory and files are probably accessible from the internet because the .htaccess file does not work.'));?>
t( 'For information how to properly configure your server, please see the documentation.', - link_to_docs('admin-install') + [link_to_docs('admin-install')] )); ?>