Passed
Branch 1.0.0-dev (4efac2)
by nguereza
04:41
created
core/libraries/FormValidation.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+     class FormValidation {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
          * @return void
99 99
          */
100 100
         public function __construct() {
101
-            $this->logger =& class_loader('Log', 'classes');
101
+            $this->logger = & class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104 104
 		   //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107
-            $this->_errorsMessages  = array(
107
+            $this->_errorsMessages = array(
108 108
                         'required'         => $obj->lang->get('fv_required'),
109 109
                         'min_length'       => $obj->lang->get('fv_min_length'),
110 110
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+			$this->enableCsrfCheck = false;
145 145
         }
146 146
 
147 147
         /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		 *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153
-        public function setData(array $data){
153
+        public function setData(array $data) {
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156 156
 			return $this;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
          * Get the form validation data
161 161
          * @return array the form validation data to be validated
162 162
          */
163
-        public function getData(){
163
+        public function getData() {
164 164
             return $this->data;
165 165
         }
166 166
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		*
170 170
 		* @return string the function name
171 171
 		*/
172
-        protected function _toCallCase($funcName, $prefix='_validate') {
172
+        protected function _toCallCase($funcName, $prefix = '_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
175 175
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
194 194
          */
195 195
         public function canDoValidation() {
196
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
196
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
197 197
         }
198 198
 
199 199
         /**
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
          * Validate the CSRF 
214 214
          * @return void 
215 215
          */
216
-        protected function validateCSRF(){
217
-            if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
216
+        protected function validateCSRF() {
217
+            if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) {
218 218
                 $this->logger->debug('Check if CSRF is enabled in configuration');
219 219
                 //first check for CSRF
220
-                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
220
+                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) {
221 221
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
222 222
                 }
223
-                else{
223
+                else {
224 224
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
225 225
                 }
226 226
             }
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
             $this->_forceFail = false;
238 238
 
239 239
             foreach ($this->getData() as $inputName => $inputVal) {
240
-    			if(is_array($this->data[$inputName])){
240
+    			if (is_array($this->data[$inputName])) {
241 241
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
242 242
     			}
243
-    			else{
243
+    			else {
244 244
     				$this->data[$inputName] = trim($this->data[$inputName]);
245 245
     			}
246 246
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         public function setRule($inputField, $inputLabel, $ruleSets) {
268 268
             $this->_rules[$inputField] = $ruleSets;
269 269
             $this->_labels[$inputField] = $inputLabel;
270
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
270
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
271 271
             return $this;
272 272
         }
273 273
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             }
432 432
             $errorOutput .= $errorsEnd;
433 433
             echo ($echo) ? $errorOutput : '';
434
-            return (! $echo) ? $errorOutput : null;
434
+            return (!$echo) ? $errorOutput : null;
435 435
         }
436 436
 
437 437
         /**
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
             /*
457 457
             //////////////// hack for regex rule that can contain "|"
458 458
             */
459
-            if(strpos($ruleString, 'regex') !== false){
459
+            if (strpos($ruleString, 'regex') !== false) {
460 460
                 $regexRule = array();
461 461
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
462 462
                 preg_match($rule, $ruleString, $regexRule);
463 463
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
464
-                 if(!empty($regexRule[0])){
464
+                 if (!empty($regexRule[0])) {
465 465
                      $ruleSets[] = $regexRule[0];
466 466
                  }
467 467
                  $ruleStringRegex = explode('|', $ruleStringTemp);
468 468
                 foreach ($ruleStringRegex as $rule) {
469 469
                     $rule = trim($rule);
470
-                    if($rule){
470
+                    if ($rule) {
471 471
                         $ruleSets[] = $rule;
472 472
                     }
473 473
                 }
474 474
                  
475 475
             }
476 476
             /***********************************/
477
-            else{
477
+            else {
478 478
                 if (strpos($ruleString, '|') !== FALSE) {
479 479
                     $ruleSets = explode('|', $ruleString);
480 480
                 } else {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
          * @return void
507 507
          */
508 508
         protected function _validateRule($inputName, $inputVal, $ruleName) {
509
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
509
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
510 510
             // Array to store args
511 511
             $ruleArgs = array();
512 512
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
                 $key = $i - 1;
552 552
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
553 553
             }
554
-            if (! array_key_exists($inputName, $this->_errors)) {
554
+            if (!array_key_exists($inputName, $this->_errors)) {
555 555
                 $this->_errors[$inputName] = $rulePhrase;
556 556
             }
557 557
         }
@@ -603,13 +603,13 @@  discard block
 block discarded – undo
603 603
          */
604 604
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
605 605
             $inputVal = $this->post($inputName);
606
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
606
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
607 607
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
608 608
                 if ($inputVal == '' && $callbackReturn == true) {
609 609
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
610 610
                 }
611 611
             } 
612
-			else if($inputVal == '') {
612
+			else if ($inputVal == '') {
613 613
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
614 614
             }
615 615
         }
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
636 636
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
637 637
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
638
-				if(! $result){
638
+				if (!$result) {
639 639
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
640 640
 				}
641 641
             }
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
                         continue;
670 670
                     }
671 671
                 } 
672
-				else{
672
+				else {
673 673
                     if ($inputVal == $doNotEqual) {
674 674
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
675 675
                         continue;
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
          */
700 700
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
701 701
             $inputVal = $this->post($inputName);
702
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
703
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
702
+            if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
703
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
704 704
                     return;
705 705
                 }
706 706
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
717 717
             $inputVal = $this->post($inputName);
718 718
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
719
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
719
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
720 720
                     return;
721 721
                 }
722 722
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
733 733
             $inputVal = $this->post($inputName);
734 734
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
735
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
735
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
736 736
                     return;
737 737
                 }
738 738
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
749 749
             $inputVal = $this->post($inputName);
750 750
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
751
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
751
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
752 752
                     return;
753 753
                 }
754 754
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
765 765
             $inputVal = $this->post($inputName);
766 766
             if ($inputVal >= $ruleArgs[1]) { 
767
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
767
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
768 768
                     return;
769 769
                 }
770 770
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
781 781
             $inputVal = $this->post($inputName);
782 782
             if ($inputVal <= $ruleArgs[1]) {
783
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
783
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
784 784
                     return;
785 785
                 }
786 786
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -795,8 +795,8 @@  discard block
 block discarded – undo
795 795
          */
796 796
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
797 797
             $inputVal = $this->post($inputName);
798
-            if (! is_numeric($inputVal)) {
799
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
798
+            if (!is_numeric($inputVal)) {
799
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
800 800
                     return;
801 801
                 }
802 802
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
813 813
             $inputVal = $this->post($inputName);
814 814
     		$obj = & get_instance();
815
-    		if(! isset($obj->database)){
815
+    		if (!isset($obj->database)) {
816 816
     			return;
817 817
     		}
818 818
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
     			          ->get();
822 822
     		$nb = $obj->database->numRows();
823 823
             if ($nb == 0) {
824
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
824
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
825 825
                     return;
826 826
                 }
827 827
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
838 838
             $inputVal = $this->post($inputName);
839 839
     		$obj = & get_instance();
840
-    		if(! isset($obj->database)){
840
+    		if (!isset($obj->database)) {
841 841
     			return;
842 842
     		}
843 843
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     			          ->get();
847 847
     		$nb = $obj->database->numRows();
848 848
             if ($nb != 0) {
849
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
849
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
850 850
                     return;
851 851
                 }
852 852
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -862,11 +862,11 @@  discard block
 block discarded – undo
862 862
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
863 863
             $inputVal = $this->post($inputName);
864 864
     		$obj = & get_instance();
865
-    		if(! isset($obj->database)){
865
+    		if (!isset($obj->database)) {
866 866
     			return;
867 867
     		}
868 868
     		$data = explode(',', $ruleArgs[1]);
869
-    		if(count($data) < 2){
869
+    		if (count($data) < 2) {
870 870
     			return;
871 871
     		}
872 872
     		list($table, $column) = explode('.', $data[0]);
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
                 		  ->get();
878 878
     		$nb = $obj->database->numRows();
879 879
             if ($nb != 0) {
880
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
880
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
881 881
                     return;
882 882
                 }
883 883
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -894,8 +894,8 @@  discard block
 block discarded – undo
894 894
             $inputVal = $this->post($inputName);
895 895
     		$list = explode(',', $ruleArgs[1]);
896 896
             $list = array_map('trim', $list);
897
-            if (! in_array($inputVal, $list)) {
898
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897
+            if (!in_array($inputVal, $list)) {
898
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
899 899
                     return;
900 900
                 }
901 901
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
912 912
             $inputVal = $this->post($inputName);
913 913
     		$regex = $ruleArgs[1];
914
-            if (! preg_match($regex, $inputVal)) {
915
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
914
+            if (!preg_match($regex, $inputVal)) {
915
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
916 916
                     return;
917 917
                 }
918 918
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             if (isset($_FILES) && is_array($_FILES)) {
258 258
                 $this->file_array = $_FILES;
259 259
             }
260
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
260
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
261 261
         }
262 262
         /**
263 263
         *    Set input.
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         */
274 274
         public function setInput($input)
275 275
         {
276
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
276
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
277 277
                 $this->input = $input;
278 278
             }
279 279
             return $this;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         */
310 310
         public function setAutoFilename()
311 311
         {
312
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
312
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
313 313
             $this->filename .= time();
314 314
             return $this;
315 315
         }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
331 331
                 // Calculate difference
332 332
                 if ($php_size < $file_size) {
333
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
333
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
334 334
                 }
335 335
                 $this->max_file_size = $file_size;
336 336
             }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
         public function setAllowedMimeTypes(array $mimes)
349 349
         {
350 350
             if (count($mimes) > 0) {
351
-                array_map(array($this , 'setAllowMimeType'), $mimes);
351
+                array_map(array($this, 'setAllowMimeType'), $mimes);
352 352
             }
353 353
             return $this;
354 354
         }
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         {
414 414
             if (!empty($name) && is_string($name)) {
415 415
                 if (array_key_exists($name, $this->mime_helping)) {
416
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
416
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
417 417
                 }
418 418
             }
419 419
             return $this;
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
         */
433 433
         public function setUploadFunction($function)
434 434
         {
435
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
436
-                if (is_callable( $function)) {
435
+            if (!empty($function) && (is_array($function) || is_string($function))) {
436
+                if (is_callable($function)) {
437 437
                     $this->upload_function = $function;
438 438
                 }
439 439
             }
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
                         $this->destination_directory = $destination_directory;
479 479
                         chdir($destination_directory);
480 480
                     }
481
-                    else{
482
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
481
+                    else {
482
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
483 483
                     }
484 484
                 }
485 485
             }
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
         public function isFilename($filename)
530 530
         {
531 531
             $filename = basename($filename);
532
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
532
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
533 533
         }
534 534
         /**
535 535
         *    Validate mime type with allowed mime types,
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
         */
572 572
         public function isDirpath($path)
573 573
         {
574
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
574
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
575 575
                 if (DIRECTORY_SEPARATOR == '/') {
576
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
576
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
577 577
                 } else {
578
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
578
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
579 579
                 }
580 580
             }
581 581
             return false;
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
         */
604 604
         public function getInfo()
605 605
         {
606
-            return (object)$this->file;
606
+            return (object) $this->file;
607 607
         }
608 608
 
609 609
 
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
          * Check if the file is uploaded
612 612
          * @return boolean
613 613
          */
614
-        public function isUploaded(){
614
+        public function isUploaded() {
615 615
             return isset($this->file_array[$this->input])
616 616
             && is_uploaded_file($this->file_array[$this->input]['tmp_name']);
617 617
         }
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
         *    @return    boolean
626 626
         *    @method    boolean    save
627 627
         */
628
-        public function save(){
628
+        public function save() {
629 629
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
630 630
                 // set original filename if not have a new name
631 631
                 if (empty($this->filename)) {
632 632
                     $this->filename = $this->file_array[$this->input]['name'];
633 633
                 }
634
-                else{
634
+                else {
635 635
                     // Replace %s for extension in filename
636 636
                     // Before: /[\w\d]*(.[\d\w]+)$/i
637 637
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -655,10 +655,10 @@  discard block
 block discarded – undo
655 655
                 $this->file['filename']     = $this->filename;
656 656
                 $this->file['error']        = $this->file_array[$this->input]['error'];
657 657
 
658
-                $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
658
+                $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
659 659
 
660 660
                 $error = $this->uploadHasError();
661
-                if($error){
661
+                if ($error) {
662 662
                     return false;
663 663
                 }
664 664
                 // Execute input callback
@@ -692,10 +692,10 @@  discard block
 block discarded – undo
692 692
         */
693 693
         public function sizeFormat($size, $precision = 2)
694 694
         {
695
-            if($size > 0){
695
+            if ($size > 0) {
696 696
                 $base       = log($size) / log(1024);
697 697
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
698
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
698
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
699 699
             }
700 700
             return null;
701 701
         }
@@ -719,14 +719,14 @@  discard block
 block discarded – undo
719 719
             if (array_key_exists('unit', $matches)) {
720 720
                 $unit = strtoupper($matches['unit']);
721 721
             }
722
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
722
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
723 723
         }
724 724
 
725 725
         /**
726 726
          * Get the upload error message
727 727
          * @return string
728 728
          */
729
-        public function getError(){
729
+        public function getError() {
730 730
             return $this->error;
731 731
         }
732 732
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
          * Set the upload error message
735 735
          * @param string $message the upload error message to set
736 736
          */
737
-        public function setError($message){
737
+        public function setError($message) {
738 738
             $this->logger->info('The file upload got error : ' . $message);
739 739
             $this->error = $message;
740 740
         }
@@ -744,9 +744,9 @@  discard block
 block discarded – undo
744 744
          * @param string $type the type of callback "input" or "output"
745 745
          * @return void 
746 746
          */
747
-        protected function runCallback($type){
748
-            if (!empty( $this->callbacks[$type])) {
749
-                call_user_func($this->callbacks[$type], (object)$this->file);
747
+        protected function runCallback($type) {
748
+            if (!empty($this->callbacks[$type])) {
749
+                call_user_func($this->callbacks[$type], (object) $this->file);
750 750
             }
751 751
         }
752 752
 
@@ -754,21 +754,21 @@  discard block
 block discarded – undo
754 754
          * Check if file upload has error
755 755
          * @return boolean
756 756
          */
757
-        protected function uploadHasError(){
757
+        protected function uploadHasError() {
758 758
             //check if file upload is  allowed in the configuration
759
-            if(! ini_get('file_uploads')){
759
+            if (!ini_get('file_uploads')) {
760 760
                 $this->setError($this->error_messages['file_uploads']);
761 761
                 return true;
762 762
             }
763 763
 
764 764
              //check for php upload error
765
-            if(is_numeric($this->file['error']) && $this->file['error'] > 0){
765
+            if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
766 766
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
767 767
                 return true;
768 768
             }
769 769
             
770 770
             //check for mime type
771
-            if (! $this->checkMimeType($this->file['mime'])) {
771
+            if (!$this->checkMimeType($this->file['mime'])) {
772 772
                 $this->setError($this->error_messages['accept_file_types']);
773 773
                 return true;
774 774
             }
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
          * @param  int $code the error code
793 793
          * @return string the error message
794 794
          */
795
-        private function getPhpUploadErrorMessageByCode($code){
795
+        private function getPhpUploadErrorMessageByCode($code) {
796 796
             $codeMessageMaps = array(
797 797
                 1 => $this->error_messages['upload_err_ini_size'],
798 798
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.