Completed
Push — master ( 8a3554...20628b )
by Ryan
07:18
created

EntryRouter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B make() 0 12 5
1
<?php namespace Anomaly\Streams\Platform\Entry;
2
3
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
4
use Anomaly\Streams\Platform\Routing\UrlGenerator;
5
use Anomaly\Streams\Platform\Support\Locator;
6
use Illuminate\Foundation\Bus\DispatchesJobs;
7
8
/**
9
 * Class EntryRouter
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 * @package       Anomaly\Streams\Platform\Entry
15
 */
16
class EntryRouter
17
{
18
19
    use DispatchesJobs;
20
21
    /**
22
     * The URL generator;
23
     *
24
     * @var UrlGenerator
25
     */
26
    protected $url;
27
28
    /**
29
     * The entry model.
30
     *
31
     * @var EntryInterface
32
     */
33
    protected $model;
34
35
    /**
36
     * The locator utility.
37
     *
38
     * @var Locator
39
     */
40
    protected $locator;
41
42
    /**
43
     * Create a new EntryRouter instance.
44
     *
45
     * @param UrlGenerator   $url
46
     * @param EntryInterface $model
47
     * @param Locator        $locator
48
     */
49
    public function __construct(UrlGenerator $url, EntryInterface $model, Locator $locator)
50
    {
51
        $this->url     = $url;
52
        $this->model   = $model;
53
        $this->locator = $locator;
54
    }
55
56
    /**
57
     * Make a route.
58
     *
59
     * @param       $route
60
     * @param array $parameters
61
     * @return mixed|null|string
62
     */
63
    public function make($route, array $parameters = [])
64
    {
65
        if (!str_contains($route, '.') && $namespace = $this->model->getStreamNamespace()) {
66
            $route = "{$namespace}.{$route}";
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $route. This often makes code more readable.
Loading history...
67
        }
68
69
        if (!str_contains($route, '::') && $namespace = $this->locator->locate($this->model)) {
70
            $route = "{$namespace}::{$route}";
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $route. This often makes code more readable.
Loading history...
71
        }
72
73
        return $this->url->make($route, $this->model, $parameters);
74
    }
75
}
76