Completed
Push — master ( 64123e...952eff )
by Rougin
01:47
created

ValidateTrait::errors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
/**
6
 * Validate Trait
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
trait ValidateTrait
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $errors = array();
17
18
    /**
19
     * Returns a listing of error messages.
20
     *
21
     * @return array
22
     */
23 3
    public function errors()
24
    {
25 3
        return $this->errors;
26
    }
27
28
    /**
29
     * Validates the specified data based on the validation rules.
30
     *
31
     * @param  array $data
32
     * @return boolean
33
     */
34 3
    public function validate(array $data = array())
35
    {
36 3
        $this->load->library('form_validation');
0 ignored issues
show
Bug introduced by
The property load does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
38 3
        ! empty($data) && $this->form_validation->set_data($data);
0 ignored issues
show
Bug introduced by
The property form_validation does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
40 3
        $this->form_validation->set_rules($this->validation_rules);
0 ignored issues
show
Bug introduced by
The property validation_rules does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
42 3
        if (! ($validated = $this->form_validation->run())) {
43 3
            $this->errors = $this->form_validation->error_array();
44 2
        }
45
46 3
        return $validated;
47
    }
48
49
    /**
50
     * Returns a listing of error messages.
51
     * NOTE: To be removed in v1.0.0. Use $this->errors instead.
52
     *
53
     * @return array
54
     */
55 3
    public function validation_errors()
56
    {
57 3
        return $this->errors();
58
    }
59
}
60