1 | <?php |
||
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) |
|
79 | |||
80 | // /** |
||
|
|||
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 | } |
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.