diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-02-21 14:32:04 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-02-21 14:32:04 +0100 |
commit | 541056f6c284953a0435d180b8620b55e344a5f4 (patch) | |
tree | 1102fa1fe3b852bd308f9def32cd4db6eea6e4d2 /lib/private/L10N/L10N.php | |
parent | 4b50fe7560444f4c42ba04ea4a034119af907db1 (diff) | |
download | nextcloud-server-541056f6c284953a0435d180b8620b55e344a5f4.tar.gz nextcloud-server-541056f6c284953a0435d180b8620b55e344a5f4.zip |
Make OCP\IL10N strict
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/L10N/L10N.php')
-rw-r--r-- | lib/private/L10N/L10N.php | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index e9e720a3766..5e74b25a1c2 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -60,7 +61,6 @@ class L10N implements IL10N { $this->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; |