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 |
||
26 | class Commit |
||
27 | { |
||
28 | /** |
||
29 | * @var string 7 characters commit hash |
||
30 | */ |
||
31 | protected $_hash; |
||
32 | |||
33 | /** |
||
34 | * @var string string representation of commit |
||
35 | */ |
||
36 | protected $_label; |
||
37 | protected $_comments = []; |
||
38 | |||
39 | protected $_date; |
||
40 | protected $_author; |
||
41 | protected $_subject; |
||
42 | |||
43 | 3 | public function __construct($hash, $label = null, array $comments = []) |
|
49 | |||
50 | public function set(Commit $commit) |
||
56 | |||
57 | 3 | public function setHash($hash) |
|
61 | |||
62 | 3 | public function getHash() |
|
66 | |||
67 | 3 | public function setLabel($label) |
|
79 | |||
80 | 3 | public function getLabel() |
|
87 | |||
88 | 2 | public function addComment($comment) |
|
92 | |||
93 | 3 | public function addComments(array $comments) |
|
99 | |||
100 | 3 | public function setComments($comments) |
|
105 | |||
106 | 3 | public function getComments() |
|
110 | |||
111 | 3 | View Code Duplication | public function setDate($value) |
120 | |||
121 | 3 | public function getDate() |
|
125 | |||
126 | 3 | public function setSubject($value) |
|
132 | |||
133 | 3 | public function getSubject() |
|
137 | |||
138 | 3 | public function setAuthor($value) |
|
144 | |||
145 | 3 | public function getAuthor() |
|
149 | } |
||
150 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.