RealCoverageModifier::modifyData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 1
f 1
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace PHPRealCoverage;
4
5
use PHPRealCoverage\Proxy\ClassMetadata;
6
use PHPRealCoverage\Proxy\Line;
7
8
class RealCoverageModifier
9
{
10
    /**
11
     * @var \PHP_CodeCoverage
12
     */
13
    private $report;
14
15
    public function __construct(\PHP_CodeCoverage $report)
16
    {
17
        $this->report = $report;
18
    }
19
20
    public function write(ClassMetadata $class)
21
    {
22
        $property = new \ReflectionProperty('\PHP_CodeCoverage', 'data');
23
        $property->setAccessible(true);
24
        $data = $property->getValue($this->report);
25
26
        $data = $this->modifyData($class, $data);
27
28
        $property->setValue($this->report, $data);
29
    }
30
31
    private function modifyData(ClassMetadata $class, $data)
32
    {
33
        foreach ($class->getLines() as $lineNumber => $line) {
34
            $data = $this->modifyClassData($class, $lineNumber, $line, $data);
35
        }
36
        return $data;
37
    }
38
39
    /**
40
     * @param integer $lineNumber
41
     */
42
    private function modifyClassData(ClassMetadata $class, $lineNumber, Line $line, $data)
43
    {
44
        $coverageInformation = $this->generateCoverageInformation($line);
45
        $data[$class->getFilename()][$lineNumber] = $coverageInformation;
46
        return $data;
47
    }
48
49
    private function generateCoverageInformation(Line $line)
50
    {
51
        if (!$line->isExecutable()) {
52
            return null;
53
        }
54
        if (!$line->isNeccessary()) {
55
            return array();
56
        }
57
58
        return $line->getCoverage();
59
    }
60
}
61