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 ArgumentsAwareConfigTrait |
||
| 15 | { |
||
| 16 | protected $arguments = []; |
||
| 17 | protected $_isArgumentsBuilt; |
||
| 18 | |||
| 19 | 55 | public function buildArguments() |
|
| 28 | |||
| 29 | 24 | public function addArguments($argsList) |
|
| 42 | |||
| 43 | 27 | public function addArgument($argument, $argumentInfo = null) |
|
| 52 | |||
| 53 | 22 | View Code Duplication | protected function buildConfig($name, $info = null) |
| 67 | |||
| 68 | /** |
||
| 69 | * @param $name |
||
| 70 | * |
||
| 71 | * @return InputField |
||
| 72 | */ |
||
| 73 | 9 | public function getArgument($name) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * @param $name |
||
| 80 | * |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | 11 | public function hasArgument($name) |
|
| 87 | |||
| 88 | 4 | public function hasArguments() |
|
| 92 | |||
| 93 | /** |
||
| 94 | * @return InputField[] |
||
| 95 | */ |
||
| 96 | 24 | public function getArguments() |
|
| 100 | |||
| 101 | 2 | public function removeArgument($name) |
|
| 109 | |||
| 110 | } |
||
| 111 |
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: