| 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 DOMElement;
|
|
|
13 |
use TheSeer\Tokenizer\NamespaceUri;
|
|
|
14 |
use TheSeer\Tokenizer\Tokenizer;
|
|
|
15 |
use TheSeer\Tokenizer\XMLSerializer;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
|
|
19 |
*/
|
|
|
20 |
final class Source
|
|
|
21 |
{
|
|
|
22 |
/** @var DOMElement */
|
|
|
23 |
private $context;
|
|
|
24 |
|
|
|
25 |
public function __construct(DOMElement $context)
|
|
|
26 |
{
|
|
|
27 |
$this->context = $context;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function setSourceCode(string $source): void
|
|
|
31 |
{
|
|
|
32 |
$context = $this->context;
|
|
|
33 |
|
|
|
34 |
$tokens = (new Tokenizer)->parse($source);
|
|
|
35 |
$srcDom = (new XMLSerializer(new NamespaceUri($context->namespaceURI)))->toDom($tokens);
|
|
|
36 |
|
|
|
37 |
$context->parentNode->replaceChild(
|
|
|
38 |
$context->ownerDocument->importNode($srcDom->documentElement, true),
|
|
|
39 |
$context
|
|
|
40 |
);
|
|
|
41 |
}
|
|
|
42 |
}
|