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 |
||
12 | class DbalUserMapper extends DbalMapper implements UserMapper |
||
13 | { |
||
14 | const COLUMNS = "id, name, role, email, phone, created_at, updated_at"; |
||
15 | |||
16 | protected static function findStatement() |
||
23 | |||
24 | protected static function findByRoleStatement() |
||
31 | |||
32 | protected static function insertStatement() |
||
36 | |||
37 | public function find($id) |
||
51 | |||
52 | View Code Duplication | public function findByRole($role) |
|
60 | |||
61 | protected function doLoad($id, array $resultSet) |
||
70 | |||
71 | public function insert(User $user) |
||
75 | |||
76 | /** |
||
77 | * Bind query parameters and execute insert statement |
||
78 | * |
||
79 | * @param User $subject |
||
80 | * @param Statement $insertStatement |
||
81 | * |
||
82 | * @return int The id of the inserted row |
||
83 | */ |
||
84 | protected function doInsert($subject, Statement $insertStatement) |
||
95 | } |
||
96 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.