Passed
Push — master ( 42c6c4...6eb781 )
by Henri
06:37
created

Helper::array()   A

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 string $lang = 'en';
14
    protected static array $err = [];
15
16
17
    protected static function array($value): Array
18
    {
19
        return (is_array($value)) ? $value : [ $value ];
20
    }
21
22
    protected static function getInstance(?string $lang = null): Validator
23
    {
24
        self::$lang = (null !== $lang) ? $lang : 'en';
25
        self::$instance = (isset(self::$instance)) ? self::$instance : new Validator();
26
        return self::$instance;
27
    }
28
29
    protected function error(array $error): void
30
    {
31
        $this->errors = array_merge($this->errors, $error);
32
    }
33
34
    protected function data($field = null, ?array $values = null)
35
    {
36
        if(null !== $values){
37
            $this->data[$field] = $values;
38
        }
39
        if(null !== $field){
40
            return $this->data[$field];
41
        }
42
        return $this->data;
43
    }
44
45
    protected function validator(string $model, ?object $callback = null)
46
    {
47
        if(null !== $callback){
48
            $this->validators[$model] = $callback;
49
        }
50
        return $this->validators[$model];
51
    }
52
53
    protected function model(?string $model = null): string
54
    {
55
        if(null !== $model){
56
            $this->model = $model;
57
        }
58
        return $this->model;
59
    }
60
61
    protected function required(): array
62
    {
63
        return $this->required;
64
    }
65
66
}
67