8
8
* Class AbstractValidator
9
9
* @package Prettus\Validator
10
10
*/
11
- abstract class AbstractValidator implements ValidatorInterface {
12
-
11
+ abstract class AbstractValidator implements ValidatorInterface
12
+ {
13
13
/**
14
14
* @var int
15
15
*/
@@ -64,7 +64,8 @@ abstract class AbstractValidator implements ValidatorInterface {
64
64
* @param $id
65
65
* @return $this
66
66
*/
67
- public function setId ($ id ){
67
+ public function setId ($ id )
68
+ {
68
69
$ this ->id = $ id ;
69
70
return $ this ;
70
71
}
@@ -108,7 +109,7 @@ public function errorsBag()
108
109
* @param string $action
109
110
* @return boolean
110
111
*/
111
- abstract public function passes ( $ action = null );
112
+ abstract public function passes ($ action = null );
112
113
113
114
/**
114
115
* Pass the data and the rules to the validator or throws ValidatorException
@@ -119,8 +120,8 @@ abstract public function passes( $action = null );
119
120
*/
120
121
public function passesOrFail ($ action = null )
121
122
{
122
- if ( !$ this ->passes ($ action ) ) {
123
- throw new ValidatorException ( $ this ->errorsBag () );
123
+ if ( !$ this ->passes ($ action )) {
124
+ throw new ValidatorException ($ this ->errorsBag ());
124
125
}
125
126
126
127
return true ;
@@ -134,11 +135,11 @@ public function passesOrFail($action = null)
134
135
* @param null $action
135
136
* @return array
136
137
*/
137
- public function getRules ($ action = null ){
138
-
138
+ public function getRules ($ action = null )
139
+ {
139
140
$ rules = $ this ->rules ;
140
141
141
- if ( isset ($ this ->rules [$ action ]) ) {
142
+ if ( isset ($ this ->rules [$ action ])) {
142
143
$ rules = $ this ->rules [$ action ];
143
144
}
144
145
@@ -162,14 +163,15 @@ public function setRules(array $rules)
162
163
*
163
164
* @return array
164
165
*/
165
- public function getMessages (){
166
-
166
+ public function getMessages ()
167
+ {
167
168
return $ this ->messages ;
168
169
}
169
170
170
171
/**
171
172
* Set Custom error messages for Validation
172
173
*
174
+ * @param array $messages
173
175
* @return $this
174
176
*/
175
177
public function setMessages (array $ messages )
@@ -183,14 +185,15 @@ public function setMessages(array $messages)
183
185
*
184
186
* @return array
185
187
*/
186
- public function getAttributes (){
187
-
188
+ public function getAttributes ()
189
+ {
188
190
return $ this ->attributes ;
189
191
}
190
192
191
193
/**
192
194
* Set Custom error attributes for Validation
193
195
*
196
+ * @param array $attributes
194
197
* @return $this
195
198
*/
196
199
public function setAttributes (array $ attributes )
@@ -208,33 +211,28 @@ public function setAttributes(array $attributes)
208
211
*/
209
212
protected function parserValidationRules ($ rules , $ id = null )
210
213
{
211
-
212
- if ($ id === null )
213
- {
214
+ if (null === $ id ) {
214
215
return $ rules ;
215
216
}
216
217
217
- array_walk ($ rules , function (&$ rules , $ field ) use ($ id )
218
- {
219
- if (!is_array ($ rules ))
220
- {
218
+ array_walk ($ rules , function (&$ rules , $ field ) use ($ id ) {
219
+ if (!is_array ($ rules )) {
221
220
$ rules = explode ("| " , $ rules );
222
221
}
223
222
224
- foreach ($ rules as $ ruleIdx => $ rule )
225
- {
223
+ foreach ($ rules as $ ruleIdx => $ rule ) {
226
224
// get name and parameters
227
225
@list ($ name , $ params ) = array_pad (explode (": " , $ rule ), 2 , null );
228
226
229
227
// only do someting for the unique rule
230
- if (strtolower ($ name ) != "unique " ) {
228
+ if (strtolower ($ name ) != "unique " ) {
231
229
continue ; // continue in foreach loop, nothing left to do here
232
230
}
233
231
234
232
$ p = array_map ("trim " , explode (", " , $ params ));
235
233
236
234
// set field name to rules key ($field) (laravel convention)
237
- if (!isset ($ p [1 ])) {
235
+ if (!isset ($ p [1 ])) {
238
236
$ p [1 ] = $ field ;
239
237
}
240
238
@@ -248,5 +246,4 @@ protected function parserValidationRules($rules, $id = null)
248
246
249
247
return $ rules ;
250
248
}
251
-
252
- }
249
+ }
0 commit comments