Completed
Branch master (b5c40b)
by Frédéric
05:15 queued 02:42
created

UrlLocalizer::addLocale()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
namespace CaribouFute\LocaleRoute\Routing;
4
5
use Config;
6
use Illuminate\Translation\Translator;
7
8
class UrlLocalizer
9
{
10
    protected $translator;
11
12 6
    public function __construct(Translator $translator)
13
    {
14 6
        $this->translator = $translator;
15 6
    }
16
17 5
    public function addLocaleConfig()
18
    {
19 5
        return Config::get('localeroute.add_locale_to_url');
20
    }
21
22
    public function getRouteUrl($locale, $route, array $urls = [])
23
    {
24
        $unlocaleUrl = isset($urls[$locale]) ? $urls[$locale] : $this->translator->get('routes.' . $route, [], $locale);
25
        $url = $this->addLocale($locale, $unlocaleUrl);
26
        return $url;
27
    }
28
29 2
    public function addLocale($locale, $url)
30
    {
31 2
        return $this->addLocaleConfig() ? $locale . '/' . $url : $url;
32
    }
33
34 2
    public function removeLocale($locale, $url)
35
    {
36 2
        return $this->addLocaleConfig() ? str_replace($locale . '/', '', $url) : $url;
37
    }
38
}
39