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 |
||
| 18 | class DBALRepository implements PermissionRepositoryInterface, PermissionQueryInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Connection |
||
| 22 | */ |
||
| 23 | protected $connection; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param String $tableName |
||
| 27 | * @param Connection $connection |
||
| 28 | */ |
||
| 29 | public function __construct(String $tableName, Connection $connection) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function getEditablePlaces(String $uitId) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @inheritdoc |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function markPlaceEditableByUser(String $placeId, String $uitId) |
|
| 74 | } |
||
| 75 |
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: