From 13e52a51f07c45c801c1e1904e912a82b466af83 Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Sun, 28 Aug 2016 19:32:07 +0100 Subject: [PATCH] Refactoring and Updating doc comments --- src/Localization.php | 63 ++++++++++++------------------------------- src/Utilities/Url.php | 4 +-- 2 files changed, 18 insertions(+), 49 deletions(-) diff --git a/src/Localization.php b/src/Localization.php index c1cfc12..5b22d78 100644 --- a/src/Localization.php +++ b/src/Localization.php @@ -3,7 +3,6 @@ use Arcanedev\Localization\Contracts\LocalesManagerInterface; use Arcanedev\Localization\Contracts\LocalizationInterface; use Arcanedev\Localization\Contracts\RouteTranslatorInterface; -use Arcanedev\Localization\Exceptions\UndefinedSupportedLocalesException; use Arcanedev\Localization\Exceptions\UnsupportedLocaleException; use Arcanedev\Localization\Utilities\Url; use Illuminate\Foundation\Application; @@ -22,30 +21,30 @@ class Localization implements LocalizationInterface | ------------------------------------------------------------------------------------------------ */ /** - * Laravel application instance. + * Base url. * - * @var Application + * @var string */ - private $app; + protected $baseUrl; /** - * Base url. + * Laravel application instance. * - * @var string + * @var \Illuminate\Foundation\Application */ - protected $baseUrl; + private $app; /** * The RouteTranslator instance. * - * @var RouteTranslatorInterface + * @var \Arcanedev\Localization\Contracts\RouteTranslatorInterface */ protected $routeTranslator; /** * The LocalesManager instance. * - * @var LocalesManagerInterface + * @var \Arcanedev\Localization\Contracts\LocalesManagerInterface */ private $localesManager; @@ -56,12 +55,9 @@ class Localization implements LocalizationInterface /** * Creates new instance. * - * @param Application $app - * @param RouteTranslatorInterface $routeTranslator - * @param LocalesManagerInterface $localesManager - * - * @throws UndefinedSupportedLocalesException - * @throws UnsupportedLocaleException + * @param \Illuminate\Foundation\Application $app + * @param \Arcanedev\Localization\Contracts\RouteTranslatorInterface $routeTranslator + * @param \Arcanedev\Localization\Contracts\LocalesManagerInterface $localesManager */ public function __construct( Application $app, @@ -84,7 +80,7 @@ public function __construct( /** * Get Request instance. * - * @return Request + * @return \Illuminate\Http\Request */ private function request() { @@ -105,8 +101,6 @@ public function getDefaultLocale() * Return an array of all supported Locales. * * @return \Arcanedev\Localization\Entities\LocaleCollection - * - * @throws UndefinedSupportedLocalesException */ public function getSupportedLocales() { @@ -131,8 +125,6 @@ public function setSupportedLocales(array $supportedLocales) * Get supported locales keys. * * @return array - * - * @throws UndefinedSupportedLocalesException */ public function getSupportedLocalesKeys() { @@ -240,9 +232,7 @@ public function setLocale($locale = null) */ public function setBaseUrl($url) { - if (substr($url, -1) !== '/') { - $url .= '/'; - } + if (substr($url, -1) !== '/') $url .= '/'; $this->baseUrl = $url; @@ -271,8 +261,6 @@ public function transRoute($routeName) * @param string|null $url * @param string|null $locale * - * @throws UnsupportedLocaleException - * * @return string */ public function localizeURL($url = null, $locale = null) @@ -302,9 +290,6 @@ public function getNonLocalizedURL($url = null) * @param array $attributes * * @return string|false - * - * @throws UndefinedSupportedLocalesException - * @throws UnsupportedLocaleException */ public function getLocalizedURL($locale = null, $url = null, $attributes = []) { @@ -386,11 +371,7 @@ public function createUrlFromUri($uri) { $uri = ltrim($uri, '/'); - if (empty($this->baseUrl)) { - return app('url')->to($uri); - } - - return $this->baseUrl . $uri; + return empty($this->baseUrl) ? app('url')->to($uri) : $this->baseUrl.$uri; } /** @@ -417,9 +398,6 @@ public function localesNavbar() * @param string $locale * * @return string|false - * - * @throws UndefinedSupportedLocalesException - * @throws UnsupportedLocaleException */ private function findTranslatedRouteByUrl($url, $attributes, $locale) { @@ -445,9 +423,6 @@ private function findTranslatedRouteByUrl($url, $attributes, $locale) * @param array $attributes * * @return string|false - * - * @throws UndefinedSupportedLocalesException - * @throws UnsupportedLocaleException */ public function getUrlFromRouteName($locale, $transKey, $attributes = []) { @@ -470,7 +445,7 @@ public function getUrlFromRouteName($locale, $transKey, $attributes = []) /** * Set route name from request. * - * @param Request $request + * @param \Illuminate\Http\Request $request */ public function setRouteNameFromRequest(Request $request) { @@ -500,15 +475,11 @@ public function isDefaultLocaleHiddenInUrl() * * @param string|bool $locale * - * @throws UndefinedSupportedLocalesException - * * @return bool */ public function isLocaleSupported($locale) { - return ( - $locale !== false && ! $this->localesManager->isSupportedLocale($locale) - ) ? false : true; + return ! ($locale !== false && ! $this->localesManager->isSupportedLocale($locale)); } /** @@ -516,7 +487,7 @@ public function isLocaleSupported($locale) * * @param string $locale * - * @throws UnsupportedLocaleException + * @throws \Arcanedev\Localization\Exceptions\UnsupportedLocaleException */ private function isLocaleSupportedOrFail($locale) { diff --git a/src/Utilities/Url.php b/src/Utilities/Url.php index 15069fd..93933f3 100644 --- a/src/Utilities/Url.php +++ b/src/Utilities/Url.php @@ -150,9 +150,7 @@ private static function hasAttributesFromUriPath($url, $path, &$attributes) } } - if (isset($url[$i + 1])) { - $match = false; - } + if (isset($url[$i + 1])) $match = false; return $match; }