Failed Conditions
Push — master ( 0bbe18...211e20 )
by Moesjarraf
03:53
created

GetByReference::getByReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor\Helper;
4
5
use function JmesPath\search as jmespath_search;
6
7
/**
8
 * Get property from source or target by reference
9
 */
10
trait GetByReference
11
{
12
    /**
13
     * @var object
14
     */
15
    protected $source;
16
17
    /**
18
     * @var object|array
19
     */
20
    protected $target;
21
22
    
23
    /**
24
     * Get copy of processor that uses the given source and target
25
     * 
26
     * @param object       $source  Data source
27
     * @param array|object $target  Target or dot key path
28
     */
29 1
    public function withSourceAndTarget($source, $target)
30
    {
31 1
        $clone = clone $this;
32
        
33 1
        $clone->source = $source;
34 1
        $clone->target = $target;
35
        
36 1
        return $clone;
37
    }
38
    
39
    /**
40
     * Get item by reference
41
     * 
42
     * @param string       $ref
43
     * @param object       $source
44
     * @param object|array $target
45
     */
46 1
    protected function getByReference($ref, $source, $target)
0 ignored issues
show
Unused Code introduced by
The parameter $target is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48 1
        $subject = $source;
49
        
50 1
        $result = jmespath_search($ref, $subject);
51
        
52 1
        return $result;
53
    }
54
}
55