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 |
||
30 | class SubscriberManager |
||
31 | { |
||
32 | /** |
||
33 | * @var SubscriberWebService |
||
34 | */ |
||
35 | private $subscriberWebService; |
||
36 | |||
37 | /** |
||
38 | * @var Serializer |
||
39 | */ |
||
40 | private $serializer; |
||
41 | |||
42 | /** |
||
43 | * @var LoggerInterface |
||
44 | */ |
||
45 | private $logger; |
||
46 | |||
47 | /** |
||
48 | * @param SubscriberWebService $subscriberWebService |
||
49 | * @param Serializer $serializer |
||
50 | * @param LoggerInterface|null $logger |
||
51 | */ |
||
52 | 8 | public function __construct(SubscriberWebService $subscriberWebService, Serializer $serializer, LoggerInterface $logger = null) |
|
58 | |||
59 | /** |
||
60 | * @param array $fields |
||
61 | * |
||
62 | * @return Subscriber |
||
63 | */ |
||
64 | 1 | public function create(array $fields) |
|
71 | |||
72 | /** |
||
73 | * @param Subscriber $subscriber |
||
74 | */ |
||
75 | 1 | public function insert(Subscriber $subscriber) |
|
84 | |||
85 | /** |
||
86 | * @param Subscriber $subscriber |
||
87 | */ |
||
88 | 2 | public function unsubscribe(Subscriber $subscriber) |
|
97 | |||
98 | /** |
||
99 | * @param array $emails |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | 4 | public function findByEmail(array $emails) |
|
124 | |||
125 | /** |
||
126 | * @param string $email |
||
127 | * |
||
128 | * @return Subscriber|null |
||
129 | */ |
||
130 | 2 | public function findOneByEmail($email) |
|
136 | } |
||
137 |
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: