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 |
||
21 | class Runner implements RunnerInterface |
||
22 | { |
||
23 | private $tasks; |
||
24 | |||
25 | private $groups = []; |
||
26 | |||
27 | private $order; |
||
28 | |||
29 | public function __construct() |
||
34 | |||
35 | View Code Duplication | public function group($group, callable $tasks = null) |
|
46 | |||
47 | /** |
||
48 | * Registres a task |
||
49 | * |
||
50 | * @param string|TaskInterface $task |
||
51 | * @param callable $callback |
||
52 | */ |
||
53 | View Code Duplication | public function task($task, callable $callback = null) |
|
64 | |||
65 | /** |
||
66 | * Allows create a task setting a property |
||
67 | * |
||
68 | * @param string|TaskInterface $task |
||
69 | * @param callable $callback |
||
70 | */ |
||
71 | public function __set(string $task, callable $callback) |
||
75 | |||
76 | /** |
||
77 | * Organize tasks and groups order |
||
78 | * If this method is executed and a task and a group is not in this list, it won't be executed |
||
79 | * |
||
80 | * @param string-variadic $tasks |
||
81 | */ |
||
82 | public function order(string ...$names) |
||
96 | |||
97 | /** |
||
98 | * Returns all registred tasks |
||
99 | * |
||
100 | * @return TasksCollection |
||
101 | */ |
||
102 | public function getTasks() : TasksCollection |
||
106 | |||
107 | public function getGroups() : GroupsCollection |
||
111 | |||
112 | public function getOrder() : array |
||
116 | |||
117 | /** |
||
118 | * Runs all tasks |
||
119 | */ |
||
120 | public function run() |
||
137 | |||
138 | /** |
||
139 | * Runs one single task |
||
140 | * |
||
141 | * @param string|TaskInterface $task |
||
142 | */ |
||
143 | public function runTask($task) |
||
159 | |||
160 | /** |
||
161 | * Runs a group of tasks |
||
162 | * |
||
163 | * @param string|GroupInterface $group |
||
164 | */ |
||
165 | public function runGroup($group) |
||
174 | |||
175 | View Code Duplication | private function getFromOrderData($name) |
|
183 | } |
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..