Completed
Branch feature/router-decorator (f7629b)
by Frédéric
02:12
created

Route   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A localeRoute() 0 11 3
A getCurrentRouteName() 0 7 2
A otherLocale() 0 7 2
A getCurrentRouteParameters() 0 7 2
A otherRoute() 0 4 1
1
<?php
2
3
namespace CaribouFute\LocaleRoute\Prefix;
4
5
use App;
6
use CaribouFute\LocaleRoute\Prefix\Base;
7
use Illuminate\Routing\Router as IlluminateRouter;
8
use Illuminate\Routing\UrlGenerator;
9
10
class Route extends Base
11
{
12
    protected $separator = '.';
13
    protected $url;
14
    protected $router;
15
16 46
    public function __construct(UrlGenerator $url, IlluminateRouter $router)
17
    {
18 46
        $this->url = $url;
19 46
        $this->router = $router;
20 46
    }
21
22 8
    public function localeRoute($locale = null, $name = null, $parameters = [], $absolute = true)
23
    {
24 8
        $locale = $locale ?: App::getLocale();
25 8
        $name = $name ?: $this->getCurrentRouteName();
26
27 8
        $localeRoute = $this->switchLocale($locale, $name);
28 8
        $localeUrl = $this->url->route($localeRoute, $parameters, $absolute);
29 8
        $localeUrl = rtrim($localeUrl, '?');
30
31 8
        return $localeUrl;
32
    }
33
34 3
    public function getCurrentRouteName()
35
    {
36 3
        $currentRoute = $this->router->current();
37 3
        $currentRouteName = $currentRoute ? $currentRoute->getName() : '';
38
39 3
        return $currentRouteName;
40
    }
41
42 1
    public function otherLocale($locale = null, $parameters = null, $absolute = true)
43
    {
44 1
        $name = $this->getCurrentRouteName();
45 1
        $parameters = $parameters ?: $this->getCurrentRouteParameters();
46
47 1
        return $this->localeRoute($locale, $name, $parameters, $absolute);
48
    }
49
50 1
    public function getCurrentRouteParameters()
51
    {
52 1
        $currentRoute = $this->router->current();
53 1
        $currentRouteParameters = $currentRoute ? $currentRoute->parameters() : [];
54
55 1
        return $currentRouteParameters;
56
    }
57
58 2
    public function otherRoute($name, $parameters = null, $absolute = true)
59
    {
60 2
        return $this->localeRoute(null, $name, $parameters, $absolute);
61
    }
62
}
63