| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the PHP Translation package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) PHP Translation team <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Translation\Extractor\Tests\Functional; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Finder\Finder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Translation\Extractor\FileExtractor\BladeFileExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Translation\Extractor\Model\SourceCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |         $collection = $this->getSourceLocations('Blade/lang.blade.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |         $this->assertCount(1, $collection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |         $source = $collection->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |         $this->assertEquals('foo.bar', $source->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 46 | 1 | View Code Duplication |     public function testExtractTrans() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |         $collection = $this->getSourceLocations('Blade/trans.blade.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |         $this->assertCount(1, $collection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |         $source = $collection->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |         $this->assertEquals('foo.bar', $source->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 55 | 1 | View Code Duplication |     public function testExtractTransChoice() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |         $collection = $this->getSourceLocations('Blade/trans_choice.blade.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |         $this->assertCount(1, $collection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |         $source = $collection->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 1 |  |         $this->assertEquals('foo.bar', $source->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 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.