Passed
Push — 1.0.0-dev ( 407604...83bedf )
by nguereza
03:26
created
core/classes/Config.php 1 patch
Spacing   +32 added lines, -32 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 Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,53 +139,53 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156 156
 				$protocol = 'http';
157
-				if(is_https()){
157
+				if (is_https()) {
158 158
 					$protocol = 'https';
159 159
 				}
160
-				$protocol .='://';
160
+				$protocol .= '://';
161 161
 
162
-				if (isset($_SERVER['SERVER_ADDR'])){
162
+				if (isset($_SERVER['SERVER_ADDR'])) {
163 163
 					$baseUrl = $_SERVER['SERVER_ADDR'];
164 164
 					//check if the server is running under IPv6
165
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
165
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
166
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
167 167
 					}
168 168
 					$serverPort = 80;
169 169
 					if (isset($_SERVER['SERVER_PORT'])) {
170 170
 						$serverPort = $_SERVER['SERVER_PORT'];
171 171
 					}
172 172
 					$port = '';
173
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
-						$port = ':'.$serverPort;
173
+					if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) {
174
+						$port = ':' . $serverPort;
175 175
 					}
176
-					$port = ((($serverPort != '80' && ! is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
176
+					$port = ((($serverPort != '80' && !is_https()) || ($serverPort != '443' && is_https())) ? ':' . $serverPort : '');
177 177
 					$baseUrl = $protocol . $baseUrl . $port . substr(
178 178
 																		$_SERVER['SCRIPT_NAME'], 
179 179
 																		0, 
180 180
 																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
181 181
 																	);
182 182
 				}
183
-				else{
183
+				else {
184 184
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
185 185
 					$baseUrl = 'http://localhost/';
186 186
 				}
187 187
 				self::set('base_url', $baseUrl);
188 188
 			}
189
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
189
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
190 190
 		}
191 191
 	}
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Spacing   +56 added lines, -56 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
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
          * @return void
98 98
          */
99 99
         public function __construct() {
100
-            $this->logger =& class_loader('Log', 'classes');
100
+            $this->logger = & class_loader('Log', 'classes');
101 101
             $this->logger->setLogger('Library::FormValidation');
102 102
            
103 103
 		   //Load form validation language message
104 104
             Loader::lang('form_validation');
105 105
             $obj = & get_instance();
106
-            $this->_errorsMessages  = array(
106
+            $this->_errorsMessages = array(
107 107
                         'required'         => $obj->lang->get('fv_required'),
108 108
                         'min_length'       => $obj->lang->get('fv_min_length'),
109 109
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
          * Set the database instance
134 134
          * @param object $database the database instance
135 135
          */
136
-        public function setDatabase(Database $database){
136
+        public function setDatabase(Database $database) {
137 137
             $this->databaseInstance = $database;
138 138
             return $this;
139 139
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
          * Get the database instance
143 143
          * @return object the database instance
144 144
          */
145
-        public function getDatabase(){
145
+        public function getDatabase() {
146 146
             return $this->databaseInstance;
147 147
         }
148 148
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 *
166 166
          * @return FormValidation Current instance of object.
167 167
          */
168
-        public function setData(array $data){
168
+        public function setData(array $data) {
169 169
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
170 170
             $this->data = $data;
171 171
 			return $this;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
          * Get the form validation data
176 176
          * @return array the form validation data to be validated
177 177
          */
178
-        public function getData(){
178
+        public function getData() {
179 179
             return $this->data;
180 180
         }
181 181
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		*
185 185
 		* @return string the function name
186 186
 		*/
187
-        protected function _toCallCase($funcName, $prefix='_validate') {
187
+        protected function _toCallCase($funcName, $prefix = '_validate') {
188 188
             $funcName = strtolower($funcName);
189 189
             $finalFuncName = $prefix;
190 190
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
209 209
          */
210 210
         public function canDoValidation() {
211
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
211
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
212 212
         }
213 213
 
214 214
         /**
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
          * Validate the CSRF 
229 229
          * @return void 
230 230
          */
231
-        protected function validateCSRF(){
232
-            if(get_instance()->request->method() == 'POST'){
231
+        protected function validateCSRF() {
232
+            if (get_instance()->request->method() == 'POST') {
233 233
                 $this->logger->debug('Check if CSRF is enabled in configuration');
234 234
                 //first check for CSRF
235
-                if (get_config('csrf_enable', false) && ! Security::validateCSRF()){
235
+                if (get_config('csrf_enable', false) && !Security::validateCSRF()) {
236 236
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
237 237
                 }
238
-                else{
238
+                else {
239 239
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
240 240
                 }
241 241
             }
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
             $this->_forceFail = false;
254 254
 
255 255
             foreach ($this->getData() as $inputName => $inputVal) {
256
-    			if(is_array($this->data[$inputName])){
256
+    			if (is_array($this->data[$inputName])) {
257 257
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258 258
     			}
259
-    			else{
259
+    			else {
260 260
     				$this->data[$inputName] = trim($this->data[$inputName]);
261 261
     			}
262 262
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         public function setRule($inputField, $inputLabel, $ruleSets) {
284 284
             $this->_rules[$inputField] = $ruleSets;
285 285
             $this->_labels[$inputField] = $inputLabel;
286
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
286
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
287 287
             return $this;
288 288
         }
289 289
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
             }
448 448
             $errorOutput .= $errorsEnd;
449 449
             echo ($echo) ? $errorOutput : '';
450
-            return (! $echo) ? $errorOutput : null;
450
+            return (!$echo) ? $errorOutput : null;
451 451
         }
452 452
 
453 453
         /**
@@ -472,25 +472,25 @@  discard block
 block discarded – undo
472 472
             /*
473 473
             //////////////// hack for regex rule that can contain "|"
474 474
             */
475
-            if(strpos($ruleString, 'regex') !== false){
475
+            if (strpos($ruleString, 'regex') !== false) {
476 476
                 $regexRule = array();
477 477
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
478 478
                 preg_match($rule, $ruleString, $regexRule);
479 479
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
480
-                 if(!empty($regexRule[0])){
480
+                 if (!empty($regexRule[0])) {
481 481
                      $ruleSets[] = $regexRule[0];
482 482
                  }
483 483
                  $ruleStringRegex = explode('|', $ruleStringTemp);
484 484
                 foreach ($ruleStringRegex as $rule) {
485 485
                     $rule = trim($rule);
486
-                    if($rule){
486
+                    if ($rule) {
487 487
                         $ruleSets[] = $rule;
488 488
                     }
489 489
                 }
490 490
                  
491 491
             }
492 492
             /***********************************/
493
-            else{
493
+            else {
494 494
                 if (strpos($ruleString, '|') !== FALSE) {
495 495
                     $ruleSets = explode('|', $ruleString);
496 496
                 } else {
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
          * @return void
523 523
          */
524 524
         protected function _validateRule($inputName, $inputVal, $ruleName) {
525
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
525
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
526 526
             // Array to store args
527 527
             $ruleArgs = array();
528 528
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                 $key = $i - 1;
568 568
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
569 569
             }
570
-            if (! array_key_exists($inputName, $this->_errors)) {
570
+            if (!array_key_exists($inputName, $this->_errors)) {
571 571
                 $this->_errors[$inputName] = $rulePhrase;
572 572
             }
573 573
         }
@@ -619,13 +619,13 @@  discard block
 block discarded – undo
619 619
          */
620 620
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
621 621
             $inputVal = $this->post($inputName);
622
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
622
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
623 623
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
624 624
                 if ($inputVal == '' && $callbackReturn == true) {
625 625
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
626 626
                 }
627 627
             } 
628
-			else if($inputVal == '') {
628
+			else if ($inputVal == '') {
629 629
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
630 630
             }
631 631
         }
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
652 652
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
653 653
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
654
-				if(! $result){
654
+				if (!$result) {
655 655
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
656 656
 				}
657 657
             }
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
                         continue;
686 686
                     }
687 687
                 } 
688
-				else{
688
+				else {
689 689
                     if ($inputVal == $doNotEqual) {
690 690
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
691 691
                         continue;
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
          */
716 716
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
717 717
             $inputVal = $this->post($inputName);
718
-            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)) {
719
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
718
+            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)) {
719
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
720 720
                     return;
721 721
                 }
722 722
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         protected function _validateExactLength($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 _validateMaxLength($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 _validateMinLength($inputName, $ruleName, array $ruleArgs) {
765 765
             $inputVal = $this->post($inputName);
766 766
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
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 _validateLessThan($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])));
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
797 797
             $inputVal = $this->post($inputName);
798 798
             if ($inputVal <= $ruleArgs[1]) {
799
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
799
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
800 800
                     return;
801 801
                 }
802 802
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -811,8 +811,8 @@  discard block
 block discarded – undo
811 811
          */
812 812
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
813 813
             $inputVal = $this->post($inputName);
814
-            if (! is_numeric($inputVal)) {
815
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
814
+            if (!is_numeric($inputVal)) {
815
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
816 816
                     return;
817 817
                 }
818 818
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
829 829
             $inputVal = $this->post($inputName);
830 830
     		$obj = & get_instance();
831
-    		if(! isset($obj->database)){
831
+    		if (!isset($obj->database)) {
832 832
     			return;
833 833
     		}
834 834
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     			          ->get();
838 838
     		$nb = $obj->database->numRows();
839 839
             if ($nb == 0) {
840
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
840
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
841 841
                     return;
842 842
                 }
843 843
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -852,9 +852,9 @@  discard block
 block discarded – undo
852 852
          */
853 853
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
854 854
             $inputVal = $this->post($inputName);
855
-            if (! is_object($this->databaseInstance)){
855
+            if (!is_object($this->databaseInstance)) {
856 856
                 $obj = & get_instance();
857
-                if(isset($obj->database)){
857
+                if (isset($obj->database)) {
858 858
                     $this->databaseInstance = $obj->database;
859 859
                 } else {
860 860
                     return;
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
     			                                      ->where($column, $inputVal);
866 866
     		$this->databaseInstance->get();
867 867
     		if ($this->databaseInstance->numRows() != 0) {
868
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
868
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
869 869
                     return;
870 870
                 }
871 871
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -880,16 +880,16 @@  discard block
 block discarded – undo
880 880
          */
881 881
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
882 882
             $inputVal = $this->post($inputName);
883
-    		if (! is_object($this->databaseInstance)){
883
+    		if (!is_object($this->databaseInstance)) {
884 884
                 $obj = & get_instance();
885
-                if(isset($obj->database)){
885
+                if (isset($obj->database)) {
886 886
                     $this->databaseInstance = $obj->database;
887 887
                 } else {
888 888
                     return;
889 889
                 }
890 890
             }
891 891
     		$data = explode(',', $ruleArgs[1]);
892
-    		if(count($data) < 2){
892
+    		if (count($data) < 2) {
893 893
     			return;
894 894
     		}
895 895
     		list($table, $column) = explode('.', $data[0]);
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
                                             		  ->where($field, '!=', trim($val));
900 900
             $this->databaseInstance->get();
901 901
     		if ($this->databaseInstance->numRows() != 0) {
902
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
902
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
903 903
                     return;
904 904
                 }
905 905
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
             $inputVal = $this->post($inputName);
917 917
     		$list = explode(',', $ruleArgs[1]);
918 918
             $list = array_map('trim', $list);
919
-            if (! in_array($inputVal, $list)) {
920
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
919
+            if (!in_array($inputVal, $list)) {
920
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
921 921
                     return;
922 922
                 }
923 923
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -933,8 +933,8 @@  discard block
 block discarded – undo
933 933
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
934 934
             $inputVal = $this->post($inputName);
935 935
     		$regex = $ruleArgs[1];
936
-            if (! preg_match($regex, $inputVal)) {
937
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
936
+            if (!preg_match($regex, $inputVal)) {
937
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
938 938
                     return;
939 939
                 }
940 940
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
core/libraries/Form.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Form{
28
+	class Form {
29 29
 
30 30
 		/**
31 31
 		 * Generate the form opened tag
@@ -35,23 +35,23 @@  discard block
 block discarded – undo
35 35
 		 * @param  string $enctype    the form enctype like "multipart/form-data"
36 36
 		 * @return string             the generated form html
37 37
 		 */
38
-		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){
39
-			if($path){
38
+		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) {
39
+			if ($path) {
40 40
 				$path = Url::site_url($path);
41 41
 			}
42 42
 			$method = strtoupper($method);
43 43
 			$str = null;
44
-			$str .= '<form action = "'.$path.'" method = "'.$method.'"';
45
-			if(! empty($enctype)){
46
-				$str .= ' enctype = "'.$enctype.'" ';
44
+			$str .= '<form action = "' . $path . '" method = "' . $method . '"';
45
+			if (!empty($enctype)) {
46
+				$str .= ' enctype = "' . $enctype . '" ';
47 47
 			}
48
-			if(! isset($attributes['accept-charset'])){
48
+			if (!isset($attributes['accept-charset'])) {
49 49
 				$attributes['accept-charset'] = get_config('charset', 'utf-8');
50 50
 			}
51 51
 			$str .= attributes_to_string($attributes);
52 52
 			$str .= '>';
53 53
 			//if CSRF is enabled in the configuration
54
-			if(get_config('csrf_enable', false) && $method == 'POST'){
54
+			if (get_config('csrf_enable', false) && $method == 'POST') {
55 55
 				$csrfValue = Security::generateCSRF();
56 56
 				$csrfName = get_config('csrf_key', 'csrf_key');
57 57
 				$str .= static::hidden($csrfName, $csrfValue);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		 * @see Form::open() for more details
65 65
 		 * @return string the generated multipart form html
66 66
 		 */
67
-		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){
67
+		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') {
68 68
 			return self::open($path, $attributes, $method, 'multipart/form-data');
69 69
 		}
70 70
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		 * Generate the form close
73 73
 		 * @return string the form close html
74 74
 		 */
75
-		public static function close(){
75
+		public static function close() {
76 76
 			return '</form>';
77 77
 		}
78 78
 
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 		 * @param  array  $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty
84 84
 		 * @return string         the generated fieldset value
85 85
 		 */
86
-		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){
86
+		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) {
87 87
 			$str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>';
88
-			if($legend){
89
-				$str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>';
88
+			if ($legend) {
89
+				$str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>';
90 90
 			}
91 91
 			return $str;
92 92
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * Generate the fieldset close tag
96 96
 		 * @return string the generated html for fieldset close
97 97
 		 */
98
-		public static function fieldsetClose(){
98
+		public static function fieldsetClose() {
99 99
 			return '</fieldset>';
100 100
 		}
101 101
 
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 		 * @param  string $name the form field name
106 106
 		 * @return string       the error message if exists and null if not
107 107
 		 */
108
-		public static function error($name){
108
+		public static function error($name) {
109 109
 			$return = null;
110 110
 			$obj = & get_instance();
111
-			if(isset($obj->formvalidation)){
111
+			if (isset($obj->formvalidation)) {
112 112
 				$errors = $obj->formvalidation->returnErrors();
113
-				$error =  isset($errors[$name]) ? $errors[$name] : null;
114
-				if($error){
113
+				$error = isset($errors[$name]) ? $errors[$name] : null;
114
+				if ($error) {
115 115
 					list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter();
116 116
 					$return = $errorStart . $error . $errorEnd;
117 117
 				}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * @param  mixed $default the default value if can not found the given form field name
126 126
 		 * @return mixed the form field value if is set, otherwise return the default value.
127 127
 		 */
128
-		public static function value($name, $default = null){
128
+		public static function value($name, $default = null) {
129 129
 			$value = get_instance()->request->query($name);
130 130
 			return $value ? $value : $default;
131 131
 		}
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 		 * @param  array  $attributes the additional attributes to be added
138 138
 		 * @return string the generated label html content
139 139
 		 */
140
-		public static function label($label, $for = '', array $attributes = array()){
140
+		public static function label($label, $for = '', array $attributes = array()) {
141 141
 			$str = '<label';
142
-			if($for){
143
-				$str .= ' for = "'.$for.'"';
142
+			if ($for) {
143
+				$str .= ' for = "' . $for . '"';
144 144
 			}
145 145
 			$str .= attributes_to_string($attributes);
146 146
 			$str .= '>';
147
-			$str .= $label.'</label>';
147
+			$str .= $label . '</label>';
148 148
 			return $str;
149 149
 		}
150 150
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 		 * @param  string $type       the type of the form field (password, text, submit, button, etc.)
157 157
 		 * @return string             the generated form field html content for the input
158 158
 		 */
159
-		public static function input($name, $value = null, array $attributes = array(), $type = 'text'){
159
+		public static function input($name, $value = null, array $attributes = array(), $type = 'text') {
160 160
 			$str = null;
161
-			$str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"';
161
+			$str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"';
162 162
 			$str .= attributes_to_string($attributes);
163 163
 			$str .= '/>';
164 164
 			return $str;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		 * Generate the form field for "text"
169 169
 		 * @see Form::input() for more details
170 170
 		 */
171
-		public static function text($name, $value = null, array $attributes = array()){
171
+		public static function text($name, $value = null, array $attributes = array()) {
172 172
 			return self::input($name, $value, $attributes, 'text');
173 173
 		}
174 174
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		 * Generate the form field for "password"
177 177
 		 * @see Form::input() for more details
178 178
 		 */
179
-		public static function password($name, $value = null, array $attributes = array()){
179
+		public static function password($name, $value = null, array $attributes = array()) {
180 180
 			return self::input($name, $value, $attributes, 'password');
181 181
 		}
182 182
 
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 		 * Generate the form field for "radio"
185 185
 		 * @see Form::input() for more details
186 186
 		 */
187
-		public static function radio($name, $value = null,  $checked = false, array $attributes = array()){
188
-			if($checked){
187
+		public static function radio($name, $value = null, $checked = false, array $attributes = array()) {
188
+			if ($checked) {
189 189
 				$attributes['checked'] = true;
190 190
 			}
191 191
 			return self::input($name, $value, $attributes, 'radio');
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 		 * Generate the form field for "checkbox"
196 196
 		 * @see Form::input() for more details
197 197
 		 */
198
-		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){
199
-			if($checked){
198
+		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) {
199
+			if ($checked) {
200 200
 				$attributes['checked'] = true;
201 201
 			}
202 202
 			return self::input($name, $value, $attributes, 'checkbox');
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		 * Generate the form field for "number"
207 207
 		 * @see Form::input() for more details
208 208
 		 */
209
-		public static function number($name, $value = null, array $attributes = array()){
209
+		public static function number($name, $value = null, array $attributes = array()) {
210 210
 			return self::input($name, $value, $attributes, 'number');
211 211
 		}
212 212
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		 * Generate the form field for "phone"
215 215
 		 * @see Form::input() for more details
216 216
 		 */
217
-		public static function phone($name, $value = null, array $attributes = array()){
217
+		public static function phone($name, $value = null, array $attributes = array()) {
218 218
 			return self::input($name, $value, $attributes, 'phone');
219 219
 		}
220 220
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		 * Generate the form field for "email"
223 223
 		 * @see Form::input() for more details
224 224
 		 */
225
-		public static function email($name, $value = null, array $attributes = array()){
225
+		public static function email($name, $value = null, array $attributes = array()) {
226 226
 			return self::input($name, $value, $attributes, 'email');
227 227
 		}
228 228
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		 * Generate the form field for "search"
231 231
 		 * @see Form::input() for more details
232 232
 		 */
233
-		public static function search($name, $value = null, array $attributes = array()){
233
+		public static function search($name, $value = null, array $attributes = array()) {
234 234
 			return self::input($name, $value, $attributes, 'search');
235 235
 		}
236 236
 		
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		 * Generate the form field for "hidden"
239 239
 		 * @see Form::input() for more details
240 240
 		 */
241
-		public static function hidden($name, $value = null, array $attributes = array()){
241
+		public static function hidden($name, $value = null, array $attributes = array()) {
242 242
 			return self::input($name, $value, $attributes, 'hidden');
243 243
 		}
244 244
 		
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		 * Generate the form field for "file"
247 247
 		 * @see Form::input() for more details
248 248
 		 */
249
-		public static function file($name, array $attributes = array()){
249
+		public static function file($name, array $attributes = array()) {
250 250
 			return self::input($name, null, $attributes, 'file');
251 251
 		}
252 252
 		
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		 * Generate the form field for "button"
255 255
 		 * @see Form::input() for more details
256 256
 		 */
257
-		public static function button($name, $value = null, array $attributes = array()){
257
+		public static function button($name, $value = null, array $attributes = array()) {
258 258
 			return self::input($name, $value, $attributes, 'button');
259 259
 		}
260 260
 		
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		 * Generate the form field for "reset"
263 263
 		 * @see Form::input() for more details
264 264
 		 */
265
-		public static function reset($name, $value = null, array $attributes = array()){
265
+		public static function reset($name, $value = null, array $attributes = array()) {
266 266
 			return self::input($name, $value, $attributes, 'reset');
267 267
 		}
268 268
 		
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		 * Generate the form field for "submit"
271 271
 		 * @see Form::input() for more details
272 272
 		 */
273
-		public static function submit($name, $value = null, array $attributes = array()){
273
+		public static function submit($name, $value = null, array $attributes = array()) {
274 274
 			return self::input($name, $value, $attributes, 'submit');
275 275
 		}
276 276
 
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
 		 * @param  array  $attributes the additional attributes to be added
282 282
 		 * @return string             the generated textarea form html content
283 283
 		 */
284
-		public static function textarea($name, $value = '', array $attributes = array()){
284
+		public static function textarea($name, $value = '', array $attributes = array()) {
285 285
 			$str = null;
286
-			$str .= '<textarea name = "'.$name.'"';
286
+			$str .= '<textarea name = "' . $name . '"';
287 287
 			$str .= attributes_to_string($attributes);
288 288
 			$str .= '>';
289
-			$str .= $value.'</textarea>';
289
+			$str .= $value . '</textarea>';
290 290
 			return $str;
291 291
 		}
292 292
 		
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 		 * @param  array  $attributes the additional attribute to be added
299 299
 		 * @return string             the generated form field html content for select
300 300
 		 */
301
-		public static function select($name, $values = null, $selected = null, array $attributes = array()){
302
-			if(! is_array($values)){
301
+		public static function select($name, $values = null, $selected = null, array $attributes = array()) {
302
+			if (!is_array($values)) {
303 303
 				$values = array('' => $values);
304 304
 			}
305 305
 			$str = null;
306
-			$str .= '<select name = "'.$name.'"';
306
+			$str .= '<select name = "' . $name . '"';
307 307
 			$str .= attributes_to_string($attributes);
308 308
 			$str .= '>';
309
-			foreach($values as $key => $val){
309
+			foreach ($values as $key => $val) {
310 310
 				$select = '';
311
-				if($key == $selected){
311
+				if ($key == $selected) {
312 312
 					$select = 'selected';
313 313
 				}
314
-				$str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>';
314
+				$str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>';
315 315
 			}
316 316
 			$str .= '</select>';
317 317
 			return $str;
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	/**
60 60
 	* Custom application path for tests 
61 61
 	*/
62
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
62
+	define('APPS_PATH', TESTS_PATH . 'hmvc' . DS);
63 63
 
64 64
 	/**
65 65
 	* The path to the controller directory of your application.
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
203 203
 	* in HMVC architecture (hierichical, controllers, models, views).
204 204
 	*/
205
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
205
+	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS);
206 206
 
207 207
 	/**
208 208
 	* The path to the directory of sources external to your application.
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	$_SESSION = array();
243 243
 	
244 244
 	//check for composer autoload file if exists include it
245
-	if (file_exists(VENDOR_PATH . 'autoload.php')){
245
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
246 246
 		require_once VENDOR_PATH . 'autoload.php';
247 247
 		
248 248
 		//define the class alias for vstream
Please login to merge, or discard this patch.