JsonInspector::writeJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Rezzza\RestApiBehatExtension\Json;
4
5
use JsonSchema\Validator;
6
use Symfony\Component\PropertyAccess\PropertyAccess;
7
8
class JsonInspector
9
{
10
    private $jsonParser;
11
12
    private $jsonStorage;
13
14
    private $jsonSearcher;
15
16
    public function __construct(JsonStorage $jsonStorage, JsonParser $jsonParser, JsonSearcher $jsonSearcher)
17
    {
18
        $this->jsonParser = $jsonParser;
19
        $this->jsonStorage = $jsonStorage;
20
        $this->jsonSearcher = $jsonSearcher;
21
    }
22
23
    public function readJsonNodeValue($jsonNodeExpression)
24
    {
25
        return $this->jsonParser->evaluate(
26
            $this->readJson(),
27
            $jsonNodeExpression
28
        );
29
    }
30
31
    public function searchJsonPath($pathExpression)
32
    {
33
        return $this->jsonSearcher->search($this->readJson(), $pathExpression);
34
    }
35
36
    public function validateJson(JsonSchema $jsonSchema)
37
    {
38
        $this->jsonParser->validate(
39
            $this->readJson(),
40
            $jsonSchema
41
        );
42
    }
43
44
    public function readJson()
45
    {
46
        return $this->jsonStorage->readJson();
47
    }
48
49
    public function writeJson($jsonContent)
50
    {
51
        $this->jsonStorage->writeRawContent($jsonContent);
52
    }
53
}
54