Total Complexity | 5 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class JsonHandler |
||
8 | { |
||
9 | /** @var Connection */ |
||
10 | protected $connection; |
||
11 | |||
12 | /** @var JsonSelectorHandler */ |
||
13 | protected $jsonSelectorHandler; |
||
14 | |||
15 | /** @var JsonExpressionFactory */ |
||
16 | protected $jsonExpressionFactory; |
||
17 | |||
18 | public function __construct(Connection $connection) |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Returns the JSON Selector Handler |
||
27 | * |
||
28 | * @return JsonSelectorHandler |
||
29 | */ |
||
30 | public function jsonSelectorHandler(): JsonSelectorHandler |
||
31 | { |
||
32 | return $this->jsonSelectorHandler; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Returns the JSON Expression library |
||
37 | * |
||
38 | * @return JsonExpressionFactory |
||
39 | */ |
||
40 | public function jsonExpressionFactory(): JsonExpressionFactory |
||
41 | { |
||
42 | return $this->jsonExpressionFactory; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Parses a JSON selector and returns as an Extract and Unquote expression. |
||
47 | * |
||
48 | * @param string $selector |
||
49 | * @return string |
||
50 | */ |
||
51 | public function extractAndUnquoteFromJsonSelector(string $selector): string |
||
52 | { |
||
53 | $selector = $this->jsonSelectorHandler()->toJsonSelector($selector); |
||
54 | return $this->jsonExpressionFactory()->extractAndUnquote( |
||
55 | $selector->getColumn(), |
||
56 | $selector->getNodes() |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Checks if the passed values is a valid JSON Selector |
||
62 | * |
||
63 | * @param mixed $expression |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function isJsonSelector($expression): bool |
||
69 | } |
||
70 | } |
||
71 |