Passed
Push — master ( d7760a...a71729 )
by Rougin
03:02
created

AbstractValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Validators;
4
5
/**
6
 * Abstract Validator
7
 *
8
 * @package App
9
 * @author  Rougin Gutib <[email protected]>
10
 */
11
abstract class AbstractValidator
12
{
13
    /**
14
     * @var \Valitron\Validator
15
     */
16
    protected $validator;
17
18
    /**
19
     * Creates a validator instance.
20
     *
21
     * @param $validator \Valitron\Validator
22
     */
23 12
    public function __construct(\Valitron\Validator $validator)
24
    {
25 12
        $this->validator = $validator;
26 12
    }
27
28
    /**
29
     * Returns a listing of errors after validation (if any).
30
     *
31
     * @return array
32
     */
33 6
    public function errors()
34
    {
35 6
        return $this->validator->errors();
36
    }
37
38
    /**
39
     * Validates the data from the based rules.
40
     *
41
     * @param  array $data
42
     * @return boolean
43
     */
44 12
    public function validate($data = array())
45
    {
46 12
        $this->validator->labels($this->labels());
47
48 12
        $this->rules($data);
49
50 12
        $this->validator = $this->validator->withData($data);
51
52 12
        return $this->validator->validate();
53
    }
54
55
    /**
56
     * Sets the labels in the validator.
57
     *
58
     * @return array
59
     */
60
    abstract protected function labels();
61
62
    /**
63
     * Sets the rules in the validator.
64
     *
65
     * @param  array $data
66
     * @return void
67
     */
68
    abstract protected function rules($data = array());
69
}
70