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 | class DeferredProcessCommand implements ProcessCommand, ParsableCommand |
|
|
|||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $shellCommand; |
||
15 | |||
16 | /** |
||
17 | * @var bool |
||
18 | */ |
||
19 | private $ignoreError; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $lineNumber; |
||
25 | |||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | private $tty; |
||
30 | |||
31 | /** |
||
32 | * @param string $shellCommand |
||
33 | * @param int $lineNumber |
||
34 | * @param bool $ignoreError |
||
35 | * @param bool $tty |
||
36 | */ |
||
37 | public function __construct( |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getShellCommand(): string |
||
56 | |||
57 | /** |
||
58 | * @return boolean |
||
59 | */ |
||
60 | public function isIgnoreError(): bool |
||
64 | |||
65 | /** |
||
66 | * @return int |
||
67 | */ |
||
68 | public function getLineNumber(): int |
||
72 | |||
73 | /** |
||
74 | * @return bool |
||
75 | */ |
||
76 | public function isTTy(): bool |
||
80 | } |
||
81 |
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.