Passed
Push — master ( 500a63...c8d25d )
by Glynn
03:58 queued 01:28
created

JsonHandler::jsonExpressionFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Pixie\JSON;
4
5
use Pixie\Connection;
6
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)
19
    {
20
        $this->connection = $connection;
21
        $this->jsonSelectorHandler = new JsonSelectorHandler($connection);
22
        $this->jsonExpressionFactory = new JsonExpressionFactory($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
67
    {
68
        return $this->jsonSelectorHandler()->isJsonSelector($expression);
69
    }
70
}
71