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 |
||
26 | class LdapObjectChoiceLoader implements ChoiceLoaderInterface |
||
27 | { |
||
28 | use LdapObjectChoiceTrait; |
||
29 | |||
30 | /** |
||
31 | * @var ChoiceListFactoryInterface |
||
32 | */ |
||
33 | private $factory; |
||
34 | |||
35 | /** |
||
36 | * @var ChoiceListInterface|null |
||
37 | */ |
||
38 | protected $choiceList; |
||
39 | |||
40 | /** |
||
41 | * @param LdapManager $ldap |
||
42 | * @param string $type The LDAP object type. |
||
43 | * @param string $labelAttribute The LDAP attribute to use for the label. |
||
44 | * @param string $id The attribute to use for the ID. |
||
45 | * @param LdapQueryBuilder|\Closure|null |
||
46 | */ |
||
47 | public function __construct(LdapManager $ldap, $type, $labelAttribute = 'name', $id = 'guid', $query = null) |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function loadChoiceList($value = null) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | View Code Duplication | public function loadValuesForChoices(array $choices, $value = null) |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | View Code Duplication | public function loadChoicesForValues(array $values, $value = null) |
|
106 | } |
||
107 |
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: