Passed
Push — master ( 39666f...8b4565 )
by Бабичев
09:02
created

Pattern   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A merge() 0 9 2
A build() 0 18 2
1
<?php
2
3
namespace Bavix\Router\Type;
4
5
use Bavix\Router\Route;
6
use Bavix\Router\Type;
7
8
class Pattern extends Type
9
{
10
11
    /**
12
     * @var bool
13
     */
14
    protected $pathRequired = true;
15
16
    /**
17
     * @param string $key
18
     * @param array  $storage
19
     */
20
    protected function merge($key, array $storage)
21
    {
22
        if (!isset($this->slice[$key]))
23
        {
24
            $this->slice[$key] = [];
25
        }
26
27
        $this->slice[$key] += $storage;
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function build()
34
    {
35
        $this->slice['http.protocol'] = $this->protocol;
36
        $this->slice['http.host']     = $this->host;
37
        $this->slice['path']          = $this->path;
38
        $this->slice['regex']         = $this->regex;
39
40
        if (empty($this->slice['methods']))
41
        {
42
            $this->slice['methods'] = $this->methods;
43
        }
44
45
        $this->merge('defaults', $this->defaults);
46
47
        return [
48
            $this->key => new Route($this->slice)
49
        ];
50
    }
51
52
}
53