Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
40.00% |
2 / 5 |
CRAP | |
33.33% |
5 / 15 |
| WebPage | |
0.00% |
0 / 1 |
|
40.00% |
2 / 5 |
26.96 | |
33.33% |
5 / 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 |
6.00 | |
0.00% |
0 / 3 |
|||
| getDom | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
| getDomQueryHandler | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 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->getDomQueryHandler(); | |
| $form = $xpath->query('//form'); | |
| return $form !== false && $form->count(); | |
| } | |
| private function getDom(): DOMDocument | |
| { | |
| if (!isset($this->dom)) { | |
| $this->dom = new DOMDocument(); | |
| $this->dom->loadHTML($this->response->getBody()); | |
| } | |
| return $this->dom; | |
| } | |
| private function getDomQueryHandler(): DOMXPath | |
| { | |
| if (!isset($this->xpath)) { | |
| $this->xpath = new DOMXPath($this->getDom()); | |
| } | |
| return $this->xpath; | |
| } | |
| } |