Completed
Pull Request — master (#17)
by Tobias
01:59
created

BladeTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 51.06 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 24
loc 47
ccs 29
cts 29
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceLocations() 0 16 2
A testExtractLang() 8 8 1
A testExtractTrans() 8 8 1
A testExtractTransChoice() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Translation\Extractor\Tests\Functional;
4
5
use Symfony\Component\Finder\Finder;
6
use Translation\Extractor\FileExtractor\BladeFileExtractor;
7
use Translation\Extractor\Model\SourceCollection;
8
9
class BladeTest extends \PHPUnit_Framework_TestCase
10
{
11 3
    private function getSourceLocations($relativePath)
12
    {
13 3
        $extractor = new BladeFileExtractor();
14
15 3
        $filename = substr($relativePath, 1 + strrpos($relativePath, '/'));
16 3
        $path = __DIR__.'/../Resources/'.substr($relativePath, 0, strrpos($relativePath, '/'));
17
18 3
        $finder = new Finder();
19 3
        $finder->files()->name($filename)->in($path);
20 3
        $collection = new SourceCollection();
21 3
        foreach ($finder as $file) {
22 3
            $extractor->getSourceLocations($file, $collection);
23 3
        }
24
25 3
        return $collection;
26
    }
27
28
29 1 View Code Duplication
    public function testExtractLang()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
30
    {
31 1
        $collection = $this->getSourceLocations('Blade/lang.blade.php');
32
33 1
        $this->assertCount(1, $collection);
34 1
        $source = $collection->first();
35 1
        $this->assertEquals('foo.bar', $source->getMessage());
36 1
    }
37
38 1 View Code Duplication
    public function testExtractTrans()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
39
    {
40 1
        $collection = $this->getSourceLocations('Blade/trans.blade.php');
41
42 1
        $this->assertCount(1, $collection);
43 1
        $source = $collection->first();
44 1
        $this->assertEquals('foo.bar', $source->getMessage());
45 1
    }
46
47 1 View Code Duplication
    public function testExtractTransChoice()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
48
    {
49 1
        $collection = $this->getSourceLocations('Blade/trans_choice.blade.php');
50
51 1
        $this->assertCount(1, $collection);
52 1
        $source = $collection->first();
53 1
        $this->assertEquals('foo.bar', $source->getMessage());
54 1
    }
55
}
56