Passed
Pull Request — master (#17)
by
unknown
01:19
created

HTML5Value   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B setContent() 0 30 3
1
<?php
2
3
namespace SilverStripe\HTML5;
4
5
use Exception;
6
use SilverStripe\View\Parsers\HTMLValue;
7
8
class HTML5Value extends HTMLValue
9
{
10
    public function setContent($content)
11
    {
12
        require_once(HTML5LIB_PATH.'/HTML5/Parser.php');
0 ignored issues
show
Bug introduced by
The constant SilverStripe\HTML5\HTML5LIB_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
14
        // Convert any errors to exceptions
15
        set_error_handler(
16
            function ($no, $str) {
17
                throw new Exception("HTML Parse Error: ".$str);
18
            },
19
            error_reporting()
20
        );
21
22
        // Use HTML5lib to parse the HTML fragment
23
        try {
24
            $document = \HTML5_Parser::parse(
0 ignored issues
show
Bug introduced by
The type HTML5_Parser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
                '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'.
26
                "<body>$content</body></html>"
27
            );
28
        } catch (Exception $e) {
29
            $document = false;
30
        }
31
32
        // Disable our error handler (restoring to previous value)
33
        restore_error_handler();
34
35
        // If we couldn't parse the HTML, set the error state
36
        if ($document) {
37
            $this->setDocument($document);
38
        } else {
39
            $this->setInvalid();
40
        }
41
    }
42
}
43