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

CoverageFilterBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 14
loc 44
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B createFromConfiguration() 14 30 5

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 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