Passed
Push — master ( b18142...b764ce )
by Henri
01:31
created

Helper::required()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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
    
14
    private static function getInstance(): Validator
15
    {
16
        self::$instance = (isset(self::$instance)) ? self::$instance : new Validator();
17
        return self::$instance;
18
    }
19
20
    protected function error($error): void
21
    {
22
        $this->errors[] = $error;
23
    }
24
25
    protected function data($field = null, ?array $values = null)
26
    {
27
        if(null !== $values){
28
            $this->data[$field] = $values;
29
        }
30
        if(null !== $field){
31
            return $this->data[$field];
32
        }
33
        return $this->data;
34
    }
35
36
    protected function validator(string $model, ?object $callback = null)
37
    {
38
        if(null !== $callback){
39
            $this->validators[$model] = $callback;
40
        }
41
        return $this->validators[$model];
42
    }
43
44
    protected function model(?string $model = null): string
45
    {
46
        if(null !== $model){
47
            $this->model = $model;
48
        }
49
        return $this->model;
50
    }
51
52
    protected function required(): array
53
    {
54
        return $this->required;
55
    }
56
57
}
58