diff --git a/phpstan.neon b/phpstan.neon index 0eb9a59..d4dc3dd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -29,9 +29,5 @@ parameters: message: '#of function str_replace expects#' paths: - src/GlossTranslator.php - - - message: '#should return Lean\\Gloss\\GlossTranslator\|string\|void\|null but returns array\|string#' - paths: - - src/helpers.php checkMissingIterableValueType: false diff --git a/src/Gloss.php b/src/Gloss.php index 3c38a1d..7ec33f1 100644 --- a/src/Gloss.php +++ b/src/Gloss.php @@ -15,6 +15,8 @@ use Illuminate\Support\Facades\Facade; * @method static ?string get($key, $replace = [], $locale = null) Get a translation string. * @method static ?string choice($key, $replace = [], $locale = null) Get a translation according to an integer value. * @method static void extend(string $shortKey, callable(string, callable): string $value) Extend a translation string. + * + * @see \Lean\Gloss\GlossTranslator */ class Gloss extends Facade { diff --git a/src/GlossTranslator.php b/src/GlossTranslator.php index f686088..06dc912 100644 --- a/src/GlossTranslator.php +++ b/src/GlossTranslator.php @@ -89,6 +89,15 @@ class GlossTranslator extends Translator $this->extensions[$shortKey][] = $value; } + /** + * Get a translation string. + * + * @param string $key + * @param array $replace + * @param string|null $locale + * @param bool $fallback + * @return string + */ public function get($key, array $replace = [], $locale = null, $fallback = true) { if (array_key_exists($key, $this->extensions)) { @@ -118,7 +127,16 @@ class GlossTranslator extends Translator return $this->getWithoutExtensions($key, $replace, $locale, $fallback); } - protected function getWithoutExtensions($key, $replace = [], $locale = null, $fallback = true) + /** + * Get a translation string and skip extensions. + * + * @param string $key + * @param array $replace + * @param string|null $locale + * @param bool $fallback + * @return string + */ + protected function getWithoutExtensions(string $key, $replace = [], $locale = null, $fallback = true) { return $this->getKeyOverride($key, $replace) ?? $this->getValueOverride($key, $replace)