Completed
Push — master ( 503ac3...8ef7d4 )
by Sven
10s
created

JmesPath   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 0
cbo 3
dl 0
loc 38
ccs 0
cts 17
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyToNode() 0 10 1
B objectivy() 0 12 5
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
use function JmesPath\search as jmespath_search;
8
use JmesPath\Utils;
9
10
/**
11
 * JMESPath processor
12
 * @see http://jmespath.org/
13
 */
14
class JmesPath implements Processor
15
{
16
    use Processor\Implementation;
17
    
18
    /**
19
     * Apply processing to a single node
20
     * 
21
     * @param Node $node
22
     */
23
    public function applyToNode(Node $node)
24
    {
25
        $path = $node->getInstruction($this);
26
        $input = $node->getResult();
27
        
28
        $result = jmespath_search($path, $input);
29
        static::objectivy($result);
30
        
31
        $node->setResult($result);
32
    }
33
    
34
    /**
35
     * Cast associated arrays to objects
36
     * 
37
     * @return mixed
38
     */
39
    protected static function objectivy(&$value)
40
    {
41
        if (Utils::isObject($value)) {
42
            $value = (object)$value;
43
        }
44
        
45
        if (is_array($value) || is_object($value)) {
46
            foreach ($value as &$item) {
47
                static::objectivy($item);
48
            }
49
        }
50
    }
51
}
52