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 | abstract class HybridSessionAbstractTest extends SapphireTest { |
||
|
|
|||
| 4 | |||
| 5 | public function setUp() { |
||
| 6 | parent::setUp(); |
||
| 7 | |||
| 8 | HybridSessionAbstractTest_TestCookieBackend::$override_headers_sent = false; |
||
| 9 | |||
| 10 | Injector::nest(); |
||
| 11 | Injector::inst()->registerService( |
||
| 12 | new HybridSessionAbstractTest_TestCookieBackend(), |
||
| 13 | 'HybridSessionStore_Cookie' |
||
| 14 | ); |
||
| 15 | |||
| 16 | SS_Datetime::set_mock_now('2010-03-15 12:00:00'); |
||
| 17 | |||
| 18 | if(get_class() === get_class($this)) { |
||
| 19 | $this->markTestSkipped("Skipping abstract test"); |
||
| 20 | $this->skipTest = true; |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | public function tearDown() { |
||
| 25 | Injector::unnest(); |
||
| 26 | SS_Datetime::clear_mock_now(); |
||
| 27 | |||
| 28 | parent::tearDown(); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return HybridSessionStore_Base |
||
| 33 | */ |
||
| 34 | abstract protected function getStore(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Test how this store handles large volumes of data (>1000 characters) |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function testStoreLargeData() { |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Test storage of data |
||
| 59 | */ |
||
| 60 | public function testStoreData() { |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Test expiry of data |
||
| 89 | */ |
||
| 90 | public function testExpiry() { |
||
| 107 | } |
||
| 108 | |||
| 127 | } |
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.