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 | abstract class AbstractRunner implements RunnerInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var \Gabrieljmj\Should\Report\Report |
||
22 | */ |
||
23 | protected $report; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $rules = []; |
||
29 | |||
30 | public function __construct() |
||
34 | |||
35 | /** |
||
36 | * @param \Gabrieljmj\Should\AmbientInterface $ambient |
||
37 | */ |
||
38 | protected function runTest(AmbientInterface $ambient) |
||
49 | |||
50 | public function pushRule(RuleInterface $rule) |
||
58 | |||
59 | /** |
||
60 | * Returns the test report |
||
61 | * |
||
62 | * @return \Gabrieljmj\Should\Report\Report |
||
63 | */ |
||
64 | public function getReport() |
||
68 | |||
69 | protected function combineReport(Report $report) |
||
91 | |||
92 | abstract protected function acceptRule(RuleInterface $rule); |
||
93 | } |
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.