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 |
||
| 16 | class Entity |
||
| 17 | { |
||
| 18 | /** Deletion flag field name */ |
||
| 19 | const DELETE_FLAG_FIELD = 'Active'; |
||
| 20 | |||
| 21 | /** @var QueryInterface Database query instance */ |
||
| 22 | protected $query; |
||
| 23 | |||
| 24 | /** @var string Entity identifier */ |
||
| 25 | protected $identifier; |
||
| 26 | |||
| 27 | /** @var string Entity primary field name */ |
||
| 28 | protected $primaryField; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Entity constructor. |
||
| 32 | * @param QueryInterface $query Database query instance |
||
| 33 | * @param string $identifier Entity identifier |
||
| 34 | */ |
||
| 35 | public function __construct(QueryInterface $query, $identifier) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get current entity identifiers collection by navigation identifier. |
||
| 44 | * |
||
| 45 | * @param string $navigationID Navigation identifier |
||
| 46 | * @param array $filteringIDs Collection of entity identifiers for filtering query |
||
| 47 | * @return array Collection of entity identifiers filtered by navigation identifier. |
||
| 48 | */ |
||
| 49 | public function idsByNavigationID($navigationID, $filteringIDs = null) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get current entity instances collection by their identifiers. |
||
| 65 | * Method can accept different query executors. |
||
| 66 | * |
||
| 67 | * @param string|array $entityIDs Entity identifier or their collection |
||
| 68 | * @param string $executor Method name for query execution |
||
| 69 | * @return self[] Collection of entity instances |
||
| 70 | */ |
||
| 71 | public function byIDs($entityIDs, $executor = 'exec') |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Get current entity instances collection by navigation identifier. |
||
| 81 | * |
||
| 82 | * @param string $navigationID Navigation identifier |
||
| 83 | * @return self[] Collection of entity instances |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function byNavigationID($navigationID) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Get current entity instances amount by navigation identifier. |
||
| 98 | * |
||
| 99 | * @param string $navigationID Navigation identifier |
||
| 100 | * @return integer Amount of entities related to Navigation identifier |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function amountByNavigationID($navigationID) |
|
| 112 | } |
||
| 113 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: