1 | <?php |
||
15 | class Sanitizer |
||
16 | { |
||
17 | /** @var array */ |
||
18 | protected $data; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $rules; |
||
22 | |||
23 | /** @var array */ |
||
24 | protected $filters = [ |
||
25 | 'capitalize' => Filters\Capitalize::class, |
||
26 | 'cast' => Filters\Cast::class, |
||
27 | 'escape' => Filters\EscapeHTML::class, |
||
28 | 'format_date' => Filters\FormatDate::class, |
||
29 | 'lowercase' => Filters\Lowercase::class, |
||
30 | 'uppercase' => Filters\Uppercase::class, |
||
31 | 'trim' => Filters\Trim::class, |
||
32 | 'strip_tags' => Filters\StripTags::class, |
||
33 | 'digit' => Filters\Digit::class, |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Create a new sanitizer instance. |
||
38 | * |
||
39 | * @param array $data |
||
40 | * @param array $rules Rules to be applied to each data attribute |
||
41 | * @param array $filters Available filters for this sanitizer |
||
|
|||
42 | */ |
||
43 | public function __construct(array $data, array $rules, array $customFilters = []) |
||
49 | |||
50 | /** |
||
51 | * Parse a rules array. |
||
52 | * |
||
53 | * @param array $rules |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | protected function parseRulesArray(array $rules) |
||
73 | |||
74 | /** |
||
75 | * Parse a rule string formatted as filterName:option1, option2 into an array formatted as [name => filterName, options => [option1, option2]] |
||
76 | * |
||
77 | * @param string $rule Formatted as 'filterName:option1, option2' or just 'filterName' |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | protected function parseRuleString($rule) |
||
97 | |||
98 | /** |
||
99 | * Apply the given filter by its name |
||
100 | * |
||
101 | * @param mixed $name |
||
102 | * |
||
103 | * @return Filter |
||
104 | */ |
||
105 | protected function applyFilter($name, $value, $options = []) |
||
122 | |||
123 | /** |
||
124 | * Sanitize the given data |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | public function sanitize() |
||
144 | |||
145 | /** |
||
146 | * Sanitize the given attribute |
||
147 | * |
||
148 | * @param string $attribute Attribute name |
||
149 | * @param mixed $value Attribute value |
||
150 | * |
||
151 | * @return mixed Sanitized value |
||
152 | */ |
||
153 | protected function sanitizeAttribute($attribute, $value) |
||
163 | } |
||
164 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.