| Conditions | 3 |
| Paths | 10 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | public function read () : void |
||
| 32 | { |
||
| 33 | if ( $this->url == null ) { |
||
| 34 | throw new Exception( "A URL must be set before reading" ); |
||
| 35 | } |
||
| 36 | |||
| 37 | try { |
||
| 38 | $ch = curl_init(); |
||
| 39 | |||
| 40 | $timeout = 5; |
||
| 41 | |||
| 42 | curl_setopt( $ch, CURLOPT_URL, $this->url ); |
||
|
|
|||
| 43 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
||
| 44 | curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); |
||
| 45 | |||
| 46 | $this->html = curl_exec( $ch ); |
||
| 47 | |||
| 48 | curl_close( $ch ); |
||
| 49 | |||
| 50 | # Create a DOM parser object |
||
| 51 | $this->dom = new DOMDocument(); |
||
| 52 | |||
| 53 | # The @ before the method call suppresses any warnings that loadHTML might throw because of invalid HTML in the page. |
||
| 54 | @$this->dom->loadHTML( $this->html ); |
||
| 55 | } catch ( Exception $e ) { |
||
| 56 | |||
| 70 |