Completed
Pull Request — master (#59)
by Alessandro
06:35
created

CoverageFilterBuilder::createFromConfiguration()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 30
Code Lines 17

Duplication

Lines 14
Ratio 46.67 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 14
loc 30
ccs 0
cts 25
cp 0
rs 8.439
c 0
b 0
f 0
cc 5
eloc 17
nc 16
nop 1
crap 30
1
<?php
2
3
namespace Paraunit\Coverage;
4
5
use Paraunit\Configuration\PHPUnitConfig;
6
use SebastianBergmann\CodeCoverage\Filter;
7
8
/**
9
 * Class CoverageFilter
10
 * @package Paraunit\Coverage
11
 */
12
class CoverageFilterBuilder
13
{
14
    /** @var  Filter */
15
    private $codeCoverageFilter;
16
17
    /**
18
     * CoverageFilterBuilder constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->codeCoverageFilter = new Filter();
23
    }
24
25
    public function createFromConfiguration(PHPUnitConfig $configFile)
26
    {
27
        $filterConfiguration = \PHPUnit_Util_Configuration::getInstance($configFile->getFileFullPath());
28
29 View Code Duplication
        foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            $this->codeCoverageFilter->addDirectoryToWhitelist(
31
                $dir['path'],
32
                $dir['suffix'],
33
                $dir['prefix']
34
            );
35
        }
36
37
        foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
38
            $this->codeCoverageFilter->addFileToWhitelist($file);
39
        }
40
41 View Code Duplication
        foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
42
            $this->codeCoverageFilter->removeDirectoryFromWhitelist(
43
                $dir['path'],
44
                $dir['suffix'],
45
                $dir['prefix']
46
            );
47
        }
48
49
        foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
50
            $this->codeCoverageFilter->removeFileFromWhitelist($file);
51
        }
52
53
        return $this->codeCoverageFilter;
54
    }
55
}
56