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 |
||
18 | class ConsoleReporter implements ReporterInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var OutputInterface |
||
22 | */ |
||
23 | protected $output; |
||
24 | |||
25 | /** |
||
26 | * @param OutputInterface $output |
||
27 | */ |
||
28 | View Code Duplication | public function __construct(OutputInterface $output = null) |
|
35 | |||
36 | public function setOutput(OutputInterface $output) |
||
40 | |||
41 | public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
||
68 | |||
69 | public function onStart(\ArrayObject $checks, $runnerConfig) |
||
73 | |||
74 | public function onBeforeRun(CheckInterface $check, $checkAlias = null) |
||
78 | |||
79 | public function onStop(ResultsCollection $results) |
||
83 | |||
84 | public function onFinish(ResultsCollection $results) |
||
88 | } |
||
89 |
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.