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 |
||
8 | class Handler |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $scripts; |
||
15 | |||
16 | /** |
||
17 | * @var Executor |
||
18 | */ |
||
19 | private $executor; |
||
20 | |||
21 | |||
22 | 4 | public function __construct(ContainerInterface $ci, Executor $executor) |
|
27 | |||
28 | |||
29 | 1 | public function handleDeploy(array $event, array $build) |
|
46 | |||
47 | |||
48 | 1 | View Code Duplication | public function handlePush(array $event) |
61 | |||
62 | |||
63 | 1 | View Code Duplication | public function handleTag(array $event) |
76 | |||
77 | |||
78 | 1 | private function extractBranchName($ref) |
|
82 | |||
83 | |||
84 | 1 | private function extractTagName($ref) |
|
88 | |||
89 | |||
90 | /** |
||
91 | * @param string|array $scriptPath |
||
92 | * @param array $env |
||
93 | */ |
||
94 | 3 | private function executeCommand($scriptPath, array $env) |
|
98 | |||
99 | } |
||
100 |
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..