Completed
Push — master ( 6f7443...94a43d )
by Frédéric
02:25
created

Url   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A trimUrl() 0 4 2
A rawRouteUrl() 0 5 2
A switchLocale() 0 7 1
A addLocale() 0 5 2
1
<?php
2
3
namespace CaribouFute\LocaleRoute\Prefix;
4
5
use CaribouFute\LocaleRoute\Prefix\Base;
6
use Illuminate\Translation\Translator;
7
8
class Url extends Base
9
{
10
    protected $separator = '/';
11
    protected $translator;
12
13 57
    public function __construct(Translator $translator)
14
    {
15 57
        $this->translator = $translator;
16 57
    }
17
18 33
    public function trimUrl($url)
19
    {
20 33
        return trim($url, '/ ') ?: '/';
21
    }
22
23 20
    public function rawRouteUrl($locale, $route, array $options = [])
24
    {
25 20
        $unlocaleUrl = isset($options[$locale]) ? $options[$locale] : $this->translator->get('routes.' . $route, [], $locale);
26 20
        return $this->trimUrl($unlocaleUrl);
27
    }
28
29 31
    public function switchLocale($locale, $url, array $options = [])
30
    {
31 31
        $unlocalized = $this->removeLocale($url);
32 31
        $localized = $this->addLocale($locale, $unlocalized, $options);
33
34 31
        return $this->trimUrl($localized);
35
    }
36
37 33
    public function addLocale($locale, $unlocalized, $options = [])
38
    {
39 33
        $localized = $this->getAddLocaleToUrl($options) ? parent::addLocale($locale, $unlocalized) : $unlocalized;
40 33
        return $this->trimUrl($localized);
41
    }
42
}
43