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 |
||
11 | class CheckerHasRecovered extends Notification |
||
12 | { |
||
13 | public $checker; |
||
14 | public $failedData; |
||
15 | |||
16 | public function __construct(Checker $checker, array $failedData) |
||
21 | |||
22 | /** |
||
23 | * Get the notification's channels from the configuration file. |
||
24 | * |
||
25 | * @return array|string |
||
26 | */ |
||
27 | public function via(): array |
||
31 | |||
32 | /** |
||
33 | * Returns an array of all relevant data for the notification. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | View Code Duplication | protected function data(): array |
|
46 | |||
47 | /** |
||
48 | * Build the mail representation of the notification. |
||
49 | * |
||
50 | * @return \Illuminate\Notifications\Messages\MailMessage |
||
51 | */ |
||
52 | public function toMail(): MailMessage |
||
62 | |||
63 | /** |
||
64 | * Build the Slack representation of the notification. |
||
65 | * |
||
66 | * @return \Illuminate\Notifications\Messages\SlackMessage |
||
67 | */ |
||
68 | View Code Duplication | public function toSlack(): SlackMessage |
|
82 | } |
||
83 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.