HQ   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 42
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 9 2
A htmlFile() 0 3 1
A html() 0 3 1
1
<?php
2
3
namespace Sulao\HtmlQuery;
4
5
use DOMDocument;
6
7
/**
8
 * Class HQ
9
 *
10
 * @package Sulao\HtmlQuery
11
 */
12
class HQ
13
{
14
    /**
15
     * Generate a new instance with the html
16
     *
17
     * @param string $html
18
     *
19
     * @return HtmlDocument
20
     */
21 80
    public static function html(string $html)
22
    {
23 80
        return static::instance($html);
24
    }
25
26
    /**
27
     * Generate a new instance with the html file
28
     *
29
     * @param string $file
30
     *
31
     * @return HtmlDocument
32
     */
33 1
    public static function htmlFile(string $file)
34
    {
35 1
        return static::html(file_get_contents($file));
36
    }
37
38
    /**
39
     * Generate a new instance, optionally with the html
40
     *
41
     * @param string|null $html
42
     *
43
     * @return HtmlDocument
44
     */
45 81
    public static function instance(?string $html = null)
46
    {
47 81
        libxml_use_internal_errors(true);
48 81
        $doc = new DOMDocument();
49 81
        if (!is_null($html)) {
50 81
            $doc->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
51
        }
52
53 81
        return new HtmlDocument($doc);
54
    }
55
}
56