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

ValidateTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 49
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A errors() 0 4 1
A validate() 0 14 3
A validation_errors() 0 4 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