SVChecker::checking()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Sourcing value checker
4
 * User: moyo
5
 * Date: 2018/6/8
6
 * Time: 3:06 PM
7
 */
8
9
namespace Carno\Validator\Chips;
10
11
use Carno\Validator\Valid\Message;
12
use Carno\Validator\Valid\Rule;
13
use Respect\Validation\Exceptions\ValidationException;
14
use Throwable;
15
16
trait SVChecker
17
{
18
    /**
19
     * @param Rule $rule
20
     * @param mixed $input
21
     * @throws Throwable
22
     */
23
    protected function checking(Rule $rule, $input)
24
    {
25
        if ($rule->e()->valid()) {
26
            $rule->v()->validate($input) || $rule->e()->throws();
27
        } else {
28
            try {
29
                $rule->v()->check($input);
30
            } catch (ValidationException $e) {
31
                (new Message($e->setName($rule->f())->getMainMessage()))->throws();
32
            }
33
        }
34
    }
35
}
36