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 |
||
8 | View Code Duplication | class FunctionEvent extends Event |
|
|
|||
9 | { |
||
10 | const FUNCTION_BEFORE_EXECUTE = 'worker.function.before_execute'; |
||
11 | const FUNCTION_AFTER_EXECUTE = 'worker.function.after_execute'; |
||
12 | |||
13 | private $jobHandler; |
||
14 | private $job; |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $result; |
||
19 | |||
20 | public function __construct(JobHandlerInterface $jobHandler, JobInterface $job, $result = []) |
||
21 | { |
||
22 | $this->jobHandler = $jobHandler; |
||
23 | $this->job = $job; |
||
24 | $this->result = $result; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @return array |
||
29 | */ |
||
30 | public function getResult() |
||
34 | |||
35 | /** |
||
36 | * @return JobHandlerInterface |
||
37 | */ |
||
38 | public function getJobHandler() |
||
42 | |||
43 | /** |
||
44 | * @return JobInterface |
||
45 | */ |
||
46 | public function getJob() |
||
50 | } |
||
51 |
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.