Completed
Push — refactor ( 0ce6e5 )
by Marco
01:39
created

Route::fromArray()   D

Complexity

Conditions 10
Paths 5

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 16
nc 5
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace MJanssen\Route;
4
5
use InvalidArgumentException;
6
use MJanssen\Assert\Method;
7
8
class Route
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
15
    /**
16
     * @var array
17
     */
18
    private $methods = [];
19
20
    /**
21
     * @var string
22
     */
23
    private $pattern;
24
25
    /**
26
     * @var string
27
     */
28
    private $controller;
29
30
    /**
31
     * @var array
32
     */
33
    private $asserts = [];
34
35
    /**
36
     * @var array
37
     */
38
    private $values = [];
39
40
    /**
41
     * @param array $methods
42
     * @param string $pattern
43
     * @param string $controller
44
     * @param array $asserts
45
     * @param array $values
46
     * @param string $name
47
     */
48
    public function __construct(
49
        Methods $methods,
50
        Pattern $pattern,
51
        Controller $controller,
52
        Asserts $asserts = null,
53
        Values $values = null,
54
        Name $name
55
    ) {
56
        $this->methods = $methods;
0 ignored issues
show
Documentation Bug introduced by
It seems like $methods of type object<MJanssen\Route\Methods> is incompatible with the declared type array of property $methods.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->pattern = $pattern;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pattern of type object<MJanssen\Route\Pattern> is incompatible with the declared type string of property $pattern.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
        $this->controller = $controller;
0 ignored issues
show
Documentation Bug introduced by
It seems like $controller of type object<MJanssen\Route\Controller> is incompatible with the declared type string of property $controller.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
        $this->asserts = $asserts;
0 ignored issues
show
Documentation Bug introduced by
It seems like $asserts of type null or object<MJanssen\Route\Asserts> is incompatible with the declared type array of property $asserts.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
        $this->values = $values;
0 ignored issues
show
Documentation Bug introduced by
It seems like $values of type null or object<MJanssen\Route\Values> is incompatible with the declared type array of property $values.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
        $this->name = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name of type object<MJanssen\Route\Name> is incompatible with the declared type string of property $name.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getName()
68
    {
69
        return $this->name;
70
    }
71
72
    /**
73
     * @return Methods
74
     */
75
    public function getMethods()
76
    {
77
        return $this->methods;
78
    }
79
80
    /**
81
     * @return Pattern
82
     */
83
    public function getPattern()
84
    {
85
        return $this->pattern;
86
    }
87
88
    /**
89
     * @return Controller
90
     */
91
    public function getController()
92
    {
93
        return $this->controller;
94
    }
95
96
    /**
97
     * @return Asserts
98
     */
99
    public function getAsserts()
100
    {
101
        return $this->asserts;
102
    }
103
104
    /**
105
     * @return Values
106
     */
107
    public function getValues()
108
    {
109
        return $this->values;
110
    }
111
}