1 | <?php |
||
14 | class Sanitizer |
||
15 | { |
||
16 | /** @var array */ |
||
17 | protected $data; |
||
18 | |||
19 | /** @var array */ |
||
20 | protected $rules; |
||
21 | |||
22 | /** @var array */ |
||
23 | protected $filters = [ |
||
24 | 'capitalize' => \Waavi\Sanitizer\Filters\Capitalize::class, |
||
25 | 'cast' => \Waavi\Sanitizer\Filters\Cast::class, |
||
26 | 'escape' => \Waavi\Sanitizer\Filters\EscapeHTML::class, |
||
27 | 'format_date' => \Waavi\Sanitizer\Filters\FormatDate::class, |
||
28 | 'lowercase' => \Waavi\Sanitizer\Filters\Lowercase::class, |
||
29 | 'uppercase' => \Waavi\Sanitizer\Filters\Uppercase::class, |
||
30 | 'trim' => \Waavi\Sanitizer\Filters\Trim::class, |
||
31 | 'strip_tags' => \Waavi\Sanitizer\Filters\StripTags::class, |
||
32 | 'digit' => \Waavi\Sanitizer\Filters\Digit::class, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Create a new sanitizer instance. |
||
37 | * |
||
38 | * @param array $data |
||
39 | * @param array $rules Rules to be applied to each data attribute |
||
40 | * @param array $filters Available filters for this sanitizer |
||
|
|||
41 | */ |
||
42 | public function __construct(array $data, array $rules, array $customFilters = []) |
||
48 | |||
49 | /** |
||
50 | * Parse a rules array. |
||
51 | * |
||
52 | * @param array $rules |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | protected function parseRulesArray(array $rules) |
||
70 | |||
71 | /** |
||
72 | * Parse a rule string formatted as filterName:option1, option2 into an array formatted as [name => filterName, options => [option1, option2]] |
||
73 | * |
||
74 | * @param string $rule Formatted as 'filterName:option1, option2' or just 'filterName' |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | protected function parseRuleString($rule) |
||
92 | |||
93 | /** |
||
94 | * Apply the given filter by its name |
||
95 | * |
||
96 | * @param mixed $name |
||
97 | * |
||
98 | * @return Filter |
||
99 | */ |
||
100 | protected function applyFilter($name, $value, $options = []) |
||
114 | |||
115 | /** |
||
116 | * Sanitize the given data |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | public function sanitize() |
||
134 | |||
135 | /** |
||
136 | * Sanitize the given attribute |
||
137 | * |
||
138 | * @param string $attribute Attribute name |
||
139 | * @param mixed $value Attribute value |
||
140 | * |
||
141 | * @return mixed Sanitized value |
||
142 | */ |
||
143 | protected function sanitizeAttribute($attribute, $value) |
||
152 | } |
||
153 |
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.