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 DOMDocument;
13
use DOMElement;
14
 
15
/**
16
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
17
 */
18
abstract class Node
19
{
20
    /**
21
     * @var DOMDocument
22
     */
23
    private $dom;
24
 
25
    /**
26
     * @var DOMElement
27
     */
28
    private $contextNode;
29
 
30
    public function __construct(DOMElement $context)
31
    {
32
        $this->setContextNode($context);
33
    }
34
 
35
    public function dom(): DOMDocument
36
    {
37
        return $this->dom;
38
    }
39
 
40
    public function totals(): Totals
41
    {
42
        $totalsContainer = $this->contextNode()->firstChild;
43
 
44
        if (!$totalsContainer) {
45
            $totalsContainer = $this->contextNode()->appendChild(
46
                $this->dom->createElementNS(
47
                    'https://schema.phpunit.de/coverage/1.0',
48
                    'totals'
49
                )
50
            );
51
        }
52
 
53
        return new Totals($totalsContainer);
54
    }
55
 
56
    public function addDirectory(string $name): Directory
57
    {
58
        $dirNode = $this->dom()->createElementNS(
59
            'https://schema.phpunit.de/coverage/1.0',
60
            'directory'
61
        );
62
 
63
        $dirNode->setAttribute('name', $name);
64
        $this->contextNode()->appendChild($dirNode);
65
 
66
        return new Directory($dirNode);
67
    }
68
 
69
    public function addFile(string $name, string $href): File
70
    {
71
        $fileNode = $this->dom()->createElementNS(
72
            'https://schema.phpunit.de/coverage/1.0',
73
            'file'
74
        );
75
 
76
        $fileNode->setAttribute('name', $name);
77
        $fileNode->setAttribute('href', $href);
78
        $this->contextNode()->appendChild($fileNode);
79
 
80
        return new File($fileNode);
81
    }
82
 
83
    protected function setContextNode(DOMElement $context): void
84
    {
85
        $this->dom         = $context->ownerDocument;
86
        $this->contextNode = $context;
87
    }
88
 
89
    protected function contextNode(): DOMElement
90
    {
91
        return $this->contextNode;
92
    }
93
}