Completed
Push — 1.x ( b6efad...f02a91 )
by Kevin
16s queued 12s
created

HtmlResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dump() 0 16 3
A crawler() 0 6 1
1
<?php
2
3
namespace Zenstruck\Browser\Response;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
use Symfony\Component\VarDumper\VarDumper;
7
use Zenstruck\Browser\Response;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
class HtmlResponse extends Response
13
{
14
    public function crawler(): Crawler
15
    {
16
        $crawler = new Crawler();
17
        $crawler->addHtmlContent($this->body());
18
19
        return $crawler;
20
    }
21
22
    /**
23
     * @internal
24
     */
25
    final public function dump(?string $selector = null): void
26
    {
27
        if (null === $selector) {
28
            parent::dump();
29
30
            return;
31
        }
32
33
        $elements = $this->crawler()->filter($selector);
34
35
        if (0 === $elements->count()) {
36
            throw new \RuntimeException("Element \"{$selector}\" not found.");
37
        }
38
39
        $elements->each(function(Crawler $node) {
40
            VarDumper::dump($node->html());
41
        });
42
    }
43
}
44