Completed
Push — master ( 0d5c20...3309bb )
by Changwan
09:19
created

PropertyTesterAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getProp() 0 11 3
1
<?php
2
namespace Wandu\Validator\Testers;
3
4
use Wandu\Validator\Contracts\Tester;
5
6
abstract class PropertyTesterAbstract implements Tester
7
{
8
    /** @var string[] */
9
    protected $keys;
10
11
    public function __construct($criteria)
12
    {
13
        $this->keys = array_map("trim", explode(".", $criteria));
14
    }
15
    
16
    protected function getProp($origin)
17
    {
18
        $keys = $this->keys;
19
        $prop = $origin;
20
        while (count($keys)) {
21
            $key = array_shift($keys);
22
            if (!isset($prop[$key])) return;
23
            $prop = $prop[$key];
24
        }
25
        return $prop;
26
    }
27
}
28