Skip to content

Commit

Permalink
Refactoring and Updating doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Aug 28, 2016
1 parent f4fdfb8 commit 13e52a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 49 deletions.
63 changes: 17 additions & 46 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -84,7 +80,7 @@ public function __construct(
/**
* Get Request instance.
*
* @return Request
* @return \Illuminate\Http\Request
*/
private function request()
{
Expand All @@ -105,8 +101,6 @@ public function getDefaultLocale()
* Return an array of all supported Locales.
*
* @return \Arcanedev\Localization\Entities\LocaleCollection
*
* @throws UndefinedSupportedLocalesException
*/
public function getSupportedLocales()
{
Expand All @@ -131,8 +125,6 @@ public function setSupportedLocales(array $supportedLocales)
* Get supported locales keys.
*
* @return array
*
* @throws UndefinedSupportedLocalesException
*/
public function getSupportedLocalesKeys()
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [])
{
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -417,9 +398,6 @@ public function localesNavbar()
* @param string $locale
*
* @return string|false
*
* @throws UndefinedSupportedLocalesException
* @throws UnsupportedLocaleException
*/
private function findTranslatedRouteByUrl($url, $attributes, $locale)
{
Expand All @@ -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 = [])
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -500,23 +475,19 @@ 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));
}

/**
* Check if the locale is supported or fail if not.
*
* @param string $locale
*
* @throws UnsupportedLocaleException
* @throws \Arcanedev\Localization\Exceptions\UnsupportedLocaleException
*/
private function isLocaleSupportedOrFail($locale)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Utilities/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 13e52a5

Please sign in to comment.