GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 621b1f...f1df5c )
by cao
03:48
created

Validator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 70
ccs 15
cts 17
cp 0.8824
rs 10
c 1
b 0
f 0
wmc 7
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasRule() 0 4 1
A rule() 0 19 6
1
<?php
2
namespace PhpBoot\Validator;
3
use PhpBoot\Annotation\EntityContainerBuilder;
4
use PhpBoot\Utils\TypeHint;
5
6
7
/**
8
 * Validator
9
 *
10
 * ** usage: **
11
 *  $v = new Validator();
12
 *  $v->rule('required|integer|in:1,2,3', 'fieldName');
13
 *
14
 * ** rules: **
15
 *
16
 * required - Required field
17
 * equals - Field must match another field (email/password confirmation)
18
 * different - Field must be different than another field
19
 * accepted - Checkbox or Radio must be accepted (yes, on, 1, true)
20
 * numeric - Must be numeric
21
 * integer - Must be integer number
22
 * boolean - Must be boolean
23
 * array - Must be array
24
 * length - String must be certain length
25
 * lengthBetween - String must be between given lengths
26
 * lengthMin - String must be greater than given length
27
 * lengthMax - String must be less than given length
28
 * min - Minimum
29
 * max - Maximum
30
 * in - Performs in_array check on given array values
31
 * notIn - Negation of in rule (not in array of values)
32
 * ip - Valid IP address
33
 * email - Valid email address
34
 * url - Valid URL
35
 * urlActive - Valid URL with active DNS record
36
 * alpha - Alphabetic characters only
37
 * alphaNum - Alphabetic and numeric characters only
38
 * slug - URL slug characters (a-z, 0-9, -, _)
39
 * regex - Field matches given regex pattern
40
 * date - Field is a valid date
41
 * dateFormat - Field is a valid date in the given format
42
 * dateBefore - Field is a valid date and is before the given date
43
 * dateAfter - Field is a valid date and is after the given date
44
 * contains - Field is a string and contains the given string
45
 * creditCard - Field is a valid credit card number
46
 * instanceOf - Field contains an instance of the given class
47
 * optional - Value does not need to be included in data array. If it is however, it must pass validation.
48
 */
49
class Validator extends \Valitron\Validator
50
{
51
    /**
52
     * @param callable|string $rule
53
     * @param array|string $fields
54
     * @return $this
55
     */
56 11
    public function rule($rule, $fields)
57
    {
58 11
        if(is_string($rule)){
59 11
            $rules = explode('|', $rule);
60 11
            foreach ($rules as $r){
61 11
                $params = explode(':', trim($r));
62 11
                $rule = $params[0];
63 11
                $params = isset($params[1])?explode(',', $params[1]):[];
64 11
                if($rule == 'in' || $rule == 'notIn'){
65 1
                    $params = [$params];
66 1
                }
67 11
                call_user_func_array([$this, 'parent::rule'], array_merge([$rule, $fields], $params));
68
69 11
            }
70 11
            return $this;
71
        }
72
        parent::rule($rule, $fields);
73
        return $this;
74
    }
75 11
    public function hasRule($name, $field)
76
    {
77 11
        return parent::hasRule($name, $field);
78
    }
79
80
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
//     * Validate that a field matches a specified type
82
//     *
83
//     * @param  string $field
84
//     * @param  mixed  $value
85
//     * @param  array  $params
86
//     * @internal param array $fields
87
//     * @return bool
88
//     */
89
//    protected function validateType($field, $value, $params)
90
//    {
91
//        $type = $params[0];
92
//        if(TypeHint::isArray($type)){
93
//            $type = TypeHint::getArrayType($type);
94
//            if(!$this->validateArray($field, $value)){
95
//                return false;
96
//            }
97
//            foreach ($value as $k=>$v){
98
//                if(!$this->validateType($field.'.'.$k, $v, [$type])){
99
//                    return false;
100
//                }
101
//            }
102
//            return true;
103
//        }
104
//        if(TypeHint::isScalarType($type)){
105
//            if($type == 'mixed'){
106
//                return true;
107
//            }else{
108
//                return call_user_func("is_$type", $value);
109
//            }
110
//        }else{
111
//            //TODO class validate
112
//            $metas = new EntityContainerBuilder($type);
113
//            $metas = $metas->getPropertyMetas();
114
//
115
//        }
116
//    }
117
118
}