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 |
||
14 | trait GithubCommitConvertTrait |
||
15 | { |
||
16 | /** |
||
17 | * @param $data |
||
18 | * |
||
19 | * @return GithubCommitSource |
||
20 | */ |
||
21 | protected function convertCommit($data) |
||
38 | |||
39 | /** |
||
40 | * @param $data |
||
41 | * |
||
42 | * @return GithubUserSource |
||
43 | */ |
||
44 | View Code Duplication | protected function getAuthor($data) |
|
55 | |||
56 | /** |
||
57 | * @param $data |
||
58 | * |
||
59 | * @return GithubUserSource |
||
60 | */ |
||
61 | View Code Duplication | protected function getCommitter($data) |
|
72 | } |
||
73 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: