Helper::array()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace HnrAzevedo\Validator;
4
5
trait Helper
6
{
7
    protected static Validator $instance;
8
    protected array $data = [];
9
    protected array $validators = [];
10
    protected string $model = '';
11
    protected array $required = [];
12
    protected array $errors = [];
13
    protected static array $err = [];
14
15
16
    protected static function array($value): Array
17
    {
18
        return (is_array($value)) ? $value : [ $value ];
19
    }
20
21
    protected static function getInstance(?string $lang = null): Validator
22
    {
23
        self::$instance = (isset(self::$instance)) ? self::$instance : new Validator($lang);
24
        return self::$instance;
25
    }
26
27
    protected function error(array $error): void
28
    {
29
        $this->errors[] = $error;
30
    }
31
32
    protected function data($field = null, ?array $values = null)
33
    {
34
        if(null !== $values){
35
            $this->data[$field] = $values;
36
        }
37
        if(null !== $field){
38
            return $this->data[$field];
39
        }
40
        return $this->data;
41
    }
42
43
    protected function validator(string $model, ?object $callback = null)
44
    {
45
        if(null !== $callback){
46
            $this->validators[$model] = $callback;
47
        }
48
        return $this->validators[$model];
49
    }
50
51
    protected function model(?string $model = null): string
52
    {
53
        if(null !== $model){
54
            $this->model = $model;
55
        }
56
        return $this->model;
57
    }
58
59
    protected function required(): array
60
    {
61
        return $this->required;
62
    }
63
64
}
65