Helper   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 25
c 2
b 0
f 1
dl 0
loc 57
rs 10
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A required() 0 3 1
A getInstance() 0 4 2
A model() 0 6 2
A error() 0 3 1
A array() 0 3 2
A validator() 0 6 2
A data() 0 9 3
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