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

XmlResponse::crawler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
final class XmlResponse extends Response
13
{
14
    public function crawler(): Crawler
15
    {
16
        $dom = new \DOMDocument();
17
        $dom->loadXML($this->body());
18
19
        return new Crawler($dom);
20
    }
21
22
    /**
23
     * @internal
24
     */
25
    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 (!\count($elements)) {
36
            throw new \RuntimeException("Element \"{$selector}\" not found.");
37
        }
38
39
        foreach ($elements as $element) {
40
            VarDumper::dump($element->textContent);
41
        }
42
    }
43
}
44