Passed
Push — master ( f58bd0...03116c )
by Rougin
01:39
created

ValidateTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A errors() 0 3 1
A validate() 0 17 2
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
/**
6
 * Validate Trait
7
 *
8
 * @property array               $rules
9
 * @property \CI_Form_validation $form_validation
10
 * @property \CI_Loader          $load
11
 *
12
 * @package Wildfire
13
 * @author  Rougin Royce Gutib <[email protected]>
14
 */
15
trait ValidateTrait
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $errors = array();
21
22
    /**
23
     * Validates the specified data based on the validation rules.
24
     *
25
     * @param  array $data
26
     * @return boolean
27
     */
28 3
    public function validate(array $data)
29
    {
30 3
        $this->load->library('form_validation');
31
32 3
        $validation = $this->form_validation;
33
34 3
        $validation->set_data((array) $data);
35
36 3
        $validation->set_rules($this->rules);
37
38 3
        if ($validation->run() === false) {
39 3
            $errors = $validation->error_array();
40
41 3
            $this->errors = (array) $errors;
42 3
        }
43
44 3
        return $validation->run() === true;
45
    }
46
47
    /**
48
     * Returns a listing of error messages.
49
     *
50
     * @return array
51
     */
52 3
    public function errors()
53
    {
54 3
        return $this->errors;
55
    }
56
}
57