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

Url::trimUrl()   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 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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