Completed
Push — master ( b9d832...421ea6 )
by Phil
06:19 queued 04:14
created

RouteGroup   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 6
c 6
b 1
f 0
lcom 1
cbo 4
dl 0
loc 65
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A map() 0 17 4
A __construct() 0 6 1
1
<?php
2
3
namespace League\Route;
4
5
class RouteGroup implements RouteCollectionInterface
6
{
7
    use RouteCollectionMapTrait;
8
    use RouteConditionTrait;
9
10
    /**
11
     * @var callable
12
     */
13
    protected $callback;
14
15
    /**
16
     * @var \League\Route\RouteCollectionInterface
17
     */
18
    protected $collection;
19
20
    /**
21
     * @var string
22
     */
23
    protected $prefix;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param string                        $prefix
29
     * @param callable                      $callback
30
     * @param \League\Route\RouteCollection $collection
31
     */
32 3
    public function __construct($prefix, callable $callback, RouteCollectionInterface $collection)
33
    {
34 3
        $this->callback   = $callback;
35 3
        $this->collection = $collection;
36 3
        $this->prefix     = sprintf('/%s', ltrim($prefix, '/'));
37 3
    }
38
39
    /**
40
     * Process the group and ensure routes are added to the collection.
41
     *
42
     * @return void
43
     */
44 3
    public function __invoke()
45
    {
46 3
        call_user_func_array($this->callback, [$this]);
47 3
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 3
    public function map($method, $path, $handler)
53
    {
54 3
        $path  = ($path === '/') ? $this->prefix : $this->prefix . sprintf('/%s', ltrim($path, '/'));
55 3
        $route = $this->collection->map($method, $path, $handler);
56
57 3
        $route->setParentGroup($this);
58
59 3
        if ($host = $this->getHost()) {
60 3
            $route->setHost($host);
61 3
        }
62
63 3
        if ($scheme = $this->getScheme()) {
64 3
            $route->setScheme($scheme);
65 3
        }
66
67 3
        return $route;
68
    }
69
}
70