Code Duplication    Length = 44-44 lines in 2 locations

src/DataEnricher/Processor/JmesPath.php 1 location

@@ 14-57 (lines=44) @@
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
        $instruction = $node->getInstruction($this);
26
        
27
        if (is_array($instruction) || is_object($instruction)) {
28
            $instruction = (object)$instruction;
29
        }
30
        
31
        $input = is_string($instruction) ? $node->getResult() : $instruction->input;
32
        $query = is_string($instruction) ? $instruction : $instruction->query;
33
        
34
        $result = jmespath_search($query, $input);
35
        static::objectivy($result);
36
        
37
        $node->setResult($result);
38
    }
39
    
40
    /**
41
     * Cast associated arrays to objects
42
     * 
43
     * @return mixed
44
     */
45
    protected static function objectivy(&$value)
46
    {
47
        if (Utils::isObject($value)) {
48
            $value = (object)$value;
49
        }
50
        
51
        if (is_array($value) || is_object($value)) {
52
            foreach ($value as &$item) {
53
                static::objectivy($item);
54
            }
55
        }
56
    }
57
}
58

src/DataEnricher/Processor/Reference.php 1 location

@@ 14-57 (lines=44) @@
11
 * Reference JMESPath processor
12
 * @see http://jmespath.org/
13
 */
14
class Reference 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
        $instruction = $node->getInstruction($this);
26
        
27
        if (is_array($instruction) || is_object($instruction)) {
28
            $instruction = (object)$instruction;
29
        }
30
        
31
        $input = is_string($instruction) ? $node->getResult() : $instruction->input;
32
        $query = is_string($instruction) ? $instruction : $instruction->query;
33
        
34
        $result = jmespath_search($query, $input);
35
        static::objectivy($result);
36
        
37
        $node->setResult($result);
38
    }
39
    
40
    /**
41
     * Cast associated arrays to objects
42
     * 
43
     * @return mixed
44
     */
45
    protected static function objectivy(&$value)
46
    {
47
        if (Utils::isObject($value)) {
48
            $value = (object)$value;
49
        }
50
        
51
        if (is_array($value) || is_object($value)) {
52
            foreach ($value as &$item) {
53
                static::objectivy($item);
54
            }
55
        }
56
    }
57
}
58