Passed
Push — 1.x ( e91c3c...4cbda7 )
by Kevin
01:45
created

JsonResponse::dump()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zenstruck\Browser\Response;
4
5
use Symfony\Component\VarDumper\VarDumper;
6
use Zenstruck\Browser\Response;
7
use function JmesPath\search;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class JsonResponse extends Response
13
{
14
    public function body()
15
    {
16
        return \json_decode(parent::body(), true, 512, JSON_THROW_ON_ERROR);
17
    }
18
19
    public function dump(?string $selector = null): void
20
    {
21
        if (null === $selector) {
22
            parent::dump();
23
24
            return;
25
        }
26
27
        VarDumper::dump($this->find($selector));
28
    }
29
30
    public function find(string $selector)
31
    {
32
        return search($selector, $this->body());
33
    }
34
35
    protected function rawBody(): string
36
    {
37
        return \json_encode($this->body(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
38
    }
39
}
40