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 |
||
17 | class Logger extends \Zend\Log\Logger implements TestListener, MasterListenerAware, LoggerInterface |
||
18 | { |
||
19 | |||
20 | protected $status = self::STATUS_PASSED; |
||
21 | |||
22 | protected $testName = self::NAME_DEFAULT; |
||
23 | |||
24 | protected $testId; |
||
25 | |||
26 | protected $invokedTest; |
||
27 | |||
28 | protected $selectorConfig = null; |
||
29 | |||
30 | public function setMasterListener(MasterListenerInterface $listener) |
||
34 | |||
35 | |||
36 | View Code Duplication | public function addCharacteristic($type, $value) |
|
47 | |||
48 | public function getInvokedTest() |
||
52 | |||
53 | public function setTestName($name) |
||
57 | |||
58 | public function setTestStatus($status) |
||
62 | |||
63 | public function setTestId($testId) |
||
67 | |||
68 | public function logStep($stepId) |
||
72 | |||
73 | public function logAssertionSuccess(AbstractAssertion $assertion, array $extra) |
||
78 | |||
79 | public function logAssertionFailure(Exception $e, AbstractAssertion $assertion, array $extra) |
||
84 | |||
85 | View Code Duplication | public function createExtra($includeArray = []) |
|
100 | |||
101 | public function addWarning(Test $test, Warning $e, $time) |
||
105 | |||
106 | public function addError(Test $test, \Exception $e, $time) |
||
111 | |||
112 | public function addFailure(Test $test, AssertionFailedError $e, $time) |
||
117 | |||
118 | public function addIncompleteTest(Test $test, Exception $e, $time) |
||
123 | |||
124 | public function addRiskyTest(Test $test, Exception $e, $time) |
||
128 | |||
129 | public function addSkippedTest(Test $test, Exception $e, $time) |
||
134 | |||
135 | public function startTestSuite(TestSuite $suite) |
||
139 | |||
140 | public function endTestSuite(TestSuite $suite) |
||
144 | |||
145 | View Code Duplication | public function startTest(Test $test) |
|
156 | |||
157 | public function endTest(Test $test, $time) |
||
162 | |||
163 | |||
164 | } |
||
165 |
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.