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 |
||
| 8 | class ArrayToViewReferenceTransformer implements DataTransformerInterface |
||
| 9 | { |
||
| 10 | public $className = 'Victoire\Bundle\ViewReferenceBundle\ViewReference\ViewReference'; |
||
| 11 | |||
| 12 | public function __construct() |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Array to ViewReference |
||
| 20 | * {@inheritdoc} |
||
| 21 | * |
||
| 22 | * @param array $array |
||
| 23 | * |
||
| 24 | * @return ViewReference |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function transform($array) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * View Reference to array |
||
| 42 | * {@inheritdoc} |
||
| 43 | * |
||
| 44 | * @param ViewReference $viewReference |
||
| 45 | * |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | public function reverseTransform($viewReference) |
||
| 58 | } |
||
| 59 |
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: