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 |
||
12 | View Code Duplication | class HasSyntaxCorrectCheck implements CheckInterface |
|
|
|||
13 | { |
||
14 | const ERROR_STATUS = 'PARSER_ERROR'; |
||
15 | |||
16 | /** @var Parser */ |
||
17 | private $parser; |
||
18 | |||
19 | /** @var string */ |
||
20 | private $lastError; |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * @param Parser $parser |
||
26 | */ |
||
27 | public function __construct(Parser $parser) |
||
31 | |||
32 | |||
33 | |||
34 | /** |
||
35 | * @param Candidate $candidate |
||
36 | * @return bool True / False based on the fact if check is met or not |
||
37 | */ |
||
38 | public function execute(Candidate $candidate) |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getLastErrorMessage() |
||
59 | |||
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getErrorCode() |
||
68 | } |
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.