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' => Filters\Capitalize::class, |
||
25 | 'cast' => Filters\Cast::class, |
||
26 | 'escape' => Filters\EscapeHTML::class, |
||
27 | 'format_date' => Filters\FormatDate::class, |
||
28 | 'lowercase' => Filters\Lowercase::class, |
||
29 | 'uppercase' => Filters\Uppercase::class, |
||
30 | 'trim' => Filters\Trim::class, |
||
31 | 'strip_tags' => Filters\StripTags::class, |
||
32 | 'digit' => 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) |
||
72 | |||
73 | /** |
||
74 | * Parse a rule string formatted as filterName:option1, option2 into an array formatted as [name => filterName, options => [option1, option2]]. |
||
75 | * |
||
76 | * @param string $rule Formatted as 'filterName:option1, option2' or just 'filterName' |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | protected function parseRuleString($rule) |
||
96 | |||
97 | /** |
||
98 | * Apply the given filter by its name. |
||
99 | * |
||
100 | * @param mixed $name |
||
101 | * |
||
102 | * @return Filter |
||
103 | */ |
||
104 | protected function applyFilter($name, $value, $options = []) |
||
121 | |||
122 | /** |
||
123 | * Sanitize the given data. |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | public function sanitize() |
||
143 | |||
144 | /** |
||
145 | * Sanitize the given attribute. |
||
146 | * |
||
147 | * @param string $attribute Attribute name |
||
148 | * @param mixed $value Attribute value |
||
149 | * |
||
150 | * @return mixed Sanitized value |
||
151 | */ |
||
152 | protected function sanitizeAttribute($attribute, $value) |
||
162 | } |
||
163 |
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.