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 namespace Nwidart\Modules\Tests; |
||
9 | class RepositoryTest extends BaseTestCase |
||
10 | { |
||
11 | /** |
||
12 | * @var Repository |
||
13 | */ |
||
14 | private $repository; |
||
15 | |||
16 | public function setUp() |
||
21 | |||
22 | /** @test */ |
||
23 | public function it_adds_location_to_paths() |
||
33 | |||
34 | /** @test */ |
||
35 | public function it_returns_a_collection() |
||
42 | |||
43 | /** @test */ |
||
44 | View Code Duplication | public function it_returns_all_enabled_modules() |
|
51 | |||
52 | /** @test */ |
||
53 | View Code Duplication | public function it_returns_all_disabled_modules() |
|
60 | |||
61 | /** @test */ |
||
62 | public function it_counts_all_modules() |
||
68 | |||
69 | /** @test */ |
||
70 | public function it_finds_a_module() |
||
77 | |||
78 | /** @test */ |
||
79 | public function it_find_or_fail_throws_exception_if_module_not_found() |
||
85 | |||
86 | /** @test */ |
||
87 | public function it_finds_the_module_asset_path() |
||
94 | |||
95 | /** @test */ |
||
96 | public function it_gets_the_used_storage_path() |
||
102 | |||
103 | /** @test */ |
||
104 | public function it_sets_used_module() |
||
113 | |||
114 | /** @test */ |
||
115 | public function it_returns_laravel_filesystem() |
||
119 | |||
120 | /** @test */ |
||
121 | public function it_gets_the_assets_path() |
||
125 | |||
126 | /** @test */ |
||
127 | public function it_gets_a_specific_module_asset() |
||
133 | |||
134 | /** @test */ |
||
135 | public function it_can_detect_if_module_is_active() |
||
141 | |||
142 | /** @test */ |
||
143 | public function it_can_detect_if_module_is_inactive() |
||
149 | |||
150 | /** @test */ |
||
151 | public function it_can_get_and_set_the_stubs_path() |
||
157 | |||
158 | /** @test */ |
||
159 | public function it_gets_the_configured_stubs_path_if_enabled() |
||
165 | |||
166 | /** @test */ |
||
167 | public function it_returns_default_stub_path() |
||
171 | } |
||
172 |
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.