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 |
||
10 | class ZendeskChannel |
||
11 | { |
||
12 | /** @var HttpClient */ |
||
13 | protected $client; |
||
14 | |||
15 | /** @var array */ |
||
16 | protected $parameters; |
||
17 | |||
18 | /** @param HttpClient $client */ |
||
19 | 2 | public function __construct(HttpClient $client) |
|
23 | |||
24 | /** |
||
25 | * Send the given notification. |
||
26 | * |
||
27 | * @param mixed $notifiable |
||
28 | * @param \Illuminate\Notifications\Notification $notification |
||
29 | * |
||
30 | * @throws \NotificationChannels\Zendesk\Exceptions\InvalidConfiguration |
||
31 | * @throws \NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification |
||
32 | */ |
||
33 | 2 | public function send($notifiable, Notification $notification) |
|
45 | |||
46 | /** |
||
47 | * Send update ticket request. |
||
48 | * |
||
49 | * @param mixed $notifiable |
||
50 | */ |
||
51 | 2 | View Code Duplication | private function updateTicket($id, $notifiable) |
61 | 1 | ||
62 | /** |
||
63 | 2 | * Send create ticket request. |
|
64 | * |
||
65 | * @param mixed $notifiable |
||
66 | */ |
||
67 | View Code Duplication | private function createNewTicket($notifiable) |
|
77 | |||
78 | /** |
||
79 | * Prepare the parameters before update request send. |
||
80 | * |
||
81 | * @param mixed $notifiable |
||
82 | */ |
||
83 | public function prepareUpdateParameters() |
||
87 | |||
88 | /** |
||
89 | * Prepare the parameters before create request send. |
||
90 | * |
||
91 | * @param mixed $notifiable |
||
92 | */ |
||
93 | private function prepareCreateParameter($notifiable) |
||
108 | } |
||
109 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.