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 |
||
| 6 | class TwigFakerExtensionTest extends PHPUnit_Framework_TestCase |
||
|
|
|||
| 7 | { |
||
| 8 | protected $twigFaker; |
||
| 9 | |||
| 10 | public function setUp() |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @test |
||
| 19 | */ |
||
| 20 | public function it_registers_the_extension_name_correctly() |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @test |
||
| 29 | */ |
||
| 30 | public function it_registers_a_fake_function() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @test |
||
| 39 | */ |
||
| 40 | public function it_throws_an_exception_when_an_invalid_factory_is_used() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @test |
||
| 49 | */ |
||
| 50 | public function it_returns_one_fake_item_when_no_count_is_passed() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @test |
||
| 59 | */ |
||
| 60 | public function it_returns_fifteen_fake_items_when_the_count_is_passed() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @test |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function it_caches_a_single_fake_item_when_given_a_cache_key() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * @test |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function it_caches_multiple_fake_item_when_given_a_cache_key() |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @test |
||
| 91 | */ |
||
| 92 | public function it_caches_single_fake_items_with_different_cache_keys() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @test |
||
| 107 | */ |
||
| 108 | public function it_allows_the_same_cache_key_to_be_used_for_different_factories() |
||
| 115 | } |
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.