1 | <?php |
||
10 | class RuleParser |
||
11 | { |
||
12 | use JavascriptRulesTrait; |
||
13 | use RuleListTrait; |
||
14 | use UseDelegatedValidatorTrait; |
||
15 | |||
16 | /** |
||
17 | * Dummy Laravel validation rule for form requests. |
||
18 | */ |
||
19 | const FORM_REQUEST_RULE_NAME = 'ProengsoftFormRequest'; |
||
20 | |||
21 | /** |
||
22 | * Js validation rule used to validate form requests. |
||
23 | */ |
||
24 | const FORM_REQUEST_RULE = 'laravelValidationFormRequest'; |
||
25 | |||
26 | /** |
||
27 | * Rule used to validate remote requests. |
||
28 | */ |
||
29 | const REMOTE_RULE = 'laravelValidationRemote'; |
||
30 | |||
31 | /** |
||
32 | * Rule used to validate javascript fields. |
||
33 | */ |
||
34 | const JAVASCRIPT_RULE = 'laravelValidation'; |
||
35 | |||
36 | /** |
||
37 | * Token used to secure romte validations. |
||
38 | * |
||
39 | * @var null|string |
||
40 | */ |
||
41 | protected $remoteToken; |
||
42 | |||
43 | /** |
||
44 | * Conditional Validations. |
||
45 | 216 | * |
|
46 | * @var array |
||
47 | 216 | */ |
|
48 | 216 | protected $conditional = []; |
|
49 | 216 | ||
50 | /** |
||
51 | * Create a new JsValidation instance. |
||
52 | * |
||
53 | * @param \Proengsoft\JsValidation\Support\DelegatedValidator $validator |
||
54 | * @param null|string $remoteToken |
||
55 | */ |
||
56 | public function __construct(DelegatedValidator $validator, $remoteToken = null) |
||
61 | |||
62 | 72 | /** |
|
63 | 72 | * Return parsed Javascript Rule. |
|
64 | * |
||
65 | 72 | * @param string $attribute |
|
66 | 36 | * @param string $rule |
|
67 | 36 | * @param $parameters |
|
68 | * @param $rawRule |
||
69 | 36 | * @return array |
|
70 | */ |
||
71 | public function getRule($attribute, $rule, $parameters, $rawRule) |
||
88 | |||
89 | /** |
||
90 | * Gets rules from Validator instance. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | 12 | public function getValidatorRules() |
|
98 | 12 | ||
99 | 12 | /** |
|
100 | * Add conditional rules. |
||
101 | 12 | * |
|
102 | * @param mixed $attribute |
||
103 | * @param array $rules |
||
104 | * @return void |
||
105 | */ |
||
106 | public function addConditionalRules($attribute, $rules = []) |
||
114 | |||
115 | /** |
||
116 | * Determine if rule is passed with sometimes. |
||
117 | * |
||
118 | * @param mixed $attribute |
||
119 | * @param string $rule |
||
120 | * @return bool |
||
121 | */ |
||
122 | protected function isConditionalRule($attribute, $rule) |
||
127 | 36 | ||
128 | /** |
||
129 | 36 | * Returns Javascript parameters for remote validated rules. |
|
130 | 12 | * |
|
131 | * @param string $attribute |
||
132 | * @param string $rule |
||
133 | 36 | * @param $parameters |
|
134 | * @return array |
||
135 | */ |
||
136 | protected function clientRule($attribute, $rule, $parameters) |
||
147 | 36 | ||
148 | 36 | /** |
|
149 | 36 | * Returns Javascript parameters for remote validated rules. |
|
150 | * |
||
151 | * @param string $attribute |
||
152 | 36 | * @param bool $forceRemote |
|
153 | * @return array |
||
154 | */ |
||
155 | protected function remoteRule($attribute, $forceRemote) |
||
166 | |||
167 | /** |
||
168 | 48 | * Handles multidimensional attribute names. |
|
169 | * |
||
170 | * @param mixed $attribute |
||
171 | * @return string |
||
172 | */ |
||
173 | protected function getAttributeName($attribute) |
||
184 | 12 | ||
185 | 12 | /** |
|
186 | * Parse named parameters to $key => $value items. |
||
187 | * |
||
188 | * @param array $parameters |
||
189 | * @return array |
||
190 | */ |
||
191 | public function parseNamedParameters($parameters) |
||
201 | } |
||
202 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.