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 |
||
| 15 | trait GithubCommitConvertTrait |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @param array $data |
||
| 19 | * |
||
| 20 | * @return GithubCommitSource |
||
| 21 | */ |
||
| 22 | protected function convertCommit(array $data) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param array $data |
||
| 37 | * |
||
| 38 | * @return GithubUserSource |
||
| 39 | */ |
||
| 40 | View Code Duplication | protected function getAuthor(array $data) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * @param array $data |
||
| 54 | * |
||
| 55 | * @return GithubUserSource |
||
| 56 | */ |
||
| 57 | View Code Duplication | protected function getCommitter(array $data) |
|
| 68 | } |
||
| 69 |
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: