Passed
Push — master ( 605b65...7a3d33 )
by Siad
09:53
created

Crap4JPHPUnitResultFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
/**
21
 * Prints Clover XML output of the test
22
 *
23
 * @author  Daniel Kreckel <[email protected]>
24
 * @package phing.tasks.ext.formatter
25
 */
26
class Crap4JPHPUnitResultFormatter extends PHPUnitResultFormatter
27
{
28
    /**
29
     * @var PHPUnit\Framework\TestResult
30
     */
31
    private $result = null;
32
    /**
33
     * PHPUnit version
34
     *
35
     * @var string
36
     */
37
    private $version = null;
38
39
    /**
40
     * @param PHPUnitTask $parentTask
41
     */
42
    public function __construct(PHPUnitTask $parentTask)
43
    {
44
        parent::__construct($parentTask);
45
        $this->version = PHPUnit\Runner\Version::id();
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getExtension()
52
    {
53
        return '.xml';
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getPreferredOutfile()
60
    {
61
        return 'crap4j-coverage';
62
    }
63
64
    /**
65
     * @param PHPUnit\Framework\TestResult $result
66
     */
67
    public function processResult(PHPUnit\Framework\TestResult $result)
68
    {
69
        $this->result = $result;
70
    }
71
72
    public function endTestRun()
73
    {
74
        $coverage = $this->result->getCodeCoverage();
75
        if (!empty($coverage)) {
76
            $crapClass = '\SebastianBergmann\CodeCoverage\Report\Crap4j';
77
            $crap = new $crapClass();
78
            $contents = $crap->process($coverage);
79
            if ($this->out) {
80
                $this->out->write($contents);
81
                $this->out->close();
82
            }
83
        }
84
        parent::endTestRun();
85
    }
86
}
87