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 | 3 | 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 | 3 | public function send($notifiable, Notification $notification) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Send update ticket request. |
||
| 48 | * |
||
| 49 | * @param int $id |
||
| 50 | */ |
||
| 51 | 1 | View Code Duplication | private function updateTicket($id) |
| 52 | { |
||
| 53 | 1 | $this->prepareUpdateParameters(); |
|
| 54 | |||
| 55 | try { |
||
| 56 | 1 | $this->client->tickets()->update($id, $this->parameters); |
|
| 57 | 1 | } catch (\Exception $e) { |
|
| 58 | throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage()); |
||
| 59 | } |
||
| 60 | 1 | } |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Send create ticket request. |
||
| 64 | * |
||
| 65 | * @param mixed $notifiable |
||
| 66 | */ |
||
| 67 | 2 | View Code Duplication | private function createNewTicket($notifiable) |
| 77 | |||
| 78 | /** |
||
| 79 | * Prepare the parameters before update request send. |
||
| 80 | * |
||
| 81 | */ |
||
| 82 | 1 | public function prepareUpdateParameters() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Prepare the parameters before create request send. |
||
| 89 | * |
||
| 90 | * @param mixed $notifiable |
||
| 91 | */ |
||
| 92 | 2 | private function prepareCreateParameter($notifiable) |
|
| 107 | } |
||
| 108 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.