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 declare(strict_types=1); |
||
9 | View Code Duplication | final class CompletedEvent extends AbstractEvent |
|
|
|||
10 | { |
||
11 | /** |
||
12 | * @var RequestInterface |
||
13 | */ |
||
14 | public $request; |
||
15 | |||
16 | /** |
||
17 | * @var ResponseInterface|null |
||
18 | */ |
||
19 | public $response; |
||
20 | |||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | public $startedAt; |
||
25 | |||
26 | /** |
||
27 | * @var float |
||
28 | */ |
||
29 | public $completedAt; |
||
30 | |||
31 | /** |
||
32 | * Init a new instance. |
||
33 | * |
||
34 | * @param float $startedAt |
||
35 | * @param RequestInterface $request |
||
36 | * @param float $completedAt |
||
37 | * @param ResponseInterface|null $response |
||
38 | */ |
||
39 | public function __construct( |
||
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.