Passed
Push — master ( 9c4d83...10cdd0 )
by Henri
02:24 queued 56s
created

ExtraCheck   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toNext() 0 3 2
A testArray() 0 8 2
A validateDate() 0 4 2
A check_required() 0 3 2
A check_requireds() 0 5 2
1
<?php
2
3
namespace HnrAzevedo\Validator;
4
5
Trait ExtraCheck{
6
    protected static array $data = [];
7
    protected static array $validators = [];
8
    protected static string $model = '';
9
    protected static array $required = [];
10
    protected static array $errors = [];
11
12
    protected static function check_requireds()
13
    {
14
        if(count(self::$required) > 0){
15
            self::$errors[] = [
16
                'As seguintes informações não poderam ser validadas: '.implode(', ',array_keys(self::$required)).'.'
17
            ];
18
        }
19
    }
20
21
    public static function validateDate($date, $format = 'Y-m-d H:i:s')
22
    {
23
        $d = \DateTime::createFromFormat($format, $date);
24
        return $d && $d->format($format) == $date;
25
    }
26
27
    protected static function check_required(string $param): bool
28
    {
29
        return (array_key_exists('required',self::$validators[self::$model]->getRules(self::$data['role'])[$param]) && self::$validators[self::$model]->getRules(self::$data['role'])[$param]['required']);
30
    }
31
32
    protected static function toNext(string $param, $value)
33
    {
34
        return (self::check_required($param) || strlen($value > 0));
35
    }
36
37
    protected static function testArray(string $param, $value): ?array
38
    {
39
        if(!is_array($value)){
40
            self::$errors[] = [
41
                $param => 'Era esperado um informação em array para está informação.'
42
            ];
43
        }
44
        return $value;
45
    }
46
}
47