Passed
Branch master (ae28f9)
by Alexey
03:28
created

RouteGroup   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 62.86%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 7 1
B getRoutes() 0 16 6
A setHost() 0 6 1
A setPrefix() 0 6 1
A setScheme() 0 6 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Venta\Contracts\Routing\RouteGroup as RouteGroupContract;
6
7
/**
8
 * Class RouteGroup
9
 *
10
 * @package Venta\Routing
11
 */
12
class RouteGroup extends RouteCollection implements RouteGroupContract
13
{
14
15
    /**
16
     * @var string
17
     */
18
    private $host = '';
19
20
    /**
21
     * @var string
22
     */
23
    private $prefix = '/';
24
25
    /**
26
     * @var string
27
     */
28
    private $scheme = '';
29
30
    /**
31
     * @param callable $callback
32
     * @return RouteGroupContract
33
     */
34 1
    public static function collect(callable $callback): RouteGroupContract
35
    {
36 1
        $group = new static();
37 1
        $callback($group);
38
39 1
        return $group;
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 4
    public function getRoutes(): array
46
    {
47 4
        $routes = [];
48
        /** @var Route $route */
49 4
        foreach (parent::getRoutes() as $route) {
50 4
            if (!$route->getHost() && $this->host) {
51 1
                $route = $route->withHost($this->host);
52
            }
53 4
            if (!$route->getScheme() && $this->scheme) {
54 1
                $route = $route->withScheme($this->scheme);
55
            }
56 4
            $routes[] = $route->withPathPrefix($this->prefix);
57
        }
58
59 4
        return $routes;
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 1
    public function setHost(string $host): RouteGroupContract
66
    {
67 1
        $this->host = $host;
68
69 1
        return $this;
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75 1
    public function setPrefix(string $prefix): RouteGroupContract
76
    {
77 1
        $this->prefix = '/' . trim($prefix, '/');
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * @inheritDoc
84
     */
85 1
    public function setScheme(string $scheme): RouteGroupContract
86
    {
87 1
        $this->scheme = $scheme;
88
89 1
        return $this;
90
    }
91
92
93
}