Inspector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A join() 0 3 1
A valid() 0 4 2
1
<?php
2
/**
3
 * Validation inspector
4
 * User: moyo
5
 * Date: 2018/6/4
6
 * Time: 6:03 PM
7
 */
8
9
namespace Carno\Validator;
10
11
use Carno\Validator\Contracts\Sourcing;
12
use Carno\Validator\Valid\Executor;
13
use Throwable;
14
15
class Inspector
16
{
17
    /**
18
     * @var Executor[][]
19
     */
20
    private $executors = [];
21
22
    /**
23
     * @var Sourcing
24
     */
25
    private $sourcing = null;
26
27
    /**
28
     * Inspector constructor.
29
     * @param Sourcing $sourcing
30
     */
31
    public function __construct(Sourcing $sourcing)
32
    {
33
        $this->sourcing = $sourcing;
34
    }
35
36
    /**
37
     * @param string $class
38
     * @param string $method
39
     * @param Executor $executor
40
     */
41
    public function join(string $class, string $method, Executor $executor) : void
42
    {
43
        $this->executors[$class][$method] = $executor;
44
    }
45
46
    /**
47
     * @param string $class
48
     * @param string $method
49
     * @param mixed $input
50
     * @throws Throwable
51
     */
52
    public function valid(string $class, string $method, $input)
53
    {
54
        if ($executor = $this->executors[$class][$method] ?? null) {
55
            $this->sourcing->validating($executor, $input);
56
        }
57
    }
58
}
59