1 | <?php |
||
5 | class Parser |
||
6 | { |
||
7 | public $options = [ |
||
8 | 'libxml_options' => 0 |
||
9 | ]; |
||
10 | |||
11 | 4 | public function __construct( $options = array() ) |
|
12 | { |
||
13 | 4 | $optionList = [ 'libxml_options' ]; |
|
14 | 4 | foreach( $options as $option => $optionValue ) { |
|
15 | if ( in_array( $option, $optionList ) ) { |
||
16 | $this->{$option} = $optionValue; |
||
17 | } |
||
18 | } |
||
19 | 4 | } |
|
20 | |||
21 | 4 | public function parse( $html, $encoding = null ) |
|
22 | { |
||
23 | 4 | if ( !$html ) { |
|
24 | return \arc\html\Proxy( null ); |
||
25 | } |
||
26 | 4 | if ( $html instanceof Proxy ) { // already parsed |
|
27 | return $html; |
||
28 | } |
||
29 | 4 | $html = (string) $html; |
|
30 | 4 | if ( stripos($html, '<body>')!==false ) { |
|
31 | 4 | return $this->parseFull( $html, $encoding ); |
|
32 | } else { |
||
33 | 1 | return $this->parsePartial( $html, $encoding ); |
|
34 | } |
||
35 | } |
||
36 | |||
37 | 1 | private function parsePartial( $html, $encoding ) |
|
38 | { |
||
39 | 1 | $result = $this->parseFull( '<body id="ArcPartialHTML">'.$html.'</body>', $encoding ); |
|
40 | 1 | if ( $result ) { |
|
41 | 1 | $result = new \arc\html\Proxy( $result->find('#ArcPartialHTML')[0]->children(), $this ); |
|
42 | // $result = new \arc\html\Proxy( $result->children(), $this ); |
||
|
|||
43 | } else { |
||
44 | throw new \arc\Exception('parse error'); |
||
45 | } |
||
46 | 1 | return $result; |
|
47 | } |
||
48 | |||
49 | private function throwError($prevErrorSetting) |
||
60 | |||
61 | 1 | private function insertEncoding($html, $encoding) |
|
62 | { |
||
63 | 1 | $meta = '<meta id="ArcTempEncoding" http-equiv="content-type" content="text/html; charset="'. htmlspecialchars($encoding) .'">'; |
|
73 | |||
74 | 1 | private function removeEncoding( $dom ) |
|
79 | |||
80 | 4 | private function parseFull( $html, $encoding ) |
|
97 | |||
98 | } |
||
99 |
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.