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 namespace Magestead\Helper; |
||
| 7 | class Config |
||
| 8 | { |
||
| 9 | protected $_projectPath; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Config constructor. |
||
| 13 | * @param OutputInterface $output |
||
| 14 | */ |
||
| 15 | public function __construct(OutputInterface $output) |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param $name |
||
| 23 | * @return mixed |
||
| 24 | */ |
||
| 25 | function __get($name) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param OutputInterface $output |
||
| 32 | * @return bool|mixed |
||
| 33 | */ |
||
| 34 | View Code Duplication | protected function getConfigFile(OutputInterface $output) |
|
| 45 | } |
||
| 46 |
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: