Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
40.00% |
2 / 5 |
CRAP | |
73.33% |
11 / 15 |
| WebPage | |
0.00% |
0 / 1 |
|
40.00% |
2 / 5 |
7.93 | |
73.33% |
11 / 15 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getUrl | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| hasForm | |
0.00% |
0 / 1 |
1.30 | |
33.33% |
1 / 3 |
|||
| getDom | |
0.00% |
0 / 1 |
2.06 | |
75.00% |
3 / 4 |
|||
| getXPath | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
| <?php | |
| namespace Luxian\Test; | |
| use DOMDocument; | |
| use DOMXPath; | |
| use Luxian\Http\Request; | |
| use Luxian\Http\Response; | |
| use Luxian\Type\Url; | |
| class WebPage | |
| { | |
| /** @var Request */ | |
| private $request; | |
| /** @var Response */ | |
| private $response; | |
| /** @var WebPage|null */ | |
| private $previous; | |
| /** @var DOMDocument|null */ | |
| private $dom; | |
| /** @var DOMXPath|null */ | |
| private $xpath; | |
| public function __construct( | |
| Request $request, | |
| Response $response, | |
| WebPage $previous = null | |
| ) | |
| { | |
| $this->request = $request; | |
| $this->response = $response; | |
| $this->previous = $previous; | |
| } | |
| public function getUrl(): Url | |
| { | |
| return Url::fromString($this->request->getRequestUriPath()); | |
| } | |
| public function hasForm(): bool | |
| { | |
| $xpath = $this->getXPath(); | |
| $xpath->query('//form'); | |
| } | |
| private function getDom(): DOMDocument | |
| { | |
| if (!isset($this->dom)) { | |
| $this->dom = new DOMDocument(); | |
| $this->dom->loadHTML($this->response->getBody()); | |
| } | |
| return $this->dom; | |
| } | |
| private function getXPath(): DOMXPath | |
| { | |
| if (!isset($this->xpath)) { | |
| $this->xpath = new DOMXPath($this->getDom()); | |
| } | |
| return $this->xpath; | |
| } | |
| } |