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 namespace DiegoCaprioli\Larachimp\Jobs; |
||
14 | View Code Duplication | class RemoveMailchimpMember implements SelfHandling, ShouldQueue |
|
|
|||
15 | { |
||
16 | use InteractsWithQueue, SerializesModels; |
||
17 | |||
18 | /** |
||
19 | * The old email that needs to be replaced with the new one on the member |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $email; |
||
24 | |||
25 | /** |
||
26 | * Create a new job instance. |
||
27 | * |
||
28 | * @param string $email |
||
29 | */ |
||
30 | 2 | public function __construct($email) |
|
34 | |||
35 | /** |
||
36 | * Execute the job. |
||
37 | */ |
||
38 | 2 | public function handle() |
|
47 | } |
||
48 |
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.