Passed
Push — master ( ca6d4f...b18142 )
by Henri
01:15
created

Helper   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 45
rs 10
c 1
b 0
f 0
wmc 10

5 Methods

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