HQ::instance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
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