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 |
||
16 | class JobEnqueueSingle extends Command |
||
17 | { |
||
18 | use ManagerRegistryAwareTrait; |
||
19 | use LoggerAwareTrait; |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | protected $signature = 'job:enqueue:single {jobId}'; |
||
25 | |||
26 | /** |
||
27 | * @var EnqueueSingleStoredJobService |
||
28 | */ |
||
29 | private $service; |
||
30 | |||
31 | /** |
||
32 | * @param EnqueueSingleStoredJobService $service |
||
33 | * @param ManagerRegistry|null $managerRegistry |
||
34 | * @param LoggerInterface|null $logger |
||
35 | */ |
||
36 | View Code Duplication | public function __construct( |
|
46 | |||
47 | /** |
||
48 | * @throws FailedToEnqueueStoredJobException |
||
49 | * @throws StoredJobNotFoundException |
||
50 | */ |
||
51 | public function handle() |
||
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | private function topicName(): string |
||
68 | } |
||
69 |
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.