PHP 8.2.30
Preview: Coverage.php Size: 1.75 KB
/home/byroehnu/easetack.com/vendor/phpunit/php-code-coverage/src/Report/Xml/Coverage.php

<?php declare(strict_types=1);
/*
 * This file is part of phpunit/php-code-coverage.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace SebastianBergmann\CodeCoverage\Report\Xml;

use DOMElement;
use SebastianBergmann\CodeCoverage\ReportAlreadyFinalizedException;
use XMLWriter;

/**
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
 */
final class Coverage
{
    private readonly XMLWriter $writer;
    private readonly DOMElement $contextNode;
    private bool $finalized = false;

    public function __construct(DOMElement $context, string $line)
    {
        $this->contextNode = $context;

        $this->writer = new XMLWriter;
        $this->writer->openMemory();
        $this->writer->startElementNS(null, $context->nodeName, 'https://schema.phpunit.de/coverage/1.0');
        $this->writer->writeAttribute('nr', $line);
    }

    /**
     * @throws ReportAlreadyFinalizedException
     */
    public function addTest(string $test): void
    {
        if ($this->finalized) {
            throw new ReportAlreadyFinalizedException;
        }

        $this->writer->startElement('covered');
        $this->writer->writeAttribute('by', $test);
        $this->writer->endElement();
    }

    public function finalize(): void
    {
        $this->writer->endElement();

        $fragment = $this->contextNode->ownerDocument->createDocumentFragment();
        $fragment->appendXML($this->writer->outputMemory());

        $this->contextNode->parentNode->replaceChild(
            $fragment,
            $this->contextNode,
        );

        $this->finalized = true;
    }
}

Directory Contents

Dirs: 0 × Files: 13

Name Size Perms Modified Actions
2.42 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
1.75 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
479 B lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
8.83 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
2.04 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
1.56 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
2.16 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
2.41 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
2.55 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
1.11 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
1.25 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
4.24 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download
2.14 KB lrw-rw-rw- 2025-02-25 13:26:39
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).