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 basename;
13
use function dirname;
14
use DOMDocument;
15
 
16
/**
17
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
18
 */
19
final class Report extends File
20
{
21
    public function __construct(string $name)
22
    {
23
        $dom = new DOMDocument;
24
        $dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="https://schema.phpunit.de/coverage/1.0"><file /></phpunit>');
25
 
26
        $contextNode = $dom->getElementsByTagNameNS(
27
            'https://schema.phpunit.de/coverage/1.0',
28
            'file'
29
        )->item(0);
30
 
31
        parent::__construct($contextNode);
32
 
33
        $this->setName($name);
34
    }
35
 
36
    public function asDom(): DOMDocument
37
    {
38
        return $this->dom();
39
    }
40
 
41
    public function functionObject($name): Method
42
    {
43
        $node = $this->contextNode()->appendChild(
44
            $this->dom()->createElementNS(
45
                'https://schema.phpunit.de/coverage/1.0',
46
                'function'
47
            )
48
        );
49
 
50
        return new Method($node, $name);
51
    }
52
 
53
    public function classObject($name): Unit
54
    {
55
        return $this->unitObject('class', $name);
56
    }
57
 
58
    public function traitObject($name): Unit
59
    {
60
        return $this->unitObject('trait', $name);
61
    }
62
 
63
    public function source(): Source
64
    {
65
        $source = $this->contextNode()->getElementsByTagNameNS(
66
            'https://schema.phpunit.de/coverage/1.0',
67
            'source'
68
        )->item(0);
69
 
70
        if (!$source) {
71
            $source = $this->contextNode()->appendChild(
72
                $this->dom()->createElementNS(
73
                    'https://schema.phpunit.de/coverage/1.0',
74
                    'source'
75
                )
76
            );
77
        }
78
 
79
        return new Source($source);
80
    }
81
 
82
    private function setName(string $name): void
83
    {
84
        $this->contextNode()->setAttribute('name', basename($name));
85
        $this->contextNode()->setAttribute('path', dirname($name));
86
    }
87
 
88
    private function unitObject(string $tagName, $name): Unit
89
    {
90
        $node = $this->contextNode()->appendChild(
91
            $this->dom()->createElementNS(
92
                'https://schema.phpunit.de/coverage/1.0',
93
                $tagName
94
            )
95
        );
96
 
97
        return new Unit($node, $name);
98
    }
99
}