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

HelperThrows   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getType() 0 16 3
1
<?php
2
3
namespace Bavix\Router;
4
5
use Bavix\Slice\Slice;
6
use Bavix\Exceptions;
7
8
trait HelperThrows
9
{
10
11
    /**
12
     * @var array
13
     */
14
    protected $types = [];
15
16
    /**
17
     * @param Slice  $slice
18
     * @param string $key
19
     *
20
     * @return mixed
21
     * @throws Exceptions\NotFound\Data
22
     */
23
    public function getType(Slice $slice, $key = null)
24
    {
25
        $type = $slice->atData('type');
26
27
        if ($type === null)
28
        {
29
            throw new Exceptions\NotFound\Data('Parameter `type` not found in a route of `' . $key . '`');
30
        }
31
32
        if (!isset($this->types[$type]))
33
        {
34
            throw new Exceptions\NotFound\Data('The `' . $type . '` type isn\'t found in a route of `' . $key . '`');
35
        }
36
37
        return $type;
38
    }
39
40
}