Conditions | 4 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
40 | public function read () : void |
||
41 | { |
||
42 | if ( empty( $this->url ) ) { |
||
43 | throw new SourceWatcherException( "A URL must be set before reading" ); |
||
44 | } |
||
45 | |||
46 | $ch = curl_init(); |
||
47 | |||
48 | $timeout = 5; |
||
49 | |||
50 | curl_setopt( $ch, CURLOPT_URL, $this->url ); |
||
51 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
||
52 | curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); |
||
53 | |||
54 | $this->html = curl_exec( $ch ); |
||
55 | |||
56 | curl_close( $ch ); |
||
57 | |||
58 | # Create a DOM parser object |
||
59 | $this->dom = new DOMDocument(); |
||
60 | |||
61 | if ( isset( $this->html ) && $this->html !== "" ) { |
||
62 | # The @ before the method call suppresses any warnings that loadHTML might throw because of invalid HTML in the page. |
||
63 | @$this->dom->loadHTML( $this->html ); |
||
|
|||
64 | } |
||
77 |
If you suppress an error, we recommend checking for the error condition explicitly: