Dom   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A locate() 0 5 1
A __toString() 0 5 2
1
<?php
2
3
namespace WebinoDomLib;
4
5
/**
6
 * Class DomHtml
7
 *
8
 * @package WebinoDomLib
9
 */
10
class Dom implements Dom\NodeLocatorInterface
11
{
12
    use Dom\LocatorAwareTrait;
13
14
    /**
15
     * @var Dom\Document
16
     */
17
    private $doc;
18
19
    // TODO factory
20
    public function __construct($code)
21
    {
22
        // hack HTML5
23
        libxml_use_internal_errors(true);
24
25
        $this->doc = new Dom\Document;
26
27
        // TODO
28
        $this->doc->isXml = false;
0 ignored issues
show
Bug introduced by
The property isXml does not seem to exist in WebinoDomLib\Dom\Document.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
30
        $this->doc->isXml ? $this->doc->loadXml($code)
31
               : $this->doc->loadHtml(mb_convert_encoding($code, 'HTML-ENTITIES', 'UTF-8'));
32
    }
33
34
    /**
35
     * Return an element collection
36
     *
37
     * @param string|array $locator
38
     * @return Dom\NodeList
39
     */
40
    public function locate($locator)
41
    {
42
        $nodeList = $this->getLocator()->query($this->doc->getDocumentElement(), $locator);
0 ignored issues
show
Bug introduced by
It seems like $this->doc->getDocumentElement() targeting WebinoDomLib\Dom\Document::getDocumentElement() can also be of type object<DOMElement>; however, WebinoDomLib\Dom\Locator::query() does only seem to accept object<WebinoDomLib\Dom\NodeInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
43
        return new Dom\NodeList($nodeList);
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function __toString()
50
    {
51
        // TODO resolve ->doc->isXml()
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
        return $this->doc->isXml ? $this->doc->saveXml() : $this->doc->saveHtml();
0 ignored issues
show
Bug introduced by
The property isXml does not seem to exist in WebinoDomLib\Dom\Document.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53
    }
54
}
55