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 |
||
19 | trait FindTrait |
||
20 | { |
||
21 | /** |
||
22 | * Find multiple records based on provided query. |
||
23 | * |
||
24 | * Example: |
||
25 | * User::find(['status' => 'active'], ['profile']); |
||
26 | * |
||
27 | * @param array $where Selection WHERE statement. |
||
28 | * @param array $load Array or relations to be pre-loaded. |
||
29 | * @return RecordSelector |
||
30 | */ |
||
31 | public static function find($where = [], array $load = []) |
||
35 | |||
36 | /** |
||
37 | * Fetch one record based on provided query or return null. Use second argument to specify |
||
38 | * relations to be loaded. |
||
39 | * |
||
40 | * Example: |
||
41 | * User::findOne(['name' => 'Wolfy-J'], ['profile'], ['id' => 'DESC']); |
||
42 | * |
||
43 | * @param array $where Selection WHERE statement. |
||
44 | * @param array $load Array or relations to be pre-loaded. |
||
45 | * @param array $orderBy Sort by conditions. |
||
46 | * @return RecordEntity|null |
||
47 | */ |
||
48 | public static function findOne($where = [], array $load = [], array $orderBy = []) |
||
57 | |||
58 | /** |
||
59 | * Find record using it's primary key. Relation data can be preloaded with found record. |
||
60 | * |
||
61 | * Example: |
||
62 | * User::findByID(1, ['profile']); |
||
63 | * |
||
64 | * @param mixed $primaryKey Primary key. |
||
65 | * @param array $load Array or relations to be pre-loaded. |
||
66 | * @return RecordEntity|null |
||
67 | */ |
||
68 | public static function findByPK($primaryKey, array $load = []) |
||
72 | |||
73 | /** |
||
74 | * Instance of ORM Selector associated with specific document. |
||
75 | * |
||
76 | * @see Component::staticContainer() |
||
77 | * @param ORM $orm ORM component, global container will be called if not instance provided. |
||
78 | * @return RecordSource |
||
79 | * @throws ORMException |
||
80 | */ |
||
81 | View Code Duplication | public static function source(ORM $orm = null) |
|
95 | } |
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: