Passed
Push — master ( 42367a...08368b )
by Sebastian
02:40
created
src/Request/Param/Validator/Numeric.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     
28 28
     protected function _validate()
29 29
     {
30
-        if(is_numeric($this->value)) {
30
+        if (is_numeric($this->value)) {
31 31
             return $this->value * 1;
32 32
         }
33 33
         
Please login to merge, or discard this patch.
src/Request/Param/Validator/Array.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     
28 28
     protected function _validate()
29 29
     {
30
-        if(is_array($this->value)) {
30
+        if (is_array($this->value)) {
31 31
             return $this->value;
32 32
         }
33 33
         
Please login to merge, or discard this patch.
src/Request/Param/Validator/Valueslist.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
     
30 30
     protected function _validate()
31 31
     {
32
-        if(!is_array($this->value)) {
32
+        if (!is_array($this->value)) {
33 33
             return array();
34 34
         }
35 35
         
36 36
         $keep = array();
37
-        foreach($this->value as $item) {
38
-            if(in_array($item, $this->getArrayOption('values'))) {
37
+        foreach ($this->value as $item) {
38
+            if (in_array($item, $this->getArrayOption('values'))) {
39 39
                 $keep[] = $item;
40 40
             }
41 41
         }
Please login to merge, or discard this patch.
src/Request/Param/Validator/Json.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,26 +29,26 @@
 block discarded – undo
29 29
     
30 30
     protected function _validate()
31 31
     {
32
-        if(!is_string($this->value)) {
32
+        if (!is_string($this->value)) {
33 33
             return '';
34 34
         }
35 35
         
36 36
         $value = trim($this->value);
37 37
         
38
-        if(empty($value)) {
38
+        if (empty($value)) {
39 39
             return '';
40 40
         }
41 41
         
42 42
         // strictly validate for objects?
43
-        if($this->getBoolOption('arrays') === false)
43
+        if ($this->getBoolOption('arrays') === false)
44 44
         {
45
-            if(is_object(json_decode($value))) {
45
+            if (is_object(json_decode($value))) {
46 46
                 return $value;
47 47
             }
48 48
         }
49 49
         else
50 50
         {
51
-            if(is_array(json_decode($value, true))) {
51
+            if (is_array(json_decode($value, true))) {
52 52
                 return $value;
53 53
             }
54 54
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,8 +45,7 @@
 block discarded – undo
45 45
             if(is_object(json_decode($value))) {
46 46
                 return $value;
47 47
             }
48
-        }
49
-        else
48
+        } else
50 49
         {
51 50
             if(is_array(json_decode($value, true))) {
52 51
                 return $value;
Please login to merge, or discard this patch.
src/Request/Param/Validator/Regex.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     
28 28
     protected function _validate()
29 29
     {
30
-        if(!is_scalar($this->value)) {
30
+        if (!is_scalar($this->value)) {
31 31
             return null;
32 32
         }
33 33
         
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
         // is a boolan, which is converted to an integer when
36 36
         // converted to string, which in turn can be validated
37 37
         // with a regex.
38
-        if(is_bool($this->value)) {
38
+        if (is_bool($this->value)) {
39 39
             return null;
40 40
         }
41 41
         
42 42
         $value = (string)$this->value;
43 43
         
44
-        if(preg_match($this->getStringOption('regex'), $value)) {
44
+        if (preg_match($this->getStringOption('regex'), $value)) {
45 45
             return $value;
46 46
         }
47 47
         
Please login to merge, or discard this patch.
src/Request/Param/Validator/Enum.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
     
30 30
     protected function _validate()
31 31
     {
32
-        if(in_array($this->value, $this->getArrayOption('values'))) {
32
+        if (in_array($this->value, $this->getArrayOption('values'))) {
33 33
             return $this->value;
34 34
         }
35 35
         
Please login to merge, or discard this patch.
src/Request/Param.php 3 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
         }
115 115
     }
116 116
     
117
-   /**
118
-    * Adds a callback as a validation method. The callback gets the
119
-    * value to validate as first parameter, and any additional 
120
-    * parameters passed here get appended to that.
121
-    * 
122
-    * The callback must return boolean true or false depending on
123
-    * whether the value is valid.
124
-    * 
125
-    * @param callable $callback
126
-    * @param array $args
127
-    * @return Request_Param
128
-    */
117
+    /**
118
+     * Adds a callback as a validation method. The callback gets the
119
+     * value to validate as first parameter, and any additional 
120
+     * parameters passed here get appended to that.
121
+     * 
122
+     * The callback must return boolean true or false depending on
123
+     * whether the value is valid.
124
+     * 
125
+     * @param callable $callback
126
+     * @param array $args
127
+     * @return Request_Param
128
+     */
129 129
     public function setCallback($callback, array $args=array()) : Request_Param
130 130
     {
131 131
         if(!is_callable($callback)) {
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
         return $value;
170 170
     }
171 171
     
172
-   /**
173
-    * Validates the specified value using the validation type. Returns
174
-    * the validated value. 
175
-    * 
176
-    * @param mixed $value
177
-    * @param string $type
178
-    * @param array $params
179
-    * @throws Request_Exception
180
-    * @return mixed
181
-    */
172
+    /**
173
+     * Validates the specified value using the validation type. Returns
174
+     * the validated value. 
175
+     * 
176
+     * @param mixed $value
177
+     * @param string $type
178
+     * @param array $params
179
+     * @throws Request_Exception
180
+     * @return mixed
181
+     */
182 182
     protected function validateType($value, string $type, array $params)
183 183
     {
184 184
         $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type);
@@ -276,13 +276,13 @@  discard block
 block discarded – undo
276 276
     
277 277
     protected $valueType = self::VALUE_TYPE_STRING;
278 278
 
279
-   /**
280
-    * Sets the variable to contain a comma-separated list of integer IDs.
281
-    * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g.
282
-    * <code>145</code>.
283
-    * 
284
-    * @return Request_Param
285
-    */
279
+    /**
280
+     * Sets the variable to contain a comma-separated list of integer IDs.
281
+     * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g.
282
+     * <code>145</code>.
283
+     * 
284
+     * @return Request_Param
285
+     */
286 286
     public function setIDList()
287 287
     {
288 288
         $this->valueType = self::VALUE_TYPE_ID_LIST;
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
         return $this;
292 292
     }
293 293
     
294
-   /**
295
-    * Sets the variable to be an alias, as defined by the
296
-    * {@link RegexHelper::REGEX_ALIAS} regular expression.
297
-    * 
298
-    * @return Request_Param
299
-    * @see RegexHelper::REGEX_ALIAS
300
-    */
294
+    /**
295
+     * Sets the variable to be an alias, as defined by the
296
+     * {@link RegexHelper::REGEX_ALIAS} regular expression.
297
+     * 
298
+     * @return Request_Param
299
+     * @see RegexHelper::REGEX_ALIAS
300
+     */
301 301
     public function setAlias()
302 302
     {
303 303
         return $this->setRegex(RegexHelper::REGEX_ALIAS);
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
         return $this->setValidation(self::VALIDATION_TYPE_ALPHA);
339 339
     }
340 340
     
341
-   /**
342
-    * Sets the parameter value as a string containing lowercase
343
-    * and/or uppercase letters, as well as numbers.
344
-    * 
345
-    * @return Request_Param
346
-    */
341
+    /**
342
+     * Sets the parameter value as a string containing lowercase
343
+     * and/or uppercase letters, as well as numbers.
344
+     * 
345
+     * @return Request_Param
346
+     */
347 347
     public function setAlnum()
348 348
     {
349 349
         return $this->setValidation(self::VALIDATION_TYPE_ALNUM);   
@@ -376,17 +376,17 @@  discard block
 block discarded – undo
376 376
         );
377 377
     }
378 378
     
379
-   /**
380
-    * Only available for array values: the parameter must be
381
-    * an array value, and the array may only contain values 
382
-    * specified in the values array.
383
-    * 
384
-    * Submitted values that are not in the allowed list of
385
-    * values are stripped from the value.
386
-    *  
387
-    * @param array $values List of allowed values
388
-    * @return \AppUtils\Request_Param
389
-    */
379
+    /**
380
+     * Only available for array values: the parameter must be
381
+     * an array value, and the array may only contain values 
382
+     * specified in the values array.
383
+     * 
384
+     * Submitted values that are not in the allowed list of
385
+     * values are stripped from the value.
386
+     *  
387
+     * @param array $values List of allowed values
388
+     * @return \AppUtils\Request_Param
389
+     */
390 390
     public function setValuesList(array $values)
391 391
     {
392 392
         $this->setArray();
@@ -404,53 +404,53 @@  discard block
 block discarded – undo
404 404
         return $this->setValidation(self::VALIDATION_TYPE_ARRAY);
405 405
     }
406 406
     
407
-   /**
408
-    * Specifies that a JSON-encoded string is expected.
409
-    * 
410
-    * NOTE: Numbers or quoted strings are technically valid
411
-    * JSON, but are not accepted, because it is assumed
412
-    * at least an array or object are expected.
413
-    * 
414
-    * @return \AppUtils\Request_Param
415
-    */
407
+    /**
408
+     * Specifies that a JSON-encoded string is expected.
409
+     * 
410
+     * NOTE: Numbers or quoted strings are technically valid
411
+     * JSON, but are not accepted, because it is assumed
412
+     * at least an array or object are expected.
413
+     * 
414
+     * @return \AppUtils\Request_Param
415
+     */
416 416
     public function setJSON() : Request_Param
417 417
     {
418 418
         return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true));
419 419
     }
420 420
     
421
-   /**
422
-    * Like {@link Request_Param::setJSON()}, but accepts
423
-    * only JSON objects. Arrays will not be accepted.
424
-    * 
425
-    * @return \AppUtils\Request_Param
426
-    */
421
+    /**
422
+     * Like {@link Request_Param::setJSON()}, but accepts
423
+     * only JSON objects. Arrays will not be accepted.
424
+     * 
425
+     * @return \AppUtils\Request_Param
426
+     */
427 427
     public function setJSONObject() : Request_Param
428 428
     {
429 429
         return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false));
430 430
     }
431 431
     
432
-   /**
433
-    * The parameter is a string boolean representation. This means
434
-    * it can be any of the following: "yes", "true", "no", "false".
435
-    * The value is automatically converted to a boolean when retrieving
436
-    * the parameter.
437
-    * 
438
-    * @return Request_Param
439
-    */
432
+    /**
433
+     * The parameter is a string boolean representation. This means
434
+     * it can be any of the following: "yes", "true", "no", "false".
435
+     * The value is automatically converted to a boolean when retrieving
436
+     * the parameter.
437
+     * 
438
+     * @return Request_Param
439
+     */
440 440
     public function setBoolean() : Request_Param
441 441
     {
442 442
         return $this->addClassFilter('Boolean');
443 443
     }
444 444
     
445
-   /**
446
-    * Validates the request parameter as an MD5 string,
447
-    * so that only values resembling md5 values are accepted.
448
-    * 
449
-    * NOTE: This can only guarantee the format, not whether
450
-    * it is an actual valid hash of something.
451
-    * 
452
-    * @return \AppUtils\Request_Param
453
-    */
445
+    /**
446
+     * Validates the request parameter as an MD5 string,
447
+     * so that only values resembling md5 values are accepted.
448
+     * 
449
+     * NOTE: This can only guarantee the format, not whether
450
+     * it is an actual valid hash of something.
451
+     * 
452
+     * @return \AppUtils\Request_Param
453
+     */
454 454
     public function setMD5() : Request_Param
455 455
     {
456 456
         return $this->setRegex(RegexHelper::REGEX_MD5);
@@ -492,14 +492,14 @@  discard block
 block discarded – undo
492 492
         return $this;
493 493
     }
494 494
     
495
-   /**
496
-    * Retrieves the value of the request parameter,
497
-    * applying all filters (if any) and validation
498
-    * (if any).
499
-    * 
500
-    * @param mixed $default
501
-    * @return mixed
502
-    */
495
+    /**
496
+     * Retrieves the value of the request parameter,
497
+     * applying all filters (if any) and validation
498
+     * (if any).
499
+     * 
500
+     * @param mixed $default
501
+     * @return mixed
502
+     */
503 503
     public function get($default=null)
504 504
     {
505 505
         $value = $this->request->getParam($this->paramName);
@@ -587,12 +587,12 @@  discard block
 block discarded – undo
587 587
         return $this;
588 588
     }
589 589
     
590
-   /**
591
-    * Adds a filter that trims whitespace from the request
592
-    * parameter using the PHP <code>trim</code> function.
593
-    * 
594
-    * @return \AppUtils\Request_Param
595
-    */
590
+    /**
591
+     * Adds a filter that trims whitespace from the request
592
+     * parameter using the PHP <code>trim</code> function.
593
+     * 
594
+     * @return \AppUtils\Request_Param
595
+     */
596 596
     public function addFilterTrim() : Request_Param
597 597
     {
598 598
         // to guarantee we only work with strings
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
         return $this->addCallbackFilter('trim');
602 602
     }
603 603
 
604
-   /**
605
-    * Converts the value to a string, even if it is not
606
-    * a string value. Complex types like arrays and objects
607
-    * are converted to an empty string.
608
-    * 
609
-    * @return \AppUtils\Request_Param
610
-    */
604
+    /**
605
+     * Converts the value to a string, even if it is not
606
+     * a string value. Complex types like arrays and objects
607
+     * are converted to an empty string.
608
+     * 
609
+     * @return \AppUtils\Request_Param
610
+     */
611 611
     public function addStringFilter() : Request_Param
612 612
     {
613 613
         return $this->addClassFilter('String');
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
         return $this->addCallbackFilter('strip_tags', array($allowedTags));
658 658
     }
659 659
     
660
-   /**
661
-    * Adds a filter that strips all whitespace from the
662
-    * request parameter, from spaces to tabs and newlines.
663
-    * 
664
-    * @return \AppUtils\Request_Param
665
-    */
660
+    /**
661
+     * Adds a filter that strips all whitespace from the
662
+     * request parameter, from spaces to tabs and newlines.
663
+     * 
664
+     * @return \AppUtils\Request_Param
665
+     */
666 666
     public function addStripWhitespaceFilter() : Request_Param
667 667
     {
668 668
         // to ensure we only work with strings.
@@ -671,14 +671,14 @@  discard block
 block discarded – undo
671 671
         return $this->addClassFilter('StripWhitespace');
672 672
     }   
673 673
     
674
-   /**
675
-    * Adds a filter that transforms comma separated values
676
-    * into an array of values.
677
-    * 
678
-    * @param bool $trimEntries Trim whitespace from each entry?
679
-    * @param bool $stripEmptyEntries Remove empty entries from the array?
680
-    * @return \AppUtils\Request_Param
681
-    */
674
+    /**
675
+     * Adds a filter that transforms comma separated values
676
+     * into an array of values.
677
+     * 
678
+     * @param bool $trimEntries Trim whitespace from each entry?
679
+     * @param bool $stripEmptyEntries Remove empty entries from the array?
680
+     * @return \AppUtils\Request_Param
681
+     */
682 682
     public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param
683 683
     {
684 684
         $this->setArray();
@@ -703,12 +703,12 @@  discard block
 block discarded – undo
703 703
         );
704 704
     }
705 705
     
706
-   /**
707
-    * Adds a filter that encodes all HTML special characters
708
-    * using the PHP <code>htmlspecialchars</code> function.
709
-    * 
710
-    * @return \AppUtils\Request_Param
711
-    */
706
+    /**
707
+     * Adds a filter that encodes all HTML special characters
708
+     * using the PHP <code>htmlspecialchars</code> function.
709
+     * 
710
+     * @return \AppUtils\Request_Param
711
+     */
712 712
     public function addHTMLSpecialcharsFilter() : Request_Param
713 713
     {
714 714
         return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8'));
@@ -721,14 +721,14 @@  discard block
 block discarded – undo
721 721
     
722 722
     protected $required = false;
723 723
     
724
-   /**
725
-    * Marks this request parameter as required. To use this feature,
726
-    * you have to call the request's {@link Request::validate()}
727
-    * method.
728
-    * 
729
-    * @return Request_Param
730
-    * @see Request::validate()
731
-    */
724
+    /**
725
+     * Marks this request parameter as required. To use this feature,
726
+     * you have to call the request's {@link Request::validate()}
727
+     * method.
728
+     * 
729
+     * @return Request_Param
730
+     * @see Request::validate()
731
+     */
732 732
     public function makeRequired() : Request_Param
733 733
     {
734 734
         $this->required = true;
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
     * @param array $args
127 127
     * @return Request_Param
128 128
     */
129
-    public function setCallback($callback, array $args=array()) : Request_Param
129
+    public function setCallback($callback, array $args = array()) : Request_Param
130 130
     {
131
-        if(!is_callable($callback)) {
131
+        if (!is_callable($callback)) {
132 132
             throw new Request_Exception(
133 133
                 'Not a valid callback',
134 134
                 'The specified callback is not a valid callable entity.',
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         
162 162
         // go through all enqueued validations in turn, each time
163 163
         // replacing the value with the adjusted, validated value.
164
-        foreach($this->validations as $validateDef) 
164
+        foreach ($this->validations as $validateDef) 
165 165
         {
166 166
             $value = $this->validateType($value, $validateDef['type'], $validateDef['params']);
167 167
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type);
185 185
         
186
-        if(!class_exists($class))
186
+        if (!class_exists($class))
187 187
         {
188 188
             throw new Request_Exception(
189 189
                 'Unknown validation type.',
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $validator = new $class($this);
200 200
         $validator->setOptions($params);
201 201
         
202
-        if($this->valueType === self::VALUE_TYPE_ID_LIST)
202
+        if ($this->valueType === self::VALUE_TYPE_ID_LIST)
203 203
         {
204 204
             $value = $this->validateType_idList($value, $validator);
205 205
         }
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
     
214 214
     protected function validateType_idList($value, Request_Param_Validator $validator) : array
215 215
     {
216
-        if(!is_array($value))
216
+        if (!is_array($value))
217 217
         {
218 218
             $value = explode(',', $value);
219 219
         }
220 220
         
221 221
         $keep = array();
222 222
         
223
-        foreach($value as $subval)
223
+        foreach ($value as $subval)
224 224
         {
225 225
             $subval = trim($subval);
226 226
             $subval = $validator->validate($subval);
227 227
             
228
-            if($subval !== null) {
228
+            if ($subval !== null) {
229 229
                 $keep[] = intval($subval);
230 230
             }
231 231
         }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     {
366 366
         $args = func_get_args(); // cannot be used as function parameter in some PHP versions
367 367
         
368
-        if(is_array($args[0])) 
368
+        if (is_array($args[0])) 
369 369
         {
370 370
             $args = $args[0];
371 371
         }
@@ -500,10 +500,10 @@  discard block
 block discarded – undo
500 500
     * @param mixed $default
501 501
     * @return mixed
502 502
     */
503
-    public function get($default=null)
503
+    public function get($default = null)
504 504
     {
505 505
         $value = $this->request->getParam($this->paramName);
506
-        if($value !== null && $value !== '') {
506
+        if ($value !== null && $value !== '') {
507 507
             return $value;
508 508
         }
509 509
 
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
     {
523 523
         $total = count($this->filters);
524 524
         for ($i = 0; $i < $total; $i++) {
525
-            $method = 'applyFilter_' . $this->filters[$i]['type'];
525
+            $method = 'applyFilter_'.$this->filters[$i]['type'];
526 526
             $value = $this->$method($value, $this->filters[$i]['params']);
527 527
         }
528 528
 
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
     * @param bool $stripEmptyEntries Remove empty entries from the array?
680 680
     * @return \AppUtils\Request_Param
681 681
     */
682
-    public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param
682
+    public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param
683 683
     {
684 684
         $this->setArray();
685 685
         
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         );
693 693
     }
694 694
     
695
-    protected function addClassFilter(string $name, array $params=array()) : Request_Param
695
+    protected function addClassFilter(string $name, array $params = array()) : Request_Param
696 696
     {
697 697
         return $this->addFilter(
698 698
             self::FILTER_TYPE_CLASS,
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -202,8 +202,7 @@
 block discarded – undo
202 202
         if($this->valueType === self::VALUE_TYPE_ID_LIST)
203 203
         {
204 204
             $value = $this->validateType_idList($value, $validator);
205
-        }
206
-        else
205
+        } else
207 206
         {
208 207
             $value = $validator->validate($value);
209 208
         }
Please login to merge, or discard this patch.