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 |
||
3 | class GridFieldRefreshButtonTest extends SapphireTest |
||
|
|||
4 | { |
||
5 | protected static $fixture_file = './GridFieldRefreshButtonTest.yml'; |
||
6 | |||
7 | public function testHasRunningJob() |
||
12 | |||
13 | public function testDoesNotHaveCancelledCompletedOrBrokenJob() |
||
20 | |||
21 | View Code Duplication | public function testHandleRefreshDoesNotCreateJobWhenJobIsRunning() |
|
30 | |||
31 | View Code Duplication | public function testHandleRefreshCreatesJobWhenNoJobIsRunning() |
|
42 | |||
43 | public function testHandleCheckReturnsValidJson() |
||
48 | |||
49 | public function testButtonIsDisabledWhenJobIsRunning() |
||
59 | |||
60 | public function testButtonIsEnabledWhenNoJobIsRunning() |
||
72 | |||
73 | protected function completeRunningJob() |
||
79 | |||
80 | protected function getGridFieldMock() |
||
94 | } |
||
95 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.