Completed
Pull Request — master (#3)
by Rougin
04:33
created

ValidateTrait::validationErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Rougin\Credo\Traits;
4
5
/**
6
 * Validate Trait
7
 *
8
 * @package Credo
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 *
11
 * @property array               $validation_rules
12
 * @property \CI_Form_validation $form_validation
13
 * @property \CI_Loader          $load
14
 */
15
trait ValidateTrait
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $validationErrors = [];
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
        if (! empty($data)) {
33 3
            $this->form_validation->set_data($data);
34 3
        }
35
36 3
        $this->form_validation->set_rules($this->validation_rules);
37
38 3
        if ($this->form_validation->run() === false) {
39 3
            $this->validationErrors = $this->form_validation->error_array();
40 3
        }
41
42 3
        return $validated;
0 ignored issues
show
Bug introduced by
The variable $validated does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
43
    }
44
45
    /**
46
     * Returns a listing of error messages.
47
     *
48
     * @return array
49
     */
50
    public function validationErrors()
51
    {
52
        return $this->validationErrors;
53
    }
54
}
55