Completed
Push — master ( 269a50...019c60 )
by Tobias
04:32
created

BladeTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 52.17 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 24
loc 46
c 0
b 0
f 0
rs 10

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
/*
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 PHPUnit\Framework\TestCase;
15
use Symfony\Component\Finder\Finder;
16
use Translation\Extractor\FileExtractor\BladeFileExtractor;
17
use Translation\Extractor\Model\SourceCollection;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class BladeTest extends TestCase
23
{
24
    private function getSourceLocations($relativePath)
25
    {
26
        $extractor = new BladeFileExtractor();
27
28
        $filename = substr($relativePath, 1 + strrpos($relativePath, '/'));
29
        $path = __DIR__.'/../Resources/'.substr($relativePath, 0, strrpos($relativePath, '/'));
30
31
        $finder = new Finder();
32
        $finder->files()->name($filename)->in($path);
33
        $collection = new SourceCollection();
34
        foreach ($finder as $file) {
35
            $extractor->getSourceLocations($file, $collection);
36
        }
37
38
        return $collection;
39
    }
40
41
    public function testExtractLang()
42
    {
43
        $collection = $this->getSourceLocations('Blade/lang.blade.php');
44
45
        $this->assertCount(1, $collection);
46
        $source = $collection->first();
47
        $this->assertEquals('foo.bar', $source->getMessage());
48
    }
49
50
    public function testExtractTrans()
51
    {
52
        $collection = $this->getSourceLocations('Blade/trans.blade.php');
53
54
        $this->assertCount(1, $collection);
55
        $source = $collection->first();
56
        $this->assertEquals('foo.bar', $source->getMessage());
57
    }
58
59
    public function testExtractTransChoice()
60
    {
61
        $collection = $this->getSourceLocations('Blade/trans_choice.blade.php');
62
63
        $this->assertCount(1, $collection);
64
        $source = $collection->first();
65
        $this->assertEquals('foo.bar', $source->getMessage());
66
    }
67
}
68