Passed
Push — 1.0.0-dev ( 3d5bea...407604 )
by nguereza
02:34
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.
core/classes/database/DatabaseQueryResult.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26 26
   
27
-  class DatabaseQueryResult{
27
+  class DatabaseQueryResult {
28 28
   	
29 29
   	/**
30 30
   	 * The database query result
31 31
   	 * @var mixed
32 32
   	 */
33
-     private $result  = null;
33
+     private $result = null;
34 34
   	
35 35
     
36 36
   	/**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param mixed $result the query result
46 46
      * @param int $numRows the number of rows returned by the query
47 47
      */
48
-    public function __construct($result = null, $numRows = 0){
48
+    public function __construct($result = null, $numRows = 0) {
49 49
         $this->result = $result;
50 50
         $this->numRows = $numRows;
51 51
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return mixed
58 58
      */
59
-    public function getResult(){
59
+    public function getResult() {
60 60
       return $this->result;
61 61
     }
62 62
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *
67 67
 	 * @return object DatabaseQueryResult
68 68
      */
69
-    public function setResult($result){
69
+    public function setResult($result) {
70 70
       $this->result = $result;
71 71
       return $this;
72 72
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return int
78 78
      */
79
-    public function getNumRows(){
79
+    public function getNumRows() {
80 80
       return $this->numRows;
81 81
     }
82 82
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
 	 * @return object DatabaseQueryResult
88 88
      */
89
-    public function setNumRows($numRows){
89
+    public function setNumRows($numRows) {
90 90
       $this->numRows = $numRows;
91 91
       return $this;
92 92
     }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryBuilder.php 1 patch
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryBuilder{
26
+  class DatabaseQueryBuilder {
27 27
   	/**
28 28
   	 * The SQL SELECT statment
29 29
   	 * @var string
30 30
   	*/
31
-  	private $select              = '*';
31
+  	private $select = '*';
32 32
   	
33 33
   	/**
34 34
   	 * The SQL FROM statment
35 35
   	 * @var string
36 36
   	*/
37
-      private $from              = null;
37
+      private $from = null;
38 38
   	
39 39
   	/**
40 40
   	 * The SQL WHERE statment
41 41
   	 * @var string
42 42
   	*/
43
-      private $where               = null;
43
+      private $where = null;
44 44
   	
45 45
   	/**
46 46
   	 * The SQL LIMIT statment
47 47
   	 * @var string
48 48
   	*/
49
-      private $limit               = null;
49
+      private $limit = null;
50 50
   	
51 51
   	/**
52 52
   	 * The SQL JOIN statment
53 53
   	 * @var string
54 54
   	*/
55
-      private $join                = null;
55
+      private $join = null;
56 56
   	
57 57
   	/**
58 58
   	 * The SQL ORDER BY statment
59 59
   	 * @var string
60 60
   	*/
61
-      private $orderBy             = null;
61
+      private $orderBy = null;
62 62
   	
63 63
   	/**
64 64
   	 * The SQL GROUP BY statment
65 65
   	 * @var string
66 66
   	*/
67
-      private $groupBy             = null;
67
+      private $groupBy = null;
68 68
   	
69 69
   	/**
70 70
   	 * The SQL HAVING statment
71 71
   	 * @var string
72 72
   	*/
73
-      private $having              = null;
73
+      private $having = null;
74 74
   	
75 75
   	/**
76 76
   	 * The full SQL query statment after build for each command
77 77
   	 * @var string
78 78
   	*/
79
-      private $query               = null;
79
+      private $query = null;
80 80
   	
81 81
   	/**
82 82
   	 * The list of SQL valid operators
83 83
   	 * @var array
84 84
   	*/
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
85
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
86 86
   	
87 87
 	
88 88
 	/**
89 89
 	 * The prefix used in each database table
90 90
 	 * @var string
91 91
 	*/
92
-    private $prefix              = null;
92
+    private $prefix = null;
93 93
     
94 94
 
95 95
     /**
96 96
   	 * The PDO instance
97 97
   	 * @var object
98 98
   	*/
99
-    private $pdo                 = null;
99
+    private $pdo = null;
100 100
 	
101 101
   	/**
102 102
   	 * The database driver name used
103 103
   	 * @var string
104 104
   	*/
105
-  	private $driver              = null;
105
+  	private $driver = null;
106 106
   	
107 107
 	
108 108
     /**
109 109
      * Construct new DatabaseQueryBuilder
110 110
      * @param object $pdo the PDO object
111 111
      */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
112
+    public function __construct(PDO $pdo = null) {
113
+        if (is_object($pdo)) {
114 114
           $this->setPdo($pdo);
115 115
         }
116 116
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
      * @param  string|array $table the table name or array of table list
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123
-    public function from($table){
124
-	  if (is_array($table)){
123
+    public function from($table) {
124
+	  if (is_array($table)) {
125 125
         $froms = '';
126
-        foreach($table as $key){
126
+        foreach ($table as $key) {
127 127
           $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  string|array $fields the field name or array of field list
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141
-    public function select($fields){
141
+    public function select($fields) {
142 142
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143 143
       $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144 144
       return $this;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param  string $field the field name to distinct
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152
-    public function distinct($field){
152
+    public function distinct($field) {
153 153
       $distinct = ' DISTINCT ' . $field;
154 154
       $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155 155
       return $this;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * @param  string $name  if is not null represent the alias used for this field in the result
162 162
      * @return object        the current DatabaseQueryBuilder instance
163 163
      */
164
-    public function count($field = '*', $name = null){
164
+    public function count($field = '*', $name = null) {
165 165
       return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param  string $name  if is not null represent the alias used for this field in the result
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174
-    public function min($field, $name = null){
174
+    public function min($field, $name = null) {
175 175
       return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param  string $name  if is not null represent the alias used for this field in the result
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184
-    public function max($field, $name = null){
184
+    public function max($field, $name = null) {
185 185
       return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param  string $name  if is not null represent the alias used for this field in the result
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194
-    public function sum($field, $name = null){
194
+    public function sum($field, $name = null) {
195 195
       return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param  string $name  if is not null represent the alias used for this field in the result
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204
-    public function avg($field, $name = null){
204
+    public function avg($field, $name = null) {
205 205
       return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
       $on = $field1;
220 220
       $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+      if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
       }
226
-      if (empty($this->join)){
226
+      if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228 228
       }
229
-      else{
229
+      else {
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 231
       }
232 232
       return $this;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      * @see  DatabaseQueryBuilder::join()
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
240
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
241 241
       return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @see  DatabaseQueryBuilder::join()
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
249
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
250 250
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
251 251
 	}
252 252
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
258
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
259 259
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @see  DatabaseQueryBuilder::join()
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
267
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
268 268
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * @see  DatabaseQueryBuilder::join()
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
276
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
277 277
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      * @see  DatabaseQueryBuilder::join()
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
285
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
286 286
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295
-    public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
297
-        foreach($field as $f){
295
+    public function whereIsNull($field, $andOr = 'AND') {
296
+      if (is_array($field)) {
297
+        foreach ($field as $f) {
298 298
         	$this->whereIsNull($f, $andOr);
299 299
         }
300 300
       } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
301
+          $this->setWhereStr($field . ' IS NULL ', $andOr);
302 302
       }
303 303
       return $this;
304 304
     }
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312
-    public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
314
-        foreach($field as $f){
312
+    public function whereIsNotNull($field, $andOr = 'AND') {
313
+      if (is_array($field)) {
314
+        foreach ($field as $f) {
315 315
           $this->whereIsNotNull($f, $andOr);
316 316
         }
317 317
       } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
318
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
319 319
       }
320 320
       return $this;
321 321
     }
@@ -330,13 +330,13 @@  discard block
 block discarded – undo
330 330
      * @param  boolean $escape whether to escape or not the $val
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
333
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
334 334
       $whereStr = '';
335
-      if (is_array($where)){
335
+      if (is_array($where)) {
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337 337
       }
338
-      else{
339
-        if (is_array($op)){
338
+      else {
339
+        if (is_array($op)) {
340 340
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342 342
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @see  DatabaseQueryBuilder::where()
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354
-    public function orWhere($where, $op = null, $val = null, $escape = true){
354
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
355 355
       return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * @see  DatabaseQueryBuilder::where()
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364
-    public function notWhere($where, $op = null, $val = null, $escape = true){
364
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
365 365
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      * @see  DatabaseQueryBuilder::where()
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
373
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
374 374
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383
-    public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
383
+    public function groupStart($type = '', $andOr = ' AND') {
384
+      if (empty($this->where)) {
385 385
         $this->where = $type . ' (';
386 386
       } else {
387
-          if (substr(trim($this->where), -1) == '('){
387
+          if (substr(trim($this->where), -1) == '(') {
388 388
             $this->where .= $type . ' (';
389 389
           } else {
390 390
           	$this->where .= $andOr . ' ' . $type . ' (';
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * @see  DatabaseQueryBuilder::groupStart()
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401
-    public function notGroupStart(){
401
+    public function notGroupStart() {
402 402
       return $this->groupStart('NOT');
403 403
     }
404 404
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      * @see  DatabaseQueryBuilder::groupStart()
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410
-    public function orGroupStart(){
410
+    public function orGroupStart() {
411 411
       return $this->groupStart('', ' OR');
412 412
     }
413 413
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @see  DatabaseQueryBuilder::groupStart()
417 417
      * @return object        the current DatabaseQueryBuilder instance
418 418
      */
419
-    public function orNotGroupStart(){
419
+    public function orNotGroupStart() {
420 420
       return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * Close the parenthesis for the grouped SQL
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427
-    public function groupEnd(){
427
+    public function groupEnd() {
428 428
       $this->where .= ')';
429 429
       return $this;
430 430
     }
@@ -438,10 +438,10 @@  discard block
 block discarded – undo
438 438
      * @param  boolean $escape whether to escape or not the values
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
441
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
442 442
       $_keys = array();
443
-      foreach ($keys as $k => $v){
444
-        if (is_null($v)){
443
+      foreach ($keys as $k => $v) {
444
+        if (is_null($v)) {
445 445
           $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      * @see  DatabaseQueryBuilder::in()
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460
-    public function notIn($field, array $keys, $escape = true){
460
+    public function notIn($field, array $keys, $escape = true) {
461 461
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  DatabaseQueryBuilder::in()
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469
-    public function orIn($field, array $keys, $escape = true){
469
+    public function orIn($field, array $keys, $escape = true) {
470 470
       return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @see  DatabaseQueryBuilder::in()
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478
-    public function orNotIn($field, array $keys, $escape = true){
478
+    public function orNotIn($field, array $keys, $escape = true) {
479 479
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
      * @param  boolean $escape whether to escape or not the values
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
492
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
493
+      if (is_null($value1)) {
494 494
         $value1 = '';
495 495
       }
496
-      if (is_null($value2)){
496
+      if (is_null($value2)) {
497 497
         $value2 = '';
498 498
       }
499 499
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @see  DatabaseQueryBuilder::between()
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509
-    public function notBetween($field, $value1, $value2, $escape = true){
509
+    public function notBetween($field, $value1, $value2, $escape = true) {
510 510
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  DatabaseQueryBuilder::between()
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518
-    public function orBetween($field, $value1, $value2, $escape = true){
518
+    public function orBetween($field, $value1, $value2, $escape = true) {
519 519
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  DatabaseQueryBuilder::between()
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527
-    public function orNotBetween($field, $value1, $value2, $escape = true){
527
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
528 528
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
      * @param  boolean $escape whether to escape or not the values
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
540
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
541
+      if (empty($data)) {
542 542
         $data = '';
543 543
       }
544 544
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
      * @see  DatabaseQueryBuilder::like()
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553
-    public function orLike($field, $data, $escape = true){
553
+    public function orLike($field, $data, $escape = true) {
554 554
       return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      * @see  DatabaseQueryBuilder::like()
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562
-    public function notLike($field, $data, $escape = true){
562
+    public function notLike($field, $data, $escape = true) {
563 563
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
      * @see  DatabaseQueryBuilder::like()
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571
-    public function orNotLike($field, $data, $escape = true){
571
+    public function orNotLike($field, $data, $escape = true) {
572 572
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
      * @param  int $limitEnd the limit count
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582
-    public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
582
+    public function limit($limit, $limitEnd = null) {
583
+      if (empty($limit)) {
584 584
         $limit = 0;
585 585
       }
586
-      if (! is_null($limitEnd)){
586
+      if (!is_null($limitEnd)) {
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588 588
       }
589
-      else{
589
+      else {
590 590
         $this->limit = $limit;
591 591
       }
592 592
       return $this;
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
      * @param  string $orderDir the order direction (ASC or DESC)
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601
-    public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
601
+    public function orderBy($orderBy, $orderDir = ' ASC') {
602
+      if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604 604
       }
605
-      else{
605
+      else {
606 606
         $this->orderBy = empty($this->orderBy) 
607 607
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 608
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
      * @param  string|array $field the field name used or array of field list
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618
-    public function groupBy($field){
619
-      if (is_array($field)){
618
+    public function groupBy($field) {
619
+      if (is_array($field)) {
620 620
         $this->groupBy = implode(', ', $field);
621 621
       }
622
-      else{
622
+      else {
623 623
         $this->groupBy = $field;
624 624
       }
625 625
       return $this;
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
      * @param  boolean $escape whether to escape or not the values
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636
-    public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
636
+    public function having($field, $op = null, $val = null, $escape = true) {
637
+      if (is_array($op)) {
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639 639
       }
640
-      else if (! in_array($op, $this->operatorList)){
641
-        if (is_null($op)){
640
+      else if (!in_array($op, $this->operatorList)) {
641
+        if (is_null($op)) {
642 642
           $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645 645
       }
646
-      else{
647
-        if (is_null($val)){
646
+      else {
647
+        if (is_null($val)) {
648 648
           $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      * @param  boolean $escape  whether to escape or not the values
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661
-    public function insert($data = array(), $escape = true){
661
+    public function insert($data = array(), $escape = true) {
662 662
       $columns = array_keys($data);
663 663
       $column = implode(', ', $columns);
664 664
       $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
      * @param  boolean $escape  whether to escape or not the values
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676
-    public function update($data = array(), $escape = true){
676
+    public function update($data = array(), $escape = true) {
677 677
       $query = 'UPDATE ' . $this->from . ' SET ';
678 678
       $values = array();
679
-      foreach ($data as $column => $val){
679
+      foreach ($data as $column => $val) {
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681 681
       }
682 682
       $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
683
+      if (!empty($this->where)) {
684 684
         $query .= ' WHERE ' . $this->where;
685 685
       }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+      if (!empty($this->orderBy)) {
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689 689
       }
690 690
 
691
-      if (! empty($this->limit)){
691
+      if (!empty($this->limit)) {
692 692
         $query .= ' LIMIT ' . $this->limit;
693 693
       }
694 694
       $this->query = $query;
@@ -699,22 +699,22 @@  discard block
 block discarded – undo
699 699
      * Delete the record in database
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702
-    public function delete(){
702
+    public function delete() {
703 703
     	$query = 'DELETE FROM ' . $this->from;
704 704
       $isTruncate = $query;
705
-    	if (! empty($this->where)){
705
+    	if (!empty($this->where)) {
706 706
   		  $query .= ' WHERE ' . $this->where;
707 707
     	}
708 708
 
709
-    	if (! empty($this->orderBy)){
709
+    	if (!empty($this->orderBy)) {
710 710
     	  $query .= ' ORDER BY ' . $this->orderBy;
711 711
       }
712 712
 
713
-    	if (! empty($this->limit)){
713
+    	if (!empty($this->limit)) {
714 714
     		$query .= ' LIMIT ' . $this->limit;
715 715
       }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
717
+  		if ($isTruncate == $query && $this->driver != 'sqlite') {  
718 718
       	$query = 'TRUNCATE TABLE ' . $this->from;
719 719
   		}
720 720
 	   $this->query = $query;
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
      * @param boolean $escaped whether we can do escape of not 
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730
-    public function escape($data, $escaped = true){
730
+    public function escape($data, $escaped = true) {
731 731
       return $escaped 
732 732
                     ? $this->getPdo()->quote(trim($data)) 
733 733
                     : $data; 
@@ -738,31 +738,31 @@  discard block
 block discarded – undo
738 738
      * Return the current SQL query string
739 739
      * @return string
740 740
      */
741
-    public function getQuery(){
741
+    public function getQuery() {
742 742
   	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
743
-  	  if(empty($this->query)){
743
+  	  if (empty($this->query)) {
744 744
   		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
745
-  		  if (! empty($this->join)){
745
+  		  if (!empty($this->join)) {
746 746
           $query .= $this->join;
747 747
   		  }
748 748
   		  
749
-  		  if (! empty($this->where)){
749
+  		  if (!empty($this->where)) {
750 750
           $query .= ' WHERE ' . $this->where;
751 751
   		  }
752 752
 
753
-  		  if (! empty($this->groupBy)){
753
+  		  if (!empty($this->groupBy)) {
754 754
           $query .= ' GROUP BY ' . $this->groupBy;
755 755
   		  }
756 756
 
757
-  		  if (! empty($this->having)){
757
+  		  if (!empty($this->having)) {
758 758
           $query .= ' HAVING ' . $this->having;
759 759
   		  }
760 760
 
761
-  		  if (! empty($this->orderBy)){
761
+  		  if (!empty($this->orderBy)) {
762 762
   			  $query .= ' ORDER BY ' . $this->orderBy;
763 763
   		  }
764 764
 
765
-  		  if (! empty($this->limit)){
765
+  		  if (!empty($this->limit)) {
766 766
           $query .= ' LIMIT ' . $this->limit;
767 767
   		  }
768 768
   		  $this->query = $query;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      * Return the PDO instance
776 776
      * @return object
777 777
      */
778
-    public function getPdo(){
778
+    public function getPdo() {
779 779
       return $this->pdo;
780 780
     }
781 781
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
      * @param PDO $pdo the pdo object
785 785
 	   * @return object DatabaseQueryBuilder
786 786
      */
787
-    public function setPdo(PDO $pdo = null){
787
+    public function setPdo(PDO $pdo = null) {
788 788
       $this->pdo = $pdo;
789 789
       return $this;
790 790
     }
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
    * Return the database table prefix
794 794
    * @return string
795 795
    */
796
-    public function getPrefix(){
796
+    public function getPrefix() {
797 797
       return $this->prefix;
798 798
     }
799 799
 
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
      * @param string $prefix the new prefix
803 803
 	   * @return object DatabaseQueryBuilder
804 804
      */
805
-    public function setPrefix($prefix){
805
+    public function setPrefix($prefix) {
806 806
       $this->prefix = $prefix;
807 807
       return $this;
808 808
     }
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
      * Return the database driver
812 812
      * @return string
813 813
      */
814
-    public function getDriver(){
814
+    public function getDriver() {
815 815
       return $this->driver;
816 816
     }
817 817
 
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
      * @param string $driver the new driver
821 821
 	   * @return object DatabaseQueryBuilder
822 822
      */
823
-    public function setDriver($driver){
823
+    public function setDriver($driver) {
824 824
       $this->driver = $driver;
825 825
       return $this;
826 826
     }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
      * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
830 830
 	   * @return object  the current DatabaseQueryBuilder instance 
831 831
      */
832
-    public function reset(){
832
+    public function reset() {
833 833
       $this->select   = '*';
834 834
       $this->from     = null;
835 835
       $this->where    = null;
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
      *
849 849
      * @return string
850 850
      */
851
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
851
+    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) {
852 852
         $x = explode('?', $field);
853 853
         $w = '';
854
-        foreach($x as $k => $v){
855
-  	      if (!empty($v)){
856
-            if (! isset($op[$k])){
854
+        foreach ($x as $k => $v) {
855
+  	      if (!empty($v)) {
856
+            if (!isset($op[$k])) {
857 857
               $op[$k] = '';
858 858
             }
859 859
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -869,15 +869,15 @@  discard block
 block discarded – undo
869 869
      *
870 870
      * @return string
871 871
      */
872
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
872
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
873 873
       $_where = array();
874
-      foreach ($where as $column => $data){
875
-        if (is_null($data)){
874
+      foreach ($where as $column => $data) {
875
+        if (is_null($data)) {
876 876
           $data = '';
877 877
         }
878 878
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
879 879
       }
880
-      $where = implode(' '.$andOr.' ', $_where);
880
+      $where = implode(' ' . $andOr . ' ', $_where);
881 881
       return $where;
882 882
     }
883 883
 
@@ -887,12 +887,12 @@  discard block
 block discarded – undo
887 887
      *
888 888
      * @return string
889 889
      */
890
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
890
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
891 891
      $x = explode('?', $where);
892 892
      $w = '';
893
-      foreach($x as $k => $v){
894
-        if (! empty($v)){
895
-            if (isset($op[$k]) && is_null($op[$k])){
893
+      foreach ($x as $k => $v) {
894
+        if (!empty($v)) {
895
+            if (isset($op[$k]) && is_null($op[$k])) {
896 896
               $op[$k] = '';
897 897
             }
898 898
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -907,15 +907,15 @@  discard block
 block discarded – undo
907 907
      *
908 908
      * @return string
909 909
      */
910
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
910
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
911 911
        $w = '';
912
-       if (! in_array((string)$op, $this->operatorList)){
913
-          if (is_null($op)){
912
+       if (!in_array((string) $op, $this->operatorList)) {
913
+          if (is_null($op)) {
914 914
             $op = '';
915 915
           }
916 916
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917 917
         } else {
918
-          if (is_null($val)){
918
+          if (is_null($val)) {
919 919
             $val = '';
920 920
           }
921 921
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -928,14 +928,14 @@  discard block
 block discarded – undo
928 928
        * @param string $whereStr the WHERE clause string
929 929
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
930 930
        */
931
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
932
-        if (empty($this->where)){
931
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
932
+        if (empty($this->where)) {
933 933
           $this->where = $whereStr;
934 934
         } else {
935
-          if (substr(trim($this->where), -1) == '('){
935
+          if (substr(trim($this->where), -1) == '(') {
936 936
             $this->where = $this->where . ' ' . $whereStr;
937 937
           } else {
938
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
938
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
939 939
           }
940 940
         }
941 941
       }
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
      * @see  DatabaseQueryBuilder::avg
952 952
      * @return object
953 953
      */
954
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
954
+    protected function select_min_max_sum_count_avg($clause, $field, $name = null) {
955 955
       $clause = strtoupper($clause);
956 956
       $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
957 957
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class FileCache implements CacheInterface{
27
+	class FileCache implements CacheInterface {
28 28
 		
29 29
 		/**
30 30
 		 * Whether to enable compression of the cache data file.
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 		private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
42
+		public function __construct(Log $logger = null) {
43
+			if (!$this->isSupported()) {
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47 47
 	         * instance of the Log class
48 48
 	         */
49
-	        if(is_object($logger)){
49
+	        if (is_object($logger)) {
50 50
 	          $this->logger = $logger;
51 51
 	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
52
+	        else {
53
+	            $this->logger = & class_loader('Log', 'classes');
54 54
 	            $this->logger->setLogger('Library::FileCache');
55 55
 	        }
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
58
+			if (!extension_loaded('zlib')) {
59 59
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60 60
 				$this->compressCacheData = false;
61 61
 			}
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 		 * @param  string $key the key to identify the cache data
67 67
 		 * @return mixed      the cache data if exists else return false
68 68
 		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
69
+		public function get($key) {
70
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
71 71
 			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
72
+			if (!file_exists($filePath)) {
73
+				$this->logger->info('No cache file found for the key [' . $key . '], return false');
74 74
 				return false;
75 75
 			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
76
+			$this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
77
+			$handle = fopen($filePath, 'r');
78
+			if (!is_resource($handle)) {
79
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		    $data = file_get_contents($filePath);
85 85
       		fclose($handle);
86 86
       		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
87
+      		if (!$data) {
88
+      			$this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
89 89
 		         // If unserializing somehow didn't work out, we'll delete the file
90 90
 		         unlink($filePath);
91 91
 		         return false;
92 92
 	      	}
93 93
 	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
94
+	      		$this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
95 95
 		        // Unlinking when the file was expired
96 96
 		        unlink($filePath);
97 97
 		        return false;
98 98
 		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
99
+		     else {
100
+		     	$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 101
 		     	return $data['data'];
102 102
 		     }
103 103
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $ttl  the cache life time
111 111
 		 * @return boolean true if success otherwise will return false
112 112
 		 */
113
-		public function set($key, $data, $ttl = 0){
113
+		public function set($key, $data, $ttl = 0) {
114 114
 			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
115
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116 116
 			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
117
+			$handle = fopen($filePath, 'w');
118
+			if (!is_resource($handle)) {
119
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
120 120
 				return false;
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 									)
130 130
 								);		   
131 131
 		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
132
+		    if (!$result) {
133
+		    	$this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
134 134
 		    	fclose($handle);
135 135
 		    	return false;
136 136
 		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
137
+		    else {
138
+		    	$this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
139 139
 		    	fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 		 * @return boolean      true if the cache is delete, false if can't delete 
150 150
 		 * the cache or the cache with the given key not exist
151 151
 		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
152
+		public function delete($key) {
153
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
154 154
 			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
155
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
156
+			if (!file_exists($filePath)) {
157 157
 				$this->logger->info('This cache file does not exists skipping');
158 158
 				return false;
159 159
 			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
160
+			else {
161
+				$this->logger->info('Found cache file [' . $filePath . '] remove it');
162 162
 	      		unlink($filePath);
163 163
 				return true;
164 164
 			}
@@ -172,25 +172,25 @@  discard block
 block discarded – undo
172 172
 		 * 'expire' => expiration time of the cache (Unix timestamp),
173 173
 		 * 'ttl' => the time to live of the cache in second
174 174
 		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
175
+		public function getInfo($key) {
176
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
177 177
 			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
178
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
179
+			if (!file_exists($filePath)) {
180 180
 				$this->logger->info('This cache file does not exists skipping');
181 181
 				return false;
182 182
 			}
183
-			else{
184
-				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
183
+			else {
184
+				$this->logger->info('Found cache file [' . $filePath . '] check the validity');
185 185
 	      		$data = file_get_contents($filePath);
186 186
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
187
-				if(! $data){
187
+				if (!$data) {
188 188
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
189 189
 					return false;
190 190
 				}
191
-				else{
191
+				else {
192 192
 					$this->logger->info('This cache data is OK check for expire');
193
-					if(isset($data['expire']) && $data['expire'] > time()){
193
+					if (isset($data['expire']) && $data['expire'] > time()) {
194 194
 						$this->logger->info('This cache not yet expired return cache informations');
195 195
 						$info = array(
196 196
 							'mtime' => $data['mtime'],
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 							);
200 200
 						return $info;
201 201
 					}
202
-					else{
202
+					else {
203 203
 						$this->logger->info('This cache already expired return false');
204 204
 						return false;
205 205
 					}
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
 		/**
212 212
 		 * Used to delete expired cache data
213 213
 		 */
214
-		public function deleteExpiredCache(){
214
+		public function deleteExpiredCache() {
215 215
 			$this->logger->debug('Deleting of expired cache files');
216 216
 			$list = glob(CACHE_PATH . '*.cache');
217
-			if(! $list){
217
+			if (!$list) {
218 218
 				$this->logger->info('No cache files were found skipping');
219 219
 			}
220
-			else{
220
+			else {
221 221
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
222 222
 				foreach ($list as $file) {
223 223
 					$this->logger->debug('Processing the cache file [' . $file . ']');
224 224
 					$data = file_get_contents($file);
225 225
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
-		      		if(! $data){
226
+		      		if (!$data) {
227 227
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228 228
 		      		}
229
-		      		else if(time() > $data['expire']){
229
+		      		else if (time() > $data['expire']) {
230 230
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231 231
 		      			unlink($file);
232 232
 		      		}
233
-		      		else{
233
+		      		else {
234 234
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235 235
 		      		}
236 236
 				}
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 		/**
241 241
 		 * Remove all file from cache folder
242 242
 		 */
243
-		public function clean(){
243
+		public function clean() {
244 244
 			$this->logger->debug('Deleting of all cache files');
245 245
 			$list = glob(CACHE_PATH . '*.cache');
246
-			if(! $list){
246
+			if (!$list) {
247 247
 				$this->logger->info('No cache files were found skipping');
248 248
 			}
249
-			else{
249
+			else {
250 250
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
251 251
 				foreach ($list as $file) {
252 252
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	    /**
259 259
 	     * @return boolean
260 260
 	     */
261
-	    public function isCompressCacheData(){
261
+	    public function isCompressCacheData() {
262 262
 	        return $this->compressCacheData;
263 263
 	    }
264 264
 
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 	     *
268 268
 	     * @return object
269 269
 	     */
270
-	    public function setCompressCacheData($status = true){
270
+	    public function setCompressCacheData($status = true) {
271 271
 			//if Zlib extension is not loaded set compressCacheData to false
272
-			if($status === true && ! extension_loaded('zlib')){
272
+			if ($status === true && !extension_loaded('zlib')) {
273 273
 				
274 274
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
275 275
 				$this->compressCacheData = false;
276 276
 			}
277
-			else{
277
+			else {
278 278
 				$this->compressCacheData = $status;
279 279
 			}
280 280
 			return $this;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		 *
286 286
 		 * @return bool
287 287
 		 */
288
-		public function isSupported(){
288
+		public function isSupported() {
289 289
 			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
290 290
 		}
291 291
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 	     * Return the Log instance
294 294
 	     * @return object
295 295
 	     */
296
-	    public function getLogger(){
296
+	    public function getLogger() {
297 297
 	      return $this->logger;
298 298
 	    }
299 299
 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	     * Set the log instance
302 302
 	     * @param Log $logger the log object
303 303
 	     */
304
-	    public function setLogger(Log $logger){
304
+	    public function setLogger(Log $logger) {
305 305
 	      $this->logger = $logger;
306 306
 	      return $this;
307 307
 	    }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 		* @param string $key the cache item key
313 313
 		* @return string the full cache file path for this key
314 314
 		*/
315
-		private function getFilePath($key){
315
+		private function getFilePath($key) {
316 316
 			return CACHE_PATH . md5($key) . '.cache';
317 317
 		}
318 318
 	}
Please login to merge, or discard this patch.
core/classes/Router.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 		/**
93 93
 		 * Construct the new Router instance
94 94
 		 */
95
-		public function __construct(){
95
+		public function __construct() {
96 96
 			$this->setLoggerFromParamOrCreateNewInstance(null);
97 97
 			
98 98
 			//loading routes for module
99 99
 			$moduleRouteList = array();
100 100
 			$modulesRoutes = Module::getModulesRoutes();
101
-			if($modulesRoutes && is_array($modulesRoutes)){
101
+			if ($modulesRoutes && is_array($modulesRoutes)) {
102 102
 				$moduleRouteList = $modulesRoutes;
103 103
 				unset($modulesRoutes);
104 104
 			}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		*/
118 118
 		public function add($uri, $callback) {
119 119
 			$uri = trim($uri, $this->uriTrim);
120
-			if(in_array($uri, $this->pattern)){
120
+			if (in_array($uri, $this->pattern)) {
121 121
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
122 122
 			}
123 123
 			$this->pattern[] = $uri;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * Get the module name
129 129
 		 * @return string
130 130
 		 */
131
-		public function getModule(){
131
+		public function getModule() {
132 132
 			return $this->module;
133 133
 		}
134 134
 		
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		 * Get the controller name
137 137
 		 * @return string
138 138
 		 */
139
-		public function getController(){
139
+		public function getController() {
140 140
 			return $this->controller;
141 141
 		}
142 142
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		 * Get the controller file path
145 145
 		 * @return string
146 146
 		 */
147
-		public function getControllerPath(){
147
+		public function getControllerPath() {
148 148
 			return $this->controllerPath;
149 149
 		}
150 150
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 		 * Get the controller method
153 153
 		 * @return string
154 154
 		 */
155
-		public function getMethod(){
155
+		public function getMethod() {
156 156
 			return $this->method;
157 157
 		}
158 158
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * Get the request arguments
161 161
 		 * @return array
162 162
 		 */
163
-		public function getArgs(){
163
+		public function getArgs() {
164 164
 			return $this->args;
165 165
 		}
166 166
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		 * Get the URL segments array
169 169
 		 * @return array
170 170
 		 */
171
-		public function getSegments(){
171
+		public function getSegments() {
172 172
 			return $this->segments;
173 173
 		}
174 174
 
@@ -177,27 +177,27 @@  discard block
 block discarded – undo
177 177
 		 * otherwise send 404 error.
178 178
 		 */
179 179
 		public function run() {
180
-			$benchmark =& class_loader('Benchmark');
180
+			$benchmark = & class_loader('Benchmark');
181 181
 			$benchmark->mark('ROUTING_PROCESS_START');
182 182
 			$this->logger->debug('Routing process start ...');
183 183
 			$segment = $this->segments;
184 184
 			$baseUrl = get_config('base_url');
185 185
 			//check if the app is not in DOCUMENT_ROOT
186
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){
186
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) {
187 187
 				array_shift($segment);
188 188
 				$this->segments = $segment;
189 189
 			}
190 190
 			$this->logger->debug('Check if the request URI contains the front controller');
191
-			if(isset($segment[0]) && $segment[0] == SELF){
191
+			if (isset($segment[0]) && $segment[0] == SELF) {
192 192
 				$this->logger->info('The request URI contains the front controller');
193 193
 				array_shift($segment);
194 194
 				$this->segments = $segment;
195 195
 			}
196
-			else{
196
+			else {
197 197
 				$this->logger->info('The request URI does not contain the front controller');
198 198
 			}
199 199
 			$uri = implode('/', $segment);
200
-			$this->logger->info('The final Request URI is [' . $uri . ']' );
200
+			$this->logger->info('The final Request URI is [' . $uri . ']');
201 201
 			//generic routes
202 202
 			$pattern = array(':num', ':alpha', ':alnum', ':any');
203 203
 			$replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*');
@@ -211,20 +211,20 @@  discard block
 block discarded – undo
211 211
 					array_shift($args);
212 212
 					//check if this contains an module
213 213
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
214
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
215
-						$this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']');
214
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
215
+						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
216 216
 						$this->module = $moduleControllerMethod[0];
217 217
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
218 218
 					}
219
-					else{
219
+					else {
220 220
 						$this->logger->info('The current request does not use the module');
221 221
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
222 222
 					}
223
-					if(is_array($moduleControllerMethod)){
224
-						if(isset($moduleControllerMethod[0])){
223
+					if (is_array($moduleControllerMethod)) {
224
+						if (isset($moduleControllerMethod[0])) {
225 225
 							$this->controller = $moduleControllerMethod[0];	
226 226
 						}
227
-						if(isset($moduleControllerMethod[1])){
227
+						if (isset($moduleControllerMethod[1])) {
228 228
 							$this->method = $moduleControllerMethod[1];
229 229
 						}
230 230
 						$this->args = $args;
@@ -234,73 +234,73 @@  discard block
 block discarded – undo
234 234
 				}
235 235
 			}
236 236
 			//first if the controller is not set and the module is set use the module name as the controller
237
-			if(! $this->getController() && $this->getModule()){
237
+			if (!$this->getController() && $this->getModule()) {
238 238
 				$this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller');
239 239
 				$this->controller = $this->getModule();
240 240
 			}
241 241
 			//if can not determine the module/controller/method via the defined routes configuration we will use
242 242
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
243
-			if(! $this->getController()){
243
+			if (!$this->getController()) {
244 244
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
245 245
 				$nbSegment = count($segment);
246 246
 				//if segment is null so means no need to perform
247
-				if($nbSegment > 0){
247
+				if ($nbSegment > 0) {
248 248
 					//get the module list
249 249
 					$modules = Module::getModuleList();
250 250
 					//first check if no module
251
-					if(! $modules){
251
+					if (!$modules) {
252 252
 						$this->logger->info('No module was loaded will skip the module checking');
253 253
 						//the application don't use module
254 254
 						//controller
255
-						if(isset($segment[0])){
255
+						if (isset($segment[0])) {
256 256
 							$this->controller = $segment[0];
257 257
 							array_shift($segment);
258 258
 						}
259 259
 						//method
260
-						if(isset($segment[0])){
260
+						if (isset($segment[0])) {
261 261
 							$this->method = $segment[0];
262 262
 							array_shift($segment);
263 263
 						}
264 264
 						//args
265 265
 						$this->args = $segment;
266 266
 					}
267
-					else{
267
+					else {
268 268
 						$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
269
-						if(in_array($segment[0], $modules)){
269
+						if (in_array($segment[0], $modules)) {
270 270
 							$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
271 271
 							$this->module = $segment[0];
272 272
 							array_shift($segment);
273 273
 							//check if the second arg is the controller from module
274
-							if(isset($segment[0])){
274
+							if (isset($segment[0])) {
275 275
 								$this->controller = $segment[0];
276 276
 								//check if the request use the same module name and controller
277 277
 								$path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
278
-								if(! $path){
278
+								if (!$path) {
279 279
 									$this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller');
280 280
 									$this->controller = $this->getModule();
281 281
 								}
282
-								else{
282
+								else {
283 283
 									$this->controllerPath = $path;
284 284
 									array_shift($segment);
285 285
 								}
286 286
 							}
287 287
 							//check for method
288
-							if(isset($segment[0])){
288
+							if (isset($segment[0])) {
289 289
 								$this->method = $segment[0];
290 290
 								array_shift($segment);
291 291
 							}
292 292
 							//the remaining is for args
293 293
 							$this->args = $segment;
294 294
 						}
295
-						else{
295
+						else {
296 296
 							$this->logger->info('The current request information is not found in the module list');
297 297
 							//controller
298
-							if(isset($segment[0])){
298
+							if (isset($segment[0])) {
299 299
 								$this->controller = $segment[0];
300 300
 								array_shift($segment);
301 301
 							}
302 302
 							//method
303
-							if(isset($segment[0])){
303
+							if (isset($segment[0])) {
304 304
 								$this->method = $segment[0];
305 305
 								array_shift($segment);
306 306
 							}
@@ -310,18 +310,18 @@  discard block
 block discarded – undo
310 310
 					}
311 311
 				}
312 312
 			}
313
-			if(! $this->getController() && $this->getModule()){
313
+			if (!$this->getController() && $this->getModule()) {
314 314
 				$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
315 315
 				$this->controller = $this->getModule();
316 316
 			}
317 317
 			//did we set the controller, so set the controller path
318
-			if($this->getController() && ! $this->getControllerPath()){
318
+			if ($this->getController() && !$this->getControllerPath()) {
319 319
 				$this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']');
320 320
 				//if it is the module controller
321
-				if($this->getModule()){
321
+				if ($this->getModule()) {
322 322
 					$this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
323 323
 				}
324
-				else{
324
+				else {
325 325
 					$this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php';
326 326
 				}
327 327
 			}
@@ -331,20 +331,20 @@  discard block
 block discarded – undo
331 331
 			$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
332 332
 			$benchmark->mark('ROUTING_PROCESS_END');
333 333
 			$e404 = false;
334
-			if(file_exists($classFilePath)){
334
+			if (file_exists($classFilePath)) {
335 335
 				require_once $classFilePath;
336
-				if(! class_exists($controller, false)){
336
+				if (!class_exists($controller, false)) {
337 337
 					$e404 = true;
338
-					$this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
338
+					$this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
339 339
 				}
340
-				else{
340
+				else {
341 341
 					$controllerInstance = new $controller();
342 342
 					$controllerMethod = $this->getMethod();
343
-					if(! method_exists($controllerInstance, $controllerMethod)){
343
+					if (!method_exists($controllerInstance, $controllerMethod)) {
344 344
 						$e404 = true;
345 345
 						$this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
346 346
 					}
347
-					else{
347
+					else {
348 348
 						$this->logger->info('Routing data is set correctly now GO!');
349 349
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs());
350 350
 						$obj = & get_instance();
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 					}
355 355
 				}
356 356
 			}
357
-			else{
357
+			else {
358 358
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
359 359
 				$e404 = true;
360 360
 			}
361
-			if($e404){
362
-				$response =& class_loader('Response', 'classes');
361
+			if ($e404) {
362
+				$response = & class_loader('Response', 'classes');
363 363
 				$response->send404();
364 364
 			}
365 365
 		}
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * Return the Log instance
369 369
      * @return Log
370 370
      */
371
-    public function getLogger(){
371
+    public function getLogger() {
372 372
       return $this->logger;
373 373
     }
374 374
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * @param Log $logger the log object
378 378
 	 * @return object
379 379
      */
380
-    public function setLogger($logger){
380
+    public function setLogger($logger) {
381 381
       $this->logger = $logger;
382 382
       return $this;
383 383
     }
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
     * @param boolean $useConfigFile whether to use route configuration file
389 389
 	* @return object
390 390
     */
391
-    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
391
+    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
392 392
         $route = array();
393
-        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
393
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')) {
394 394
             require_once CONFIG_PATH . 'routes.php';
395 395
         }
396 396
         $route = array_merge($route, $overwriteConfig);
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
     /**
402 402
      * Set the route paramaters using the configuration
403 403
      */
404
-    protected function setRouteParams(){
404
+    protected function setRouteParams() {
405 405
     	//adding route
406
-		foreach($this->routes as $pattern => $callback){
406
+		foreach ($this->routes as $pattern => $callback) {
407 407
 			$this->add($pattern, $callback);
408 408
 		}
409 409
 		
@@ -413,10 +413,10 @@  discard block
 block discarded – undo
413 413
 		//remove url suffix from the request URI
414 414
 		$suffix = get_config('url_suffix');
415 415
 		if ($suffix) {
416
-			$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
416
+			$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
417 417
 			$uri = str_ireplace($suffix, '', $uri);
418 418
 		} 
419
-		if (strpos($uri, '?') !== false){
419
+		if (strpos($uri, '?') !== false) {
420 420
 			$uri = substr($uri, 0, strpos($uri, '?'));
421 421
 		}
422 422
 		$uri = trim($uri, $this->uriTrim);
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
      * Set the Log instance using argument or create new instance
428 428
      * @param object $logger the Log instance if not null
429 429
      */
430
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
431
-      if ($logger !== null){
430
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
431
+      if ($logger !== null) {
432 432
         $this->logger = $logger;
433 433
       }
434
-      else{
435
-          $this->logger =& class_loader('Log', 'classes');
434
+      else {
435
+          $this->logger = & class_loader('Log', 'classes');
436 436
           $this->logger->setLogger('Library::Router');
437 437
       }
438 438
     }
Please login to merge, or discard this patch.
core/classes/Log.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Log{
27
+	class Log {
28 28
 		
29 29
 		/**
30 30
 		 * The defined constante for Log level
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		/**
53 53
 		 * Create new Log instance
54 54
 		 */
55
-		public function __construct(){
55
+		public function __construct() {
56 56
 		}
57 57
 
58 58
 		/**
59 59
 		 * Set the logger to identify each message in the log
60 60
 		 * @param string $logger the logger name
61 61
 		 */
62
-		public  function setLogger($logger){
62
+		public  function setLogger($logger) {
63 63
 			$this->logger = $logger;
64 64
 		}
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 * @see Log::writeLog for more detail
69 69
 		 * @param  string $message the log message to save
70 70
 		 */
71
-		public function fatal($message){
71
+		public function fatal($message) {
72 72
 			$this->writeLog($message, self::FATAL);
73 73
 		} 
74 74
 		
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		 * @see Log::writeLog for more detail
78 78
 		 * @param  string $message the log message to save
79 79
 		 */
80
-		public function error($message){
80
+		public function error($message) {
81 81
 			$this->writeLog($message, self::ERROR);
82 82
 		} 
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		 * @see Log::writeLog for more detail
87 87
 		 * @param  string $message the log message to save
88 88
 		 */
89
-		public function warning($message){
89
+		public function warning($message) {
90 90
 			$this->writeLog($message, self::WARNING);
91 91
 		} 
92 92
 		
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * @see Log::writeLog for more detail
96 96
 		 * @param  string $message the log message to save
97 97
 		 */
98
-		public function info($message){
98
+		public function info($message) {
99 99
 			$this->writeLog($message, self::INFO);
100 100
 		} 
101 101
 		
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @see Log::writeLog for more detail
105 105
 		 * @param  string $message the log message to save
106 106
 		 */
107
-		public function debug($message){
107
+		public function debug($message) {
108 108
 			$this->writeLog($message, self::DEBUG);
109 109
 		} 
110 110
 		
@@ -115,54 +115,54 @@  discard block
 block discarded – undo
115 115
 		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116 116
 		 * to allow check the log level threshold.
117 117
 		 */
118
-		public function writeLog($message, $level = self::INFO){
118
+		public function writeLog($message, $level = self::INFO) {
119 119
 			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
120
+			if (!$configLogLevel) {
121 121
 				//so means no need log just stop here
122 122
 				return;
123 123
 			}
124 124
 			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
125
+			if (!self::isValidConfigLevel($configLogLevel)) {
126 126
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
127 127
 				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128 128
 			}
129 129
 			
130 130
 			//check if config log_logger_name is set
131
-			if($this->logger){
131
+			if ($this->logger) {
132 132
 				$configLoggersName = get_config('log_logger_name', array());
133 133
 				if (!empty($configLoggersName)) {
134 134
 					//for best comparaison put all string to lowercase
135 135
 					$configLoggersName = array_map('strtolower', $configLoggersName);
136
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
136
+					if (!in_array(strtolower($this->logger), $configLoggersName)) {
137 137
 						return;
138 138
 					}
139 139
 				}
140 140
 			}
141 141
 			
142 142
 			//if $level is not an integer
143
-			if(! is_numeric($level)){
143
+			if (!is_numeric($level)) {
144 144
 				$level = self::getLevelValue($level);
145 145
 			}
146 146
 			
147 147
 			//check if can logging regarding the log level config
148 148
 			$configLevel = self::getLevelValue($configLogLevel);
149
-			if($configLevel > $level){
149
+			if ($configLevel > $level) {
150 150
 				//can't log
151 151
 				return;
152 152
 			}
153 153
 			
154 154
 			$logSavePath = get_config('log_save_path');
155
-			if(! $logSavePath){
155
+			if (!$logSavePath) {
156 156
 				$logSavePath = LOGS_PATH;
157 157
 			}
158 158
 			
159
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
159
+			if (!is_dir($logSavePath) || !is_writable($logSavePath)) {
160 160
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
161 161
 				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
162 162
 			}
163 163
 			
164 164
 			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
165
-			if(! file_exists($path)){
165
+			if (!file_exists($path)) {
166 166
 				touch($path);
167 167
 			}
168 168
 			//may be at this time helper user_agent not yet included
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			
185 185
 			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
186 186
 			$fp = fopen($path, 'a+');
187
-			if(is_resource($fp)){
187
+			if (is_resource($fp)) {
188 188
 				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
189 189
 				fwrite($fp, $str);
190 190
 				fclose($fp);
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		 *
199 199
 		 * @return boolean        true if the given log level is valid, false if not
200 200
 		 */
201
-		private static function isValidConfigLevel($level){
201
+		private static function isValidConfigLevel($level) {
202 202
 			$level = strtolower($level);
203 203
 			return in_array($level, self::$validConfigLevel);
204 204
 		}
@@ -208,27 +208,27 @@  discard block
 block discarded – undo
208 208
 		 * @param  string $level the log level in string format
209 209
 		 * @return int        the log level in integer format using the predefinied constants
210 210
 		 */
211
-		private static function getLevelValue($level){
211
+		private static function getLevelValue($level) {
212 212
 			$level = strtolower($level);
213 213
 			$value = self::NONE;
214 214
 			
215 215
 			//the default value is NONE, so means no need test for NONE
216
-			if($level == 'fatal'){
216
+			if ($level == 'fatal') {
217 217
 				$value = self::FATAL;
218 218
 			}
219
-			else if($level == 'error'){
219
+			else if ($level == 'error') {
220 220
 				$value = self::ERROR;
221 221
 			}
222
-			else if($level == 'warning' || $level == 'warn'){
222
+			else if ($level == 'warning' || $level == 'warn') {
223 223
 				$value = self::WARNING;
224 224
 			}
225
-			else if($level == 'info'){
225
+			else if ($level == 'info') {
226 226
 				$value = self::INFO;
227 227
 			}
228
-			else if($level == 'debug'){
228
+			else if ($level == 'debug') {
229 229
 				$value = self::DEBUG;
230 230
 			}
231
-			else if($level == 'all'){
231
+			else if ($level == 'all') {
232 232
 				$value = self::ALL;
233 233
 			}
234 234
 			return $value;
@@ -239,23 +239,23 @@  discard block
 block discarded – undo
239 239
 		 * @param  integer $level the log level in integer format
240 240
 		 * @return string        the log level in string format
241 241
 		 */
242
-		private static function getLevelName($level){
242
+		private static function getLevelName($level) {
243 243
 			$value = '';
244 244
 			
245 245
 			//the default value is NONE, so means no need test for NONE
246
-			if($level == self::FATAL){
246
+			if ($level == self::FATAL) {
247 247
 				$value = 'FATAL';
248 248
 			}
249
-			else if($level == self::ERROR){
249
+			else if ($level == self::ERROR) {
250 250
 				$value = 'ERROR';
251 251
 			}
252
-			else if($level == self::WARNING){
252
+			else if ($level == self::WARNING) {
253 253
 				$value = 'WARNING';
254 254
 			}
255
-			else if($level == self::INFO){
255
+			else if ($level == self::INFO) {
256 256
 				$value = 'INFO';
257 257
 			}
258
-			else if($level == self::DEBUG){
258
+			else if ($level == self::DEBUG) {
259 259
 				$value = 'DEBUG';
260 260
 			}
261 261
 			//no need for ALL
Please login to merge, or discard this patch.
core/classes/Loader.php 1 patch
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes/database', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,34 +332,34 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354 354
 			$config = array();
355
-			if(file_exists($configFilePath)){
355
+			if (file_exists($configFilePath)) {
356 356
 				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
357
+				if (!empty($config) && is_array($config)) {
358 358
 					Config::setAll($config);
359 359
 				}
360 360
 			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
361
+			else {
362
+				show_error('Unable to find config file [' . $configFilePath . ']');
363 363
 			}
364 364
 			static::$loaded['config_' . $filename] = $configFilePath;
365 365
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 		 *
376 376
 		 * @return void
377 377
 		 */
378
-		public static function lang($language){
378
+		public static function lang($language) {
379 379
 			$logger = static::getLogger();
380 380
 			$language = str_ireplace('.php', '', $language);
381 381
 			$language = trim($language, '/\\');
382 382
 			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
383
+			$file = 'lang_' . $language . '.php';
384 384
 			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
385
+			if (isset(static::$loaded['lang_' . $language])) {
386 386
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387 387
 				return;
388 388
 			}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			$cfgKey = get_config('language_cookie_name');
393 393
 			$objCookie = & class_loader('Cookie');
394 394
 			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
395
+			if ($cookieLang) {
396 396
 				$appLang = $cookieLang;
397 397
 			}
398 398
 			$languageFilePath = null;
@@ -401,30 +401,30 @@  discard block
 block discarded – undo
401 401
 			$searchModuleName = null;
402 402
 			$obj = & get_instance();
403 403
 			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
404
+			if (strpos($language, '/') !== false) {
405 405
 				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
406
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
407 407
 					$searchModuleName = $path[0];
408 408
 					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
409
+					$file = $path[0] . DS . $language;
410 410
 				}
411 411
 			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
412
+			if (!$searchModuleName && !empty($obj->moduleName)) {
413 413
 				$searchModuleName = $obj->moduleName;
414 414
 			}
415 415
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
416
+			if ($moduleLanguagePath) {
417
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
418 418
 				$languageFilePath = $moduleLanguagePath;
419 419
 			}
420
-			else{
420
+			else {
421 421
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422 422
 			}
423
-			if(! $languageFilePath){
423
+			if (!$languageFilePath) {
424 424
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
425
+				foreach ($searchDir as $dir) {
426 426
 					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
427
+					if (file_exists($filePath)) {
428 428
 						$languageFilePath = $filePath;
429 429
 						//is already found not to continue
430 430
 						break;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 				}
433 433
 			}
434 434
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
435
+			if ($languageFilePath) {
436 436
 				$lang = array();
437 437
 				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
438
+				if (!empty($lang) && is_array($lang)) {
439
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
440 440
 					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
441
+					$langObj = & class_loader('Lang', 'classes');
442 442
 					$langObj->addLangMessages($lang);
443 443
 					//free the memory
444 444
 					unset($lang);
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
 				static::$loaded['lang_' . $language] = $languageFilePath;
447 447
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448 448
 			}
449
-			else{
449
+			else {
450 450
 				show_error('Unable to find language file [' . $file . ']');
451 451
 			}
452 452
 		}
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
455
+		private function getResourcesFromAutoloadConfig() {
456 456
 			$autoloads = array();
457 457
 			$autoloads['config']    = array();
458 458
 			$autoloads['languages'] = array();
@@ -460,17 +460,17 @@  discard block
 block discarded – undo
460 460
 			$autoloads['models']    = array();
461 461
 			$autoloads['functions'] = array();
462 462
 			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
463
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
464 464
 				$autoload = array();
465 465
 				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
466
+				if (!empty($autoload) && is_array($autoload)) {
467 467
 					$autoloads = array_merge($autoloads, $autoload);
468 468
 					unset($autoload);
469 469
 				}
470 470
 			}
471 471
 			//loading autoload configuration for modules
472 472
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
473
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
474 474
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475 475
 			}
476 476
 			return $autoloads;
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		 * Load the autoload configuration
481 481
 		 * @return void
482 482
 		 */
483
-		private function loadResourcesFromAutoloadConfig(){
483
+		private function loadResourcesFromAutoloadConfig() {
484 484
 			$autoloads = array();
485 485
 			$autoloads['config']    = array();
486 486
 			$autoloads['languages'] = array();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		 * @param  array  $resources the resource to load
514 514
 		 * @return void            
515 515
 		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
516
+		private function loadAutoloadResourcesArray($method, array $resources) {
517 517
 			foreach ($resources as $name) {
518 518
 				$this->{$method}($name);
519 519
 			}
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryRunner{
26
+  class DatabaseQueryRunner {
27 27
       
28 28
     /**
29 29
 	* The logger instance
30 30
 	* @var object
31 31
 	*/
32
-    private $logger            = null;
32
+    private $logger = null;
33 33
     
34 34
   	/**
35 35
   	 * The last query result
36 36
   	 * @var object
37 37
   	*/
38
-  	private $queryResult       = null;
38
+  	private $queryResult = null;
39 39
   	
40 40
   	/**
41 41
     * The benchmark instance
@@ -47,45 +47,45 @@  discard block
 block discarded – undo
47 47
 	 * The SQL query statment to execute
48 48
 	 * @var string
49 49
 	*/
50
-    private $query             = null;
50
+    private $query = null;
51 51
     
52 52
     /**
53 53
 	 * Indicate if we need return result as list (boolean) 
54 54
      * or the data used to replace the placeholder (array)
55 55
 	 * @var array|boolean
56 56
 	 */
57
-     private $returnAsList     = true;
57
+     private $returnAsList = true;
58 58
      
59 59
      
60 60
      /**
61 61
 	   * Indicate if we need return result as array or not
62 62
      * @var boolean
63 63
 	   */
64
-     private $returnAsArray     = true;
64
+     private $returnAsArray = true;
65 65
      
66 66
      /**
67 67
      * The last PDOStatment instance
68 68
      * @var object
69 69
      */
70
-     private $pdoStatment       = null;
70
+     private $pdoStatment = null;
71 71
      
72 72
      /**
73 73
   	 * The error returned for the last query
74 74
   	 * @var string
75 75
   	 */
76
-     private $error             = null;
76
+     private $error = null;
77 77
 	
78 78
     /**
79 79
      * The PDO instance
80 80
      * @var object
81 81
     */
82
-    private $pdo                = null;
82
+    private $pdo = null;
83 83
   
84 84
     /**
85 85
      * The database driver name used
86 86
      * @var string
87 87
     */
88
-    private $driver             = null;
88
+    private $driver = null;
89 89
 
90 90
 
91 91
 	
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      * @param boolean $returnAsList if need return as list or just one row
97 97
      * @param boolean $returnAsArray whether to return the result as array or not
98 98
      */
99
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
100
-        if (is_object($pdo)){
99
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
100
+        if (is_object($pdo)) {
101 101
           $this->pdo = $pdo;
102 102
         }
103 103
         $this->query         = $query;
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
      * 
113 113
      * @return object|void
114 114
      */
115
-    public function execute(){
115
+    public function execute() {
116 116
         //reset instance
117 117
         $this->reset();
118 118
        
119 119
        //for database query execution time
120 120
         $benchmarkMarkerKey = $this->getBenchmarkKey();
121
-        if (! is_object($this->benchmarkInstance)){
121
+        if (!is_object($this->benchmarkInstance)) {
122 122
           $this->benchmarkInstance = & class_loader('Benchmark');
123 123
         }
124 124
         
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
135 135
                                                               );
136 136
 		    //TODO use the configuration value for the high response time currently is 1 second
137
-        if ($responseTime >= 1 ){
137
+        if ($responseTime >= 1) {
138 138
             $this->logger->warning(
139 139
                                     'High response time while processing database query [' . $this->query . ']. 
140
-                                     The response time is [' .$responseTime. '] sec.'
140
+                                     The response time is [' .$responseTime . '] sec.'
141 141
                                   );
142 142
         }
143 143
 		
144
-        if ($this->pdoStatment !== false){
144
+        if ($this->pdoStatment !== false) {
145 145
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
-          if($isSqlSELECTQuery){
146
+          if ($isSqlSELECTQuery) {
147 147
               $this->setResultForSelect();              
148 148
           }
149
-          else{
149
+          else {
150 150
               $this->setResultForNonSelect();
151 151
           }
152 152
           return $this->queryResult;
@@ -158,28 +158,28 @@  discard block
 block discarded – undo
158 158
    * Return the result for SELECT query
159 159
    * @see DatabaseQueryRunner::execute
160 160
    */
161
-    protected function setResultForSelect(){
161
+    protected function setResultForSelect() {
162 162
       //if need return all result like list of record
163 163
       $result = null;
164 164
       $numRows = 0;
165 165
       $fetchMode = PDO::FETCH_OBJ;
166
-      if($this->returnAsArray){
166
+      if ($this->returnAsArray) {
167 167
         $fetchMode = PDO::FETCH_ASSOC;
168 168
       }
169
-      if ($this->returnAsList){
169
+      if ($this->returnAsList) {
170 170
           $result = $this->pdoStatment->fetchAll($fetchMode);
171 171
       }
172
-      else{
172
+      else {
173 173
           $result = $this->pdoStatment->fetch($fetchMode);
174 174
       }
175 175
       //Sqlite and pgsql always return 0 when using rowCount()
176
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
176
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
177 177
         $numRows = count($result);  
178 178
       }
179
-      else{
179
+      else {
180 180
         $numRows = $this->pdoStatment->rowCount(); 
181 181
       }
182
-      if(! is_object($this->queryResult)){
182
+      if (!is_object($this->queryResult)) {
183 183
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184 184
       }
185 185
       $this->queryResult->setResult($result);
@@ -190,20 +190,20 @@  discard block
 block discarded – undo
190 190
    * Return the result for non SELECT query
191 191
    * @see DatabaseQueryRunner::execute
192 192
    */
193
-    protected function setResultForNonSelect(){
193
+    protected function setResultForNonSelect() {
194 194
       //Sqlite and pgsql always return 0 when using rowCount()
195 195
       $result = false;
196 196
       $numRows = 0;
197
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
197
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
198 198
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
199 199
         $numRows = 1; //TODO use the correct method to get the exact affected row
200 200
       }
201
-      else{
201
+      else {
202 202
           //to test the result for the query like UPDATE, INSERT, DELETE
203 203
           $result  = $this->pdoStatment->rowCount() >= 0; 
204 204
           $numRows = $this->pdoStatment->rowCount(); 
205 205
       }
206
-      if(! is_object($this->queryResult)){
206
+      if (!is_object($this->queryResult)) {
207 207
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208 208
       }
209 209
       $this->queryResult->setResult($result);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * Return the benchmark instance
216 216
      * @return Benchmark
217 217
      */
218
-    public function getBenchmark(){
218
+    public function getBenchmark() {
219 219
       return $this->benchmarkInstance;
220 220
     }
221 221
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @param Benchmark $benchmark the benchmark object
225 225
 	 * @return object DatabaseQueryRunner
226 226
      */
227
-    public function setBenchmark($benchmark){
227
+    public function setBenchmark($benchmark) {
228 228
       $this->benchmarkInstance = $benchmark;
229 229
       return $this;
230 230
     }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return object DatabaseQueryResult
236 236
      */
237
-    public function getQueryResult(){
237
+    public function getQueryResult() {
238 238
       return $this->queryResult;
239 239
     }
240 240
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
 	 * @return object DatabaseQueryRunner
246 246
      */
247
-    public function setQueryResult(DatabaseQueryResult $queryResult){
247
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
248 248
       $this->queryResult = $queryResult;
249 249
       return $this;
250 250
     }
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      * Return the Log instance
254 254
      * @return Log
255 255
      */
256
-    public function getLogger(){
256
+    public function getLogger() {
257 257
       return $this->logger;
258 258
     }
259 259
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * @param Log $logger the log object
263 263
 	 * @return object DatabaseQueryRunner
264 264
      */
265
-    public function setLogger($logger){
265
+    public function setLogger($logger) {
266 266
       $this->logger = $logger;
267 267
       return $this;
268 268
     }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * Return the current query SQL string
272 272
      * @return string
273 273
      */
274
-    public function getQuery(){
274
+    public function getQuery() {
275 275
       return $this->query;
276 276
     }
277 277
     
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @param string $query the SQL query to set
281 281
      * @return object DatabaseQueryRunner
282 282
      */
283
-    public function setQuery($query){
283
+    public function setQuery($query) {
284 284
        $this->query = $query;
285 285
        return $this;
286 286
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @param boolean $returnType
291 291
      * @return object DatabaseQueryRunner
292 292
      */
293
-    public function setReturnType($returnType){
293
+    public function setReturnType($returnType) {
294 294
        $this->returnAsList = $returnType;
295 295
        return $this;
296 296
     }
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      * @param boolean $status the status if true will return as array
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303
-    public function setReturnAsArray($status = true){
303
+    public function setReturnAsArray($status = true) {
304 304
        $this->returnAsArray = $status;
305 305
        return $this;
306 306
     }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * Return the error for last query execution
310 310
      * @return string
311 311
      */
312
-    public function getQueryError(){
312
+    public function getQueryError() {
313 313
       return $this->error;
314 314
     }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * Return the PDO instance
318 318
      * @return object
319 319
      */
320
-    public function getPdo(){
320
+    public function getPdo() {
321 321
       return $this->pdo;
322 322
     }
323 323
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      * @param PDO $pdo the pdo object
327 327
      * @return object DatabaseQueryRunner
328 328
      */
329
-    public function setPdo(PDO $pdo = null){
329
+    public function setPdo(PDO $pdo = null) {
330 330
       $this->pdo = $pdo;
331 331
       return $this;
332 332
     }
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * Return the database driver
336 336
      * @return string
337 337
      */
338
-    public function getDriver(){
338
+    public function getDriver() {
339 339
       return $this->driver;
340 340
     }
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @param string $driver the new driver
345 345
      * @return object DatabaseQueryRunner
346 346
      */
347
-    public function setDriver($driver){
347
+    public function setDriver($driver) {
348 348
       $this->driver = $driver;
349 349
       return $this;
350 350
     }
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
      * 
355 355
      *  @return string
356 356
      */
357
-    protected function getBenchmarkKey(){
357
+    protected function getBenchmarkKey() {
358 358
       return md5($this->query . $this->returnAsList . $this->returnAsArray);
359 359
     }
360 360
     
361 361
     /**
362 362
      * Set error for database query execution
363 363
      */
364
-    protected function setQueryRunnerError(){
364
+    protected function setQueryRunnerError() {
365 365
       $error = $this->pdo->errorInfo();
366 366
       $this->error = isset($error[2]) ? $error[2] : '';
367 367
       $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -373,12 +373,12 @@  discard block
 block discarded – undo
373 373
      * Set the Log instance using argument or create new instance
374 374
      * @param object $logger the Log instance if not null
375 375
      */
376
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
377
-      if ($logger !== null){
376
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
377
+      if ($logger !== null) {
378 378
         $this->logger = $logger;
379 379
       }
380
-      else{
381
-          $this->logger =& class_loader('Log', 'classes');
380
+      else {
381
+          $this->logger = & class_loader('Log', 'classes');
382 382
           $this->logger->setLogger('Library::DatabaseQueryRunner');
383 383
       }
384 384
     }
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
     /**
388 388
     * Reset the instance before run each query
389 389
     */
390
-    private function reset(){
390
+    private function reset() {
391 391
         $this->error = null;
392 392
         $this->pdoStatment = null;
393 393
     }
Please login to merge, or discard this patch.