Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\CodeCoverage\Report\Xml;
11
 
12
use function sprintf;
13
use DOMElement;
14
use DOMNode;
15
use SebastianBergmann\CodeCoverage\Util\Percentage;
16
 
17
/**
18
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
19
 */
20
final class Totals
21
{
22
    /**
23
     * @var DOMNode
24
     */
25
    private $container;
26
 
27
    /**
28
     * @var DOMElement
29
     */
30
    private $linesNode;
31
 
32
    /**
33
     * @var DOMElement
34
     */
35
    private $methodsNode;
36
 
37
    /**
38
     * @var DOMElement
39
     */
40
    private $functionsNode;
41
 
42
    /**
43
     * @var DOMElement
44
     */
45
    private $classesNode;
46
 
47
    /**
48
     * @var DOMElement
49
     */
50
    private $traitsNode;
51
 
52
    public function __construct(DOMElement $container)
53
    {
54
        $this->container = $container;
55
        $dom             = $container->ownerDocument;
56
 
57
        $this->linesNode = $dom->createElementNS(
58
            'https://schema.phpunit.de/coverage/1.0',
59
            'lines'
60
        );
61
 
62
        $this->methodsNode = $dom->createElementNS(
63
            'https://schema.phpunit.de/coverage/1.0',
64
            'methods'
65
        );
66
 
67
        $this->functionsNode = $dom->createElementNS(
68
            'https://schema.phpunit.de/coverage/1.0',
69
            'functions'
70
        );
71
 
72
        $this->classesNode = $dom->createElementNS(
73
            'https://schema.phpunit.de/coverage/1.0',
74
            'classes'
75
        );
76
 
77
        $this->traitsNode = $dom->createElementNS(
78
            'https://schema.phpunit.de/coverage/1.0',
79
            'traits'
80
        );
81
 
82
        $container->appendChild($this->linesNode);
83
        $container->appendChild($this->methodsNode);
84
        $container->appendChild($this->functionsNode);
85
        $container->appendChild($this->classesNode);
86
        $container->appendChild($this->traitsNode);
87
    }
88
 
89
    public function container(): DOMNode
90
    {
91
        return $this->container;
92
    }
93
 
94
    public function setNumLines(int $loc, int $cloc, int $ncloc, int $executable, int $executed): void
95
    {
96
        $this->linesNode->setAttribute('total', (string) $loc);
97
        $this->linesNode->setAttribute('comments', (string) $cloc);
98
        $this->linesNode->setAttribute('code', (string) $ncloc);
99
        $this->linesNode->setAttribute('executable', (string) $executable);
100
        $this->linesNode->setAttribute('executed', (string) $executed);
101
        $this->linesNode->setAttribute(
102
            'percent',
103
            $executable === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($executed, $executable)->asFloat())
104
        );
105
    }
106
 
107
    public function setNumClasses(int $count, int $tested): void
108
    {
109
        $this->classesNode->setAttribute('count', (string) $count);
110
        $this->classesNode->setAttribute('tested', (string) $tested);
111
        $this->classesNode->setAttribute(
112
            'percent',
113
            $count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat())
114
        );
115
    }
116
 
117
    public function setNumTraits(int $count, int $tested): void
118
    {
119
        $this->traitsNode->setAttribute('count', (string) $count);
120
        $this->traitsNode->setAttribute('tested', (string) $tested);
121
        $this->traitsNode->setAttribute(
122
            'percent',
123
            $count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat())
124
        );
125
    }
126
 
127
    public function setNumMethods(int $count, int $tested): void
128
    {
129
        $this->methodsNode->setAttribute('count', (string) $count);
130
        $this->methodsNode->setAttribute('tested', (string) $tested);
131
        $this->methodsNode->setAttribute(
132
            'percent',
133
            $count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat())
134
        );
135
    }
136
 
137
    public function setNumFunctions(int $count, int $tested): void
138
    {
139
        $this->functionsNode->setAttribute('count', (string) $count);
140
        $this->functionsNode->setAttribute('tested', (string) $tested);
141
        $this->functionsNode->setAttribute(
142
            'percent',
143
            $count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat())
144
        );
145
    }
146
}