Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
5 | class RouteContainer |
||
6 | { |
||
7 | /** |
||
8 | * Current route (match) instance |
||
9 | * @var \Psecio\Invoke\MatchInstance |
||
10 | */ |
||
11 | private $route; |
||
12 | |||
13 | /** |
||
14 | * Current configuration |
||
15 | * @var array |
||
16 | */ |
||
17 | private $config; |
||
18 | |||
19 | /** |
||
20 | * Parameters found in route processing |
||
21 | * @var array |
||
22 | */ |
||
23 | private $params = []; |
||
24 | |||
25 | /** |
||
26 | * Initialize the container with the provided route and |
||
27 | * configuration information |
||
28 | * |
||
29 | * @param string $route Route to provide to the match |
||
30 | * @param array $config Route configuration |
||
31 | */ |
||
32 | public function __construct($route, array $config) |
||
38 | |||
39 | /** |
||
40 | * Get the current configuration |
||
41 | * |
||
42 | * @return array Configuration set |
||
43 | */ |
||
44 | View Code Duplication | public function getConfig($name = null) |
|
52 | |||
53 | /** |
||
54 | * Get the current route instance |
||
55 | * |
||
56 | * @return \Psecio\Invoke\MatchInstance |
||
57 | */ |
||
58 | public function getRoute() |
||
62 | |||
63 | /** |
||
64 | * Set the parameters for the current route match |
||
65 | * |
||
66 | * @param array $params Parameter set |
||
67 | */ |
||
68 | public function setParams(array $params = array()) |
||
72 | |||
73 | /** |
||
74 | * Get the current parameter set |
||
75 | * |
||
76 | * @return array Parameter set |
||
77 | */ |
||
78 | public function getParams() |
||
82 | } |
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..