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 | abstract class AbstractParser implements JSONParserChainElementInterface, OutputContainerBearerInterface |
||
| 13 | { |
||
| 14 | /** @var OutputContainer */ |
||
| 15 | protected $outputContainer; |
||
| 16 | |||
| 17 | /** @var string */ |
||
| 18 | protected $singleResultMarker; |
||
| 19 | |||
| 20 | 37 | /** @var string */ |
|
| 21 | protected $title; |
||
| 22 | 37 | ||
| 23 | 37 | /** @var string */ |
|
| 24 | 37 | protected $status; |
|
| 25 | |||
| 26 | 37 | /** @var string */ |
|
| 27 | 37 | protected $messageStartsWith; |
|
| 28 | |||
| 29 | /** |
||
| 30 | * AbstractParser constructor. |
||
| 31 | * |
||
| 32 | 26 | * @param OutputContainer $outputContainer |
|
| 33 | * @param string $singleResultMarker The output of the single test result (.FERW etc) |
||
| 34 | 26 | * @param string $status The status that the parser should catch |
|
| 35 | * @param string | null $messageStartsWith The start of the message that the parser should look for |
||
| 36 | */ |
||
| 37 | public function __construct(OutputContainer $outputContainer, $singleResultMarker, $status, $messageStartsWith = null) |
||
| 44 | |||
| 45 | 24 | /** |
|
| 46 | 10 | * {@inheritdoc} |
|
| 47 | */ |
||
| 48 | 10 | View Code Duplication | public function parsingFoundResult(ProcessResultInterface $process, \stdClass $log) |
| 59 | |||
| 60 | /** |
||
| 61 | * @return OutputContainer |
||
| 62 | */ |
||
| 63 | 18 | public function getOutputContainer() |
|
| 67 | |||
| 68 | 4 | /** |
|
| 69 | * @param ProcessResultInterface $process |
||
| 70 | * @return bool |
||
| 71 | 15 | */ |
|
| 72 | protected function storeParsedBlocks(ProcessResultInterface $process) |
||
| 89 | |||
| 90 | /** |
||
| 91 | 37 | * @param ProcessResultInterface $process |
|
| 92 | * @return bool |
||
| 93 | */ |
||
| 94 | protected function parsingFoundSomething(ProcessResultInterface $process) |
||
| 104 | |||
| 105 | private function parse(ProcessResultInterface $process) |
||
| 112 | } |
||
| 113 |
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.