From 24e23876ca51dfd810d88a17b43ea488aa47cb2a Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Tue, 22 Sep 2015 12:30:18 +0100 Subject: [PATCH] Fixing RouteTranslator --- src/Utilities/RouteTranslator.php | 33 ++++++++++--------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/Utilities/RouteTranslator.php b/src/Utilities/RouteTranslator.php index 094fde1..0db54b3 100644 --- a/src/Utilities/RouteTranslator.php +++ b/src/Utilities/RouteTranslator.php @@ -165,7 +165,7 @@ public function getTranslatedRoute( public function getRouteNameFromPath($uri, $locale) { $attributes = Url::extractAttributes($uri); - $uri = str_replace([url(), "/$locale/"], ['', ''], $uri); + $uri = str_replace([url(), "/$locale/"], '', $uri); $uri = trim($uri, '/'); foreach ($this->translatedRoutes as $route) { @@ -245,9 +245,16 @@ private function translate($key, $locale = null) } $translation = $this->translator->trans($key, [], '', $locale); - $this->checkTranslation($key, $locale, $translation); - return $translation; + // @codeCoverageIgnoreStart + if ( ! is_string($translation)) { + throw new InvalidTranslationException( + "The translation key [$key] for locale [$locale] should return a string value." + ); + } + // @codeCoverageIgnoreEnd + + return (string) $translation; } /* ------------------------------------------------------------------------------------------------ @@ -276,24 +283,4 @@ public function hasTranslation($key, $locale = null) { return $this->translator->has($key, $locale); } - - /** - * Check the translation. - * - * @param string $key - * @param string $locale - * @param mixed $translation - * - * @throws InvalidTranslationException - */ - private function checkTranslation($key, $locale, $translation) - { - // @codeCoverageIgnoreStart - if ( ! is_string($translation)) { - throw new InvalidTranslationException( - "The translation key [$key] for locale [$locale] should return a string value." - ); - } - // @codeCoverageIgnoreEnd - } }