Completed
Push — master ( 97eb8d...d5332d )
by
unknown
59:42 queued 58:43
created

ValidationRuleParserProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 36.36%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 2
dl 0
loc 65
ccs 4
cts 11
cp 0.3636
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parse() 0 4 1
A explodeRules() 0 4 1
A __call() 0 6 1
1
<?php
2
3
namespace Proengsoft\JsValidation\Support;
4
5
use Illuminate\Validation\ValidationRuleParser;
6
7
class ValidationRuleParserProxy
8
{
9
    use AccessProtectedTrait;
10
    
11
    /**
12
     * ValidationRuleParser instance.
13
     *
14
     * @var ValidationRuleParser
15
     */
16
    protected $parser;
17
18
    /**
19
     * Closure to invoke non accessible Validator methods.
20
     *
21
     * @var \Closure
22
     */
23
    protected $parserMethod;
24
25
    /**
26
     * ValidationRuleParserProxy constructor.
27
     *
28
     * @param array $data
29
     */
30 72
    public function __construct($data = [])
31
    {
32 72
        $this->parser = new ValidationRuleParser((array) $data);
33 72
        $this->parserMethod = $this->createProtectedCaller($this->parser);
34 72
    }
35
36
    /**
37
     * Extract the rule name and parameters from a rule.
38
     *
39
     * @param array|string $rules
40
     * @return array
41
     */
42
    public function parse($rules)
43
    {
44
        return $this->parser->parse($rules);
45
    }
46
47
    /**
48
     * Explode the rules into an array of explicit rules.
49
     *
50
     * @param  array $rules
51
     * @return mixed
52
     */
53
    public function explodeRules($rules)
54
    {
55
        return $this->callProtected($this->parserMethod, 'explodeRules', [ $rules ]);
56
    }
57
58
    /**
59
     * Delegate method calls to parser instance.
60
     *
61
     * @param  string $method
62
     * @param  mixed  $params
63
     * @return mixed
64
     */
65
    public function __call($method, $params)
66
    {
67
        $arrCaller = [$this->parser, $method];
68
69
        return call_user_func_array($arrCaller, $params);
70
    }
71
}
72