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 BlockCest extends CestCase |
||
|
|
|||
| 4 | { |
||
| 5 | |||
| 6 | private $simpleBlock = [ |
||
| 7 | 'fields' => [ |
||
| 8 | 'name' => 'testing block', |
||
| 9 | ], |
||
| 10 | 'options' => [ |
||
| 11 | 'day' => 'sobota', |
||
| 12 | 'start_hour' => '10', |
||
| 13 | 'end_hour' => '12', |
||
| 14 | 'start_minute' => '15', |
||
| 15 | 'end_minute' => '30', |
||
| 16 | ], |
||
| 17 | ]; |
||
| 18 | |||
| 19 | private $fullBlock = [ |
||
| 20 | 'fields' => [ |
||
| 21 | 'name' => 'testing block', |
||
| 22 | "//textarea[@name='description']" => 'testování', |
||
| 23 | 'tutor' => 'Tester Testovič', |
||
| 24 | 'email' => '[email protected]', |
||
| 25 | 'capacity' => 1, |
||
| 26 | ], |
||
| 27 | 'options' => [ |
||
| 28 | 'day' => 'sobota', |
||
| 29 | 'start_hour' => '10', |
||
| 30 | 'end_hour' => '12', |
||
| 31 | 'start_minute' => '15', |
||
| 32 | 'end_minute' => '30', |
||
| 33 | 'program' => 1, |
||
| 34 | 'display_progs' => 0, |
||
| 35 | 'category' => 1, |
||
| 36 | ], |
||
| 37 | ]; |
||
| 38 | |||
| 39 | public function _before(AcceptanceTester $I) |
||
| 51 | |||
| 52 | public function _after(AcceptanceTester $I) |
||
| 55 | |||
| 56 | // tests |
||
| 57 | public function ensure_that_blocks_works(\AcceptanceTester $I) |
||
| 63 | |||
| 64 | public function ensure_that_creating_works(\AcceptanceTester $I) |
||
| 83 | |||
| 84 | View Code Duplication | public function it_should_create_simple_block(\AcceptanceTester $I) |
|
| 95 | |||
| 96 | public function it_should_update_simple_block(\AcceptanceTester $I) |
||
| 99 | |||
| 100 | View Code Duplication | public function it_should_create_full_block(\AcceptanceTester $I) |
|
| 111 | |||
| 112 | public function it_should_update_full_block(\AcceptanceTester $I) |
||
| 115 | |||
| 116 | } |
||
| 117 |
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.