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 |
||
9 | class FeedbackService |
||
10 | { |
||
11 | /** |
||
12 | * The feedback client instance. |
||
13 | * |
||
14 | * @var \ZendService\Apple\Apns\Client\Feedback |
||
15 | */ |
||
16 | protected $client; |
||
17 | |||
18 | /** |
||
19 | * The connection environment. |
||
20 | * |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $environment; |
||
24 | |||
25 | /** |
||
26 | * The connection certificate. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $certificate; |
||
31 | |||
32 | /** |
||
33 | * The connection pass phrase. |
||
34 | * |
||
35 | * @var stirng |
||
36 | */ |
||
37 | protected $passPhrase; |
||
38 | |||
39 | /** |
||
40 | * Create feedback service instance. |
||
41 | * |
||
42 | * @param \ZendService\Apple\Apns\Client\Feedback $client |
||
43 | * @param string $environment |
||
44 | * @param string $certificate |
||
45 | * @param string|null $passPhrase |
||
46 | */ |
||
47 | 1 | public function __construct(Client $client, $environment, $certificate, $passPhrase = null) |
|
54 | |||
55 | /** |
||
56 | * Get feedback from the Apple Feedback Service about failed deliveries. |
||
57 | * |
||
58 | * @return array|ApnFeedback[] |
||
59 | * @throws Exceptions\ConnectionFailed |
||
60 | */ |
||
61 | 1 | public function get() |
|
71 | |||
72 | /** |
||
73 | * Open the connection to the feedback service. |
||
74 | * |
||
75 | * @return void |
||
76 | * @throws \NotificationChannels\Apn\Exception\ConnectionFailed |
||
77 | */ |
||
78 | 1 | View Code Duplication | protected function openConnection() |
86 | |||
87 | /** |
||
88 | * Fetch the feedback from APNS and collect our feedback object. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | protected function fetchFeedback() |
|
103 | } |
||
104 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.