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 |
||
18 | class BladeTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | 3 | private function getSourceLocations($relativePath) |
|
21 | { |
||
22 | 3 | $extractor = new BladeFileExtractor(); |
|
23 | |||
24 | 3 | $filename = substr($relativePath, 1 + strrpos($relativePath, '/')); |
|
25 | 3 | $path = __DIR__.'/../Resources/'.substr($relativePath, 0, strrpos($relativePath, '/')); |
|
26 | |||
27 | 3 | $finder = new Finder(); |
|
28 | 3 | $finder->files()->name($filename)->in($path); |
|
29 | 3 | $collection = new SourceCollection(); |
|
30 | 3 | foreach ($finder as $file) { |
|
31 | 3 | $extractor->getSourceLocations($file, $collection); |
|
32 | 3 | } |
|
33 | |||
34 | 3 | return $collection; |
|
35 | } |
||
36 | |||
37 | 1 | View Code Duplication | public function testExtractLang() |
45 | |||
46 | 1 | View Code Duplication | public function testExtractTrans() |
54 | |||
55 | 1 | View Code Duplication | public function testExtractTransChoice() |
63 | } |
||
64 |
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.