Issues (26)

src/snippet/SimpleSnippet.php (2 issues)

Labels
Severity
1
<?php declare(strict_types = 1);
2
namespace Templado\Engine;
3
4
use DOMElement;
5
use DOMNode;
6
7
class SimpleSnippet implements Snippet {
8
9
    /** @var DOMNode */
10
    private $content;
11
12
    /** @var string */
13
    private $targetId;
14
15 15
    public function __construct(string $targetId, DOMNode $content) {
16 15
        $this->targetId = $targetId;
17 15
        $this->content  = $content;
18 15
    }
19
20 3
    public function getTargetId(): string {
21 3
        return $this->targetId;
22
    }
23
24 9
    public function applyTo(DOMElement $node): DOMNode {
25 9
        $content = $node->ownerDocument->importNode($this->content, true);
0 ignored issues
show
The method importNode() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $content = $node->ownerDocument->importNode($this->content, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
27 9
        if ($this->shouldReplace($node, $content)) {
28 3
            $node->parentNode->replaceChild($content, $node);
0 ignored issues
show
The method replaceChild() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            $node->parentNode->/** @scrutinizer ignore-call */ 
29
                               replaceChild($content, $node);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
30 3
            return $content;
31
        }
32
33 6
        $node->appendChild($content);
34
35 6
        return $node;
36
    }
37
38 9
    private function shouldReplace(DOMElement $node, DOMNode $content): bool {
39 9
        if (!$content instanceof DOMElement) {
40 3
            return false;
41
        }
42
43 6
        if (!$node->hasAttribute('id') || !$content->hasAttribute('id')) {
44 3
            return false;
45
        }
46
47 3
        return $node->getAttribute('id') === $content->getAttribute('id');
48
    }
49
}
50