Test Failed
Push — 1.0.0-dev ( 14bd99...2a3084 )
by nguereza
03:00
created
core/classes/Security.php 1 patch
Spacing   +20 added lines, -20 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 Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (self::$logger == null) {
41
+				self::$logger[0] = & class_loader('Log', 'classes');
42 42
 				self::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return self::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = self::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = self::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 			//super instance
94 94
 			$obj = & get_instance();
95 95
 			$token = $obj->request->query($key);
96
-			if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
97
-				$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
96
+			if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
97
+				$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
98 98
 				return false;
99 99
 			}
100
-			$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
100
+			$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
101 101
 			//remove the token from session
102 102
 			Session::clear($key);
103 103
 			Session::clear($keyExpire);
@@ -107,24 +107,24 @@  discard block
 block discarded – undo
107 107
 		/**
108 108
 		 * This method is used to check the whitelist IP address access
109 109
 		 */
110
-		 public static function checkWhiteListIpAccess(){
110
+		 public static function checkWhiteListIpAccess() {
111 111
 			$logger = self::getLogger();
112 112
 			$logger->debug('Validation of the IP address access ...');
113 113
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
114 114
 			$isEnable = get_config('white_list_ip_enable', false);
115
-			if($isEnable){
115
+			if ($isEnable) {
116 116
 				$logger->info('Whitelist IP access is enabled in the configuration');
117 117
 				$list = get_config('white_list_ip_addresses', array());
118
-				if(! empty($list)){
118
+				if (!empty($list)) {
119 119
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
120 120
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
121 121
 					$ip = get_ip();
122
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
122
+					if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
123 123
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124 124
 						//wildcard to access all ip address
125 125
 						return;
126 126
 					}
127
-					else{
127
+					else {
128 128
 						// go through all whitelisted ips
129 129
 						foreach ($list as $ipaddr) {
130 130
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 					}
151 151
 				}
152 152
 			}
153
-			else{
153
+			else {
154 154
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155 155
 			}
156 156
 		 }
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Spacing   +71 added lines, -71 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 Response{
27
+	class Response {
28 28
 
29 29
 		/**
30 30
 		 * The list of request header to send with response
@@ -65,15 +65,15 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Construct new response instance
67 67
 		 */
68
-		public function __construct(){
68
+		public function __construct() {
69 69
 			$currentUrl = '';
70
-			if (! empty($_SERVER['REQUEST_URI'])){
70
+			if (!empty($_SERVER['REQUEST_URI'])) {
71 71
 				$currentUrl = $_SERVER['REQUEST_URI'];
72 72
 			}
73
-			if (! empty($_SERVER['QUERY_STRING'])){
73
+			if (!empty($_SERVER['QUERY_STRING'])) {
74 74
 				$currentUrl .= '?' . $_SERVER['QUERY_STRING'];
75 75
 			}
76
-			$this->_currentUrl =  $currentUrl;
76
+			$this->_currentUrl = $currentUrl;
77 77
 					
78 78
 			$this->_currentUrlCacheKey = md5($this->_currentUrl);
79 79
 			
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 		 * Get the logger singleton instance
89 89
 		 * @return Log the logger instance
90 90
 		 */
91
-		private static function getLogger(){
92
-			if(self::$logger == null){
93
-				self::$logger[0] =& class_loader('Log', 'classes');
91
+		private static function getLogger() {
92
+			if (self::$logger == null) {
93
+				self::$logger[0] = & class_loader('Log', 'classes');
94 94
 				self::$logger[0]->setLogger('Library::Response');
95 95
 			}
96 96
 			return self::$logger[0];
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 		 * @param  integer $httpCode the HTTP status code
102 102
 		 * @param  array   $headers   the additional headers to add to the existing headers list
103 103
 		 */
104
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
104
+		public static function sendHeaders($httpCode = 200, array $headers = array()) {
105 105
 			set_http_status_header($httpCode);
106 106
 			self::setHeaders($headers);
107
-			if(! headers_sent()){
108
-				foreach(self::getHeaders() as $key => $value){
109
-					header($key .': '.$value);
107
+			if (!headers_sent()) {
108
+				foreach (self::getHeaders() as $key => $value) {
109
+					header($key . ': ' . $value);
110 110
 				}
111 111
 			}
112 112
 		}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		 * Get the list of the headers
116 116
 		 * @return array the headers list
117 117
 		 */
118
-		public static function getHeaders(){
118
+		public static function getHeaders() {
119 119
 			return self::$headers;
120 120
 		}
121 121
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		 * @param  string $name the header name
125 125
 		 * @return string       the header value
126 126
 		 */
127
-		public static function getHeader($name){
127
+		public static function getHeader($name) {
128 128
 			return array_key_exists($name, self::$headers) ? self::$headers[$name] : null;
129 129
 		}
130 130
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		 * @param string $name  the header name
135 135
 		 * @param string $value the header value to be set
136 136
 		 */
137
-		public static function setHeader($name, $value){
137
+		public static function setHeader($name, $value) {
138 138
 			self::$headers[$name] = $value;
139 139
 		}
140 140
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		 * @param array $headers the list of the headers to set. 
144 144
 		 * Note: this will merge with the existing headers
145 145
 		 */
146
-		public static function setHeaders(array $headers){
146
+		public static function setHeaders(array $headers) {
147 147
 			self::$headers = array_merge(self::getHeaders(), $headers);
148 148
 		}
149 149
 		
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
 		 * Redirect user in the specified page
152 152
 		 * @param  string $path the URL or URI to be redirect to
153 153
 		 */
154
-		public static function redirect($path = ''){
154
+		public static function redirect($path = '') {
155 155
 			$logger = self::getLogger();
156 156
 			$url = Url::site_url($path);
157
-			$logger->info('Redirect to URL [' .$url. ']');
158
-			if(! headers_sent()){
159
-				header('Location: '.$url);
157
+			$logger->info('Redirect to URL [' . $url . ']');
158
+			if (!headers_sent()) {
159
+				header('Location: ' . $url);
160 160
 				exit;
161 161
 			}
162
-			else{
162
+			else {
163 163
 				echo '<script>
164
-						location.href = "'.$url.'";
164
+						location.href = "'.$url . '";
165 165
 					</script>';
166 166
 			}
167 167
 		}
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 		 * @return void|string          if $return is true will return the view content otherwise
175 175
 		 * will display the view content.
176 176
 		 */
177
-		public function render($view, $data = null, $return = false){
177
+		public function render($view, $data = null, $return = false) {
178 178
 			$logger = self::getLogger();
179 179
 			//convert data to an array
180
-			$data = ! is_array($data) ? (array) $data : $data;
180
+			$data = !is_array($data) ? (array) $data : $data;
181 181
 			$view = str_ireplace('.php', '', $view);
182 182
 			$view = trim($view, '/\\');
183 183
 			$viewFile = $view . '.php';
@@ -186,42 +186,42 @@  discard block
 block discarded – undo
186 186
 			//super instance
187 187
 			$obj = & get_instance();
188 188
 			
189
-			if(Module::hasModule()){
189
+			if (Module::hasModule()) {
190 190
 				//check in module first
191 191
 				$logger->debug('Checking the view [' . $view . '] from module list ...');
192 192
 				$mod = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($view, '/') !== false){
194
+				if (strpos($view, '/') !== false) {
195 195
 					$viewPath = explode('/', $view);
196
-					if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
196
+					if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
197 197
 						$mod = $viewPath[0];
198 198
 						array_shift($viewPath);
199 199
 						$view = implode('/', $viewPath);
200 200
 						$viewFile = $view . '.php';
201 201
 					}
202 202
 				}
203
-				if(! $mod && !empty($obj->moduleName)){
203
+				if (!$mod && !empty($obj->moduleName)) {
204 204
 					$mod = $obj->moduleName;
205 205
 				}
206
-				if($mod){
206
+				if ($mod) {
207 207
 					$moduleViewPath = Module::findViewFullPath($view, $mod);
208
-					if($moduleViewPath){
208
+					if ($moduleViewPath) {
209 209
 						$path = $moduleViewPath;
210
-						$logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it');
210
+						$logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it');
211 211
 					}
212
-					else{
213
-						$logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location');
212
+					else {
213
+						$logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location');
214 214
 					}
215 215
 				}
216
-				else{
216
+				else {
217 217
 					$logger->info('The current request does not use module using the default location.');
218 218
 				}
219 219
 			}
220 220
 			$logger->info('The view file path to be loaded is [' . $path . ']');
221 221
 			$found = false;
222
-			if(file_exists($path)){
223
-				foreach(get_object_vars($obj) as $key => $value){
224
-					if(! isset($this->{$key})){
222
+			if (file_exists($path)) {
223
+				foreach (get_object_vars($obj) as $key => $value) {
224
+					if (!isset($this->{$key})) {
225 225
 						$this->{$key} = & $obj->{$key};
226 226
 					}
227 227
 				}
@@ -230,44 +230,44 @@  discard block
 block discarded – undo
230 230
 				//need use require() instead of require_once because can load this view many time
231 231
 				require $path;
232 232
 				$content = ob_get_clean();
233
-				if($return){
233
+				if ($return) {
234 234
 					return $content;
235 235
 				}
236 236
 				$this->_pageRender .= $content;
237 237
 				$found = true;
238 238
 			}
239
-			if(! $found){
240
-				show_error('Unable to find view [' .$view . ']');
239
+			if (!$found) {
240
+				show_error('Unable to find view [' . $view . ']');
241 241
 			}
242 242
 		}
243 243
 		
244 244
 		/**
245 245
 		* Send the final page output to user
246 246
 		*/
247
-		public function renderFinalPage(){
247
+		public function renderFinalPage() {
248 248
 			$logger = self::getLogger();
249 249
 			$obj = & get_instance();
250 250
 			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
251 251
 			$dispatcher = $obj->eventdispatcher;
252 252
 			$content = $this->_pageRender;
253
-			if(! $content){
253
+			if (!$content) {
254 254
 				$logger->warning('The final view content is empty.');
255 255
 				return;
256 256
 			}
257 257
 			//dispatch
258 258
 			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
259
-			$content = ! empty($event->payload) ? $event->payload : null;
260
-			if(empty($content)){
259
+			$content = !empty($event->payload) ? $event->payload : null;
260
+			if (empty($content)) {
261 261
 				$logger->warning('The view content is empty after dispatch to event listeners.');
262 262
 			}
263 263
 			
264 264
 			//check whether need save the page into cache.
265
-			if($cachePageStatus){
265
+			if ($cachePageStatus) {
266 266
 				//current page URL
267 267
 				$url = $this->_currentUrl;
268 268
 				//Cache view Time to live in second
269 269
 				$viewCacheTtl = get_config('cache_ttl');
270
-				if (!empty($obj->view_cache_ttl)){
270
+				if (!empty($obj->view_cache_ttl)) {
271 271
 					$viewCacheTtl = $obj->view_cache_ttl;
272 272
 				}
273 273
 				//the cache handler instance
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 				
281 281
 				//get the cache information to prepare header to send to browser
282 282
 				$cacheInfo = $cacheInstance->getInfo($cacheKey);
283
-				if($cacheInfo){
283
+				if ($cacheInfo) {
284 284
 					$lastModified = $cacheInfo['mtime'];
285 285
 					$expire = $cacheInfo['expire'];
286 286
 					$maxAge = $expire - time();
287 287
 					self::setHeader('Pragma', 'public');
288 288
 					self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
289
-					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
290
-					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
289
+					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
290
+					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
291 291
 				}
292 292
 			}
293 293
 			
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 			
300 300
 			//compress the output if is available
301 301
 			$type = null;
302
-			if (self::$_canCompressOutput){
302
+			if (self::$_canCompressOutput) {
303 303
 				$type = 'ob_gzhandler';
304 304
 			}
305 305
 			ob_start($type);
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 		/**
312 312
 		* Send the final page output to user if is cached
313 313
 		*/
314
-		public function renderFinalPageFromCache(&$cache){
314
+		public function renderFinalPageFromCache(&$cache) {
315 315
 			$logger = self::getLogger();
316 316
 			$url = $this->_currentUrl;					
317 317
 			//the current page cache key for identification
@@ -320,15 +320,15 @@  discard block
 block discarded – undo
320 320
 			$logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...');
321 321
 			//get the cache information to prepare header to send to browser
322 322
 			$cacheInfo = $cache->getInfo($pageCacheKey);
323
-			if($cacheInfo){
323
+			if ($cacheInfo) {
324 324
 				$lastModified = $cacheInfo['mtime'];
325 325
 				$expire = $cacheInfo['expire'];
326 326
 				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
327 327
 				self::setHeader('Pragma', 'public');
328 328
 				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
329
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
330
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
331
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
329
+				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
330
+				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
331
+				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
332 332
 					$logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser');
333 333
 					self::sendHeaders(304);
334 334
 					return;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 				self::sendHeaders(200);
338 338
 				//get the cache content
339 339
 				$content = $cache->get($pageCacheKey);
340
-				if($content){
340
+				if ($content) {
341 341
 					$logger->info('The page content for the URL [' . $url . '] already cached just display it');
342 342
 					//load benchmark class
343 343
 					$benchmark = & class_loader('Benchmark');
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 					///display the final output
352 352
 					//compress the output if is available
353 353
 					$type = null;
354
-					if (self::$_canCompressOutput){
354
+					if (self::$_canCompressOutput) {
355 355
 						$type = 'ob_gzhandler';
356 356
 					}
357 357
 					ob_start($type);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 					ob_end_flush();
360 360
 					return;
361 361
 				}
362
-				else{
362
+				else {
363 363
 					$logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired');
364 364
 					$cache->delete($pageCacheKey);
365 365
 				}
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 		* Get the final page to be rendered
372 372
 		* @return string
373 373
 		*/
374
-		public function getFinalPageRendered(){
374
+		public function getFinalPageRendered() {
375 375
 			return $this->_pageRender;
376 376
 		}
377 377
 
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 		 * Send the HTTP 404 error if can not found the 
380 380
 		 * routing information for the current request
381 381
 		 */
382
-		public static function send404(){
382
+		public static function send404() {
383 383
 			/********* for logs **************/
384 384
 			//can't use $obj = & get_instance()  here because the global super object will be available until
385 385
 			//the main controller is loaded even for Loader::library('xxxx');
386 386
 			$logger = self::getLogger();
387
-			$request =& class_loader('Request', 'classes');
388
-			$userAgent =& class_loader('Browser');
389
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
387
+			$request = & class_loader('Request', 'classes');
388
+			$userAgent = & class_loader('Browser');
389
+			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
390 390
 			
391 391
 			//here can't use Loader::functions just include the helper manually
392 392
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
@@ -396,10 +396,10 @@  discard block
 block discarded – undo
396 396
 			$logger->error($str);
397 397
 			/***********************************/
398 398
 			$path = CORE_VIEWS_PATH . '404.php';
399
-			if(file_exists($path)){
399
+			if (file_exists($path)) {
400 400
 				//compress the output if is available
401 401
 				$type = null;
402
-				if (self::$_canCompressOutput){
402
+				if (self::$_canCompressOutput) {
403 403
 					$type = 'ob_gzhandler';
404 404
 				}
405 405
 				ob_start($type);
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 				self::sendHeaders(404);
409 409
 				echo $output;
410 410
 			}
411
-			else{
412
-				show_error('The 404 view [' .$path. '] does not exist');
411
+			else {
412
+				show_error('The 404 view [' . $path . '] does not exist');
413 413
 			}
414 414
 		}
415 415
 
@@ -417,12 +417,12 @@  discard block
 block discarded – undo
417 417
 		 * Display the error to user
418 418
 		 * @param  array  $data the error information
419 419
 		 */
420
-		public static function sendError(array $data = array()){
420
+		public static function sendError(array $data = array()) {
421 421
 			$path = CORE_VIEWS_PATH . 'errors.php';
422
-			if(file_exists($path)){
422
+			if (file_exists($path)) {
423 423
 				//compress the output if is available
424 424
 				$type = null;
425
-				if (self::$_canCompressOutput){
425
+				if (self::$_canCompressOutput) {
426 426
 					$type = 'ob_gzhandler';
427 427
 				}
428 428
 				ob_start($type);
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 				self::sendHeaders(503);
433 433
 				echo $output;
434 434
 			}
435
-			else{
435
+			else {
436 436
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
437 437
 				set_http_status_header(503);
438 438
 				echo 'The error view [' . $path . '] does not exist';
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Spacing   +58 added lines, -58 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
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                     }
267 267
                 }
268 268
             }
269
-            $this->_success =  empty($this->_errors) && $this->_forceFail === false;
269
+            $this->_success = empty($this->_errors) && $this->_forceFail === false;
270 270
         }
271 271
 
272 272
         /**
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         public function setRule($inputField, $inputLabel, $ruleSets) {
281 281
             $this->_rules[$inputField] = $ruleSets;
282 282
             $this->_labels[$inputField] = $inputLabel;
283
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
283
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
284 284
             return $this;
285 285
         }
286 286
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
             }
445 445
             $errorOutput .= $errorsEnd;
446 446
             echo ($echo) ? $errorOutput : '';
447
-            return (! $echo) ? $errorOutput : null;
447
+            return (!$echo) ? $errorOutput : null;
448 448
         }
449 449
 
450 450
         /**
@@ -469,25 +469,25 @@  discard block
 block discarded – undo
469 469
             /*
470 470
             //////////////// hack for regex rule that can contain "|"
471 471
             */
472
-            if(strpos($ruleString, 'regex') !== false){
472
+            if (strpos($ruleString, 'regex') !== false) {
473 473
                 $regexRule = array();
474 474
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
475 475
                 preg_match($rule, $ruleString, $regexRule);
476 476
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
477
-                 if(!empty($regexRule[0])){
477
+                 if (!empty($regexRule[0])) {
478 478
                      $ruleSets[] = $regexRule[0];
479 479
                  }
480 480
                  $ruleStringRegex = explode('|', $ruleStringTemp);
481 481
                 foreach ($ruleStringRegex as $rule) {
482 482
                     $rule = trim($rule);
483
-                    if($rule){
483
+                    if ($rule) {
484 484
                         $ruleSets[] = $rule;
485 485
                     }
486 486
                 }
487 487
                  
488 488
             }
489 489
             /***********************************/
490
-            else{
490
+            else {
491 491
                 if (strpos($ruleString, '|') !== FALSE) {
492 492
                     $ruleSets = explode('|', $ruleString);
493 493
                 } else {
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
          * @return void
520 520
          */
521 521
         protected function _validateRule($inputName, $inputVal, $ruleName) {
522
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
522
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
523 523
             // Array to store args
524 524
             $ruleArgs = array();
525 525
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                 $key = $i - 1;
565 565
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
566 566
             }
567
-            if (! array_key_exists($inputName, $this->_errors)) {
567
+            if (!array_key_exists($inputName, $this->_errors)) {
568 568
                 $this->_errors[$inputName] = $rulePhrase;
569 569
             }
570 570
         }
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
          */
617 617
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
618 618
             $inputVal = $this->post($inputName);
619
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
619
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
620 620
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
621 621
                 if ($inputVal == '' && $callbackReturn == true) {
622 622
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
623 623
                 }
624 624
             } 
625
-			else if($inputVal == '') {
625
+			else if ($inputVal == '') {
626 626
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
627 627
             }
628 628
         }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
649 649
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
650 650
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
651
-				if(! $result){
651
+				if (!$result) {
652 652
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
653 653
 				}
654 654
             }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                         continue;
683 683
                     }
684 684
                 } 
685
-				else{
685
+				else {
686 686
                     if ($inputVal == $doNotEqual) {
687 687
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
688 688
                         continue;
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
          */
713 713
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
714 714
             $inputVal = $this->post($inputName);
715
-            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)) {
716
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
715
+            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)) {
716
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
717 717
                     return;
718 718
                 }
719 719
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
730 730
             $inputVal = $this->post($inputName);
731 731
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
732
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
732
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
733 733
                     return;
734 734
                 }
735 735
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
746 746
             $inputVal = $this->post($inputName);
747 747
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
748
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
748
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
749 749
                     return;
750 750
                 }
751 751
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
762 762
             $inputVal = $this->post($inputName);
763 763
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
764
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
764
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
765 765
                     return;
766 766
                 }
767 767
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
778 778
             $inputVal = $this->post($inputName);
779 779
             if ($inputVal >= $ruleArgs[1]) { 
780
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
780
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
781 781
                     return;
782 782
                 }
783 783
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
794 794
             $inputVal = $this->post($inputName);
795 795
             if ($inputVal <= $ruleArgs[1]) {
796
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
796
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
797 797
                     return;
798 798
                 }
799 799
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
          */
809 809
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
810 810
             $inputVal = $this->post($inputName);
811
-            if (! is_numeric($inputVal)) {
812
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
811
+            if (!is_numeric($inputVal)) {
812
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
813 813
                     return;
814 814
                 }
815 815
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
          */
825 825
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
826 826
             $inputVal = $this->post($inputName);
827
-    		if (! is_object($this->databaseInstance)){
827
+    		if (!is_object($this->databaseInstance)) {
828 828
                 $obj = & get_instance();
829
-                if(isset($obj->database)){
829
+                if (isset($obj->database)) {
830 830
                     $this->databaseInstance = $obj->database;
831 831
                 } 
832 832
             }
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
     			                                       ->where($column, $inputVal);
836 836
     		$this->databaseInstance->get();
837 837
             if ($this->databaseInstance->numRows() <= 0) {
838
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
838
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
839 839
                     return;
840 840
                 }
841 841
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -850,9 +850,9 @@  discard block
 block discarded – undo
850 850
          */
851 851
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
852 852
             $inputVal = $this->post($inputName);
853
-            if (! is_object($this->databaseInstance)){
853
+            if (!is_object($this->databaseInstance)) {
854 854
                 $obj = & get_instance();
855
-                if(isset($obj->database)){
855
+                if (isset($obj->database)) {
856 856
                     $this->databaseInstance = $obj->database;
857 857
                 } 
858 858
             }
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
     			                                      ->where($column, $inputVal);
862 862
     		$this->databaseInstance->get();
863 863
     		if ($this->databaseInstance->numRows() > 0) {
864
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
864
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
865 865
                     return;
866 866
                 }
867 867
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -876,14 +876,14 @@  discard block
 block discarded – undo
876 876
          */
877 877
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
878 878
             $inputVal = $this->post($inputName);
879
-    		if (! is_object($this->databaseInstance)){
879
+    		if (!is_object($this->databaseInstance)) {
880 880
                 $obj = & get_instance();
881
-                if(isset($obj->database)){
881
+                if (isset($obj->database)) {
882 882
                     $this->databaseInstance = $obj->database;
883 883
                 } 
884 884
             }
885 885
     		$data = explode(',', $ruleArgs[1]);
886
-    		if(count($data) < 2){
886
+    		if (count($data) < 2) {
887 887
     			return;
888 888
     		}
889 889
     		list($table, $column) = explode('.', $data[0]);
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
                                             		  ->where($field, '!=', trim($val));
894 894
             $this->databaseInstance->get();
895 895
     		if ($this->databaseInstance->numRows() > 0) {
896
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
896
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897 897
                     return;
898 898
                 }
899 899
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
             $inputVal = $this->post($inputName);
911 911
     		$list = explode(',', $ruleArgs[1]);
912 912
             $list = array_map('trim', $list);
913
-            if (! in_array($inputVal, $list)) {
914
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
913
+            if (!in_array($inputVal, $list)) {
914
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
915 915
                     return;
916 916
                 }
917 917
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -927,8 +927,8 @@  discard block
 block discarded – undo
927 927
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
928 928
             $inputVal = $this->post($inputName);
929 929
     		$regex = $ruleArgs[1];
930
-            if (! preg_match($regex, $inputVal)) {
931
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
930
+            if (!preg_match($regex, $inputVal)) {
931
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
932 932
                     return;
933 933
                 }
934 934
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
core/libraries/Browser.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -916,27 +916,27 @@  discard block
 block discarded – undo
916 916
                 if (isset($aresult[1])) {
917 917
                     $this->setBrowser(self::BROWSER_IE);
918 918
                     $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
919
-                    if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){
920
-                        if($aresult[1] == '3.1'){
919
+                    if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) {
920
+                        if ($aresult[1] == '3.1') {
921 921
                             $this->setVersion('7.0');
922 922
                         }
923
-                        else if($aresult[1] == '4.0'){
923
+                        else if ($aresult[1] == '4.0') {
924 924
                             $this->setVersion('8.0');
925 925
                         }
926
-                        else if($aresult[1] == '5.0'){
926
+                        else if ($aresult[1] == '5.0') {
927 927
                             $this->setVersion('9.0');
928 928
                         }
929
-                        else if($aresult[1] == '6.0'){
929
+                        else if ($aresult[1] == '6.0') {
930 930
                             $this->setVersion('10.0');
931 931
                         }
932
-                        else if($aresult[1] == '7.0'){
932
+                        else if ($aresult[1] == '7.0') {
933 933
                             $this->setVersion('11.0');
934 934
                         }
935
-                        else if($aresult[1] == '8.0'){
935
+                        else if ($aresult[1] == '8.0') {
936 936
                             $this->setVersion('11.0');
937 937
                         }
938 938
                     }
939
-                    if(stripos($this->_agent, 'IEMobile') !== false) {
939
+                    if (stripos($this->_agent, 'IEMobile') !== false) {
940 940
                         $this->setBrowser(self::BROWSER_POCKET_IE);
941 941
                         $this->setMobile(true);
942 942
                     }
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
               'mac' => self::PLATFORM_APPLE,
1677 1677
               'android' => self::PLATFORM_ANDROID,
1678 1678
               'Silk' => self::PLATFORM_FIRE_OS,
1679
-              'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV,
1679
+              'linux_smarttv' => self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV,
1680 1680
               'linux' => self::PLATFORM_LINUX,
1681 1681
               'Nokia' => self::PLATFORM_NOKIA,
1682 1682
               'BlackBerry' => self::PLATFORM_BLACKBERRY,
@@ -1700,9 +1700,9 @@  discard block
 block discarded – undo
1700 1700
             );
1701 1701
 
1702 1702
             foreach ($platformMaps as $name => $value) {
1703
-                if($name == 'linux_smarttv' 
1703
+                if ($name == 'linux_smarttv' 
1704 1704
                     && stripos($this->_agent, 'linux') !== false 
1705
-                    && stripos($this->_agent, 'SMART-TV') !== false ){
1705
+                    && stripos($this->_agent, 'SMART-TV') !== false) {
1706 1706
                         $this->_platform = $value;
1707 1707
                         break;
1708 1708
                 } elseif (stripos($this->_agent, $name) !== false) {
Please login to merge, or discard this patch.
core/functions/function_string.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 *  @filesource
40 40
 	 */
41 41
 
42
-	if(! function_exists('get_random_string')){
42
+	if (!function_exists('get_random_string')) {
43 43
 		/**
44 44
 		 * Generate a random string
45 45
 		 * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
 		 * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50 50
 		 * @return string the generated string.
51 51
 		 */
52
-		function get_random_string($type = 'alnum', $length = 10, $lower = false){
52
+		function get_random_string($type = 'alnum', $length = 10, $lower = false) {
53 53
 			$chars = array(
54 54
 							'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
55 55
 							'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
56 56
 							'num' => '1234567890'
57 57
 						);
58 58
 			$str = null;
59
-			if(isset($chars[$type])){
59
+			if (isset($chars[$type])) {
60 60
 				$str = $chars[$type];
61 61
 			}
62 62
 			$random = null;
63
-			for($i = 0; $i < $length; $i++){
63
+			for ($i = 0; $i < $length; $i++) {
64 64
 				$random .= $str[mt_rand() % strlen($str)];
65 65
 			}
66
-			if($lower){
66
+			if ($lower) {
67 67
 				$random = strtolower($random);
68 68
 			}
69 69
 			return $random;
Please login to merge, or discard this patch.
core/libraries/Pagination.php 1 patch
Spacing   +45 added lines, -45 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 Pagination{
27
+    class Pagination {
28 28
         
29 29
 		/**
30 30
          * The list of loaded config
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
          * Create an instance of pagination
43 43
          * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
44 44
          */
45
-        public function __construct($overwriteConfig = array()){
46
-            if (file_exists(CONFIG_PATH . 'config_pagination.php')){
45
+        public function __construct($overwriteConfig = array()) {
46
+            if (file_exists(CONFIG_PATH . 'config_pagination.php')) {
47 47
                 $config = array();
48 48
                 require_once CONFIG_PATH . 'config_pagination.php';
49
-                if (empty($config) || ! is_array($config)){
49
+                if (empty($config) || !is_array($config)) {
50 50
                     show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
51 51
                 }
52
-				else{
53
-					if (! empty($overwriteConfig)){
52
+				else {
53
+					if (!empty($overwriteConfig)) {
54 54
 						$config = array_merge($config, $overwriteConfig);
55 55
 					}
56 56
 					$this->config = $config;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 					unset($config);
60 60
 				}
61 61
             }
62
-            else{
62
+            else {
63 63
                 show_error('Unable to find the pagination configuration file');
64 64
             }
65 65
         }
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
          * config_pagination.php
71 71
          * @param array $config the configuration to overwrite
72 72
          */
73
-        public function setConfig(array $config = array()){
74
-            if (! empty($config)){
73
+        public function setConfig(array $config = array()) {
74
+            if (!empty($config)) {
75 75
                 $this->config = array_merge($this->config, $config);
76 76
                 Config::setAll($config);
77 77
             }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
          * 
83 83
          * @return array
84 84
          */
85
-        public function getConfig(){
85
+        public function getConfig() {
86 86
             return $this->config;
87 87
         }
88 88
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
          * Return the value of the pagination query string
91 91
          * @return string
92 92
          */
93
-        public function getPaginationQueryString(){
93
+        public function getPaginationQueryString() {
94 94
             return $this->paginationQueryString;
95 95
         }
96 96
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
          * @param string $paginationQueryString the new value
100 100
          * @return object
101 101
          */
102
-        public function setPaginationQueryString($paginationQueryString){
102
+        public function setPaginationQueryString($paginationQueryString) {
103 103
             $this->paginationQueryString = $paginationQueryString;
104 104
             return $this;
105 105
         }
@@ -112,25 +112,25 @@  discard block
 block discarded – undo
112 112
          * 
113 113
          * @return object
114 114
          */
115
-        public function determinePaginationQueryStringValue(){
115
+        public function determinePaginationQueryStringValue() {
116 116
             $pageQueryName = $this->config['page_query_string_name'];
117 117
             $queryString = Url::queryString();
118 118
             $currentUrl = Url::current();
119 119
             $query = '';
120
-             if ($queryString == ''){
120
+             if ($queryString == '') {
121 121
                 $query = '?' . $pageQueryName . '=';
122 122
             }
123
-            else{
123
+            else {
124 124
                 $tab = explode($pageQueryName . '=', $queryString);
125 125
                 $nb = count($tab);
126
-                if ($nb == 1){
126
+                if ($nb == 1) {
127 127
                     $query = '?' . $queryString . '&' . $pageQueryName . '=';
128 128
                 }
129
-                else{
130
-                    if ($tab[0] == ''){
129
+                else {
130
+                    if ($tab[0] == '') {
131 131
                         $query = '?' . $pageQueryName . '=';
132 132
                     }
133
-                    else{
133
+                    else {
134 134
                         $query = '?' . $tab[0] . '' . $pageQueryName . '=';
135 135
                     }
136 136
                 }
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
          * 
149 149
          * @return string the pagination link
150 150
          */
151
-        public function getLink($totalRows, $currentPageNumber){
151
+        public function getLink($totalRows, $currentPageNumber) {
152 152
             $numberOfLink = $this->config['nb_link'];
153 153
 			$numberOfRowPerPage = $this->config['pagination_per_page'];
154
-            if (empty($this->paginationQueryString)){
154
+            if (empty($this->paginationQueryString)) {
155 155
                 //determine the pagination query string value
156 156
                 $this->determinePaginationQueryStringValue();
157 157
             }
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             $numberOfLink = (int) $numberOfLink;
163 163
             $numberOfRowPerPage = (int) $numberOfRowPerPage;
164 164
 			
165
-            if ($currentPageNumber <= 0){
165
+            if ($currentPageNumber <= 0) {
166 166
 				$currentPageNumber = 1;
167 167
 			}
168 168
             if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) {
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
             $start = null;
172 172
             $end   = null;
173 173
             $begin = null;
174
-            if ($numberOfLink % 2 == 0){
174
+            if ($numberOfLink % 2 == 0) {
175 175
                 $start = $currentPageNumber - ($numberOfLink / 2) + 1;
176 176
                 $end = $currentPageNumber + ($numberOfLink / 2);
177 177
             }
178
-            else{
178
+            else {
179 179
                 $start = $currentPageNumber - floor($numberOfLink / 2);
180 180
                 $end = $currentPageNumber + floor($numberOfLink / 2);
181 181
             }
182
-            if ($start <= 1){
182
+            if ($start <= 1) {
183 183
                 $begin = 1;
184 184
                 $end = $numberOfLink;
185 185
             }
186
-            else if ($start > 1 && $end < $numberOfPage){
186
+            else if ($start > 1 && $end < $numberOfPage) {
187 187
                 $begin = $start;
188 188
                 $end = $end;
189 189
             }
190
-            else{
190
+            else {
191 191
                 $begin = ($numberOfPage - $numberOfLink) + 1;
192 192
                 $end = $numberOfPage;
193 193
             }
194
-            if ($numberOfPage <= $numberOfLink){
194
+            if ($numberOfPage <= $numberOfLink) {
195 195
                 $begin = 1;
196 196
                 $end = $numberOfPage;
197 197
             }
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
             $end = (int) $end;
200 200
 
201 201
             //**
202
-            if ($currentPageNumber == 1){
202
+            if ($currentPageNumber == 1) {
203 203
                 $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber);
204 204
             }
205 205
             ///////////
206
-            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
206
+            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) {
207 207
                 $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber);
208 208
             }
209
-            else if ($currentPageNumber == $numberOfPage){
209
+            else if ($currentPageNumber == $numberOfPage) {
210 210
                $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
211 211
             }
212 212
             $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
          * @param  int $currentPageNumber the pagination current page number
221 221
          * @return string                    
222 222
          */
223
-        protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber){
223
+        protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber) {
224 224
             $navbar = null;
225 225
             $query = $this->paginationQueryString;
226
-            for($i = $begin; $i <= $end; $i++){
227
-                if ($i == $currentPageNumber){
226
+            for ($i = $begin; $i <= $end; $i++) {
227
+                if ($i == $currentPageNumber) {
228 228
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
229 229
                 }
230
-                else{
230
+                else {
231 231
                     $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
232 232
                 }
233 233
             }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
          * @param  int $currentPageNumber the pagination current page number
243 243
          * @return string                    
244 244
          */
245
-        protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber){
245
+        protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber) {
246 246
             $navbar = null;
247 247
             $query = $this->paginationQueryString;
248 248
             $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
249
-            for($i = $begin; $i <= $end; $i++){
250
-                if ($i == $currentPageNumber){
249
+            for ($i = $begin; $i <= $end; $i++) {
250
+                if ($i == $currentPageNumber) {
251 251
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
252 252
                 }
253
-                else{
254
-                    $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
253
+                else {
254
+                    $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
255 255
                 }
256 256
             }
257
-            $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
257
+            $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close'];
258 258
             return $navbar;
259 259
         }
260 260
 
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
          * @param  int $currentPageNumber the pagination current page number
266 266
          * @return string                    
267 267
          */
268
-        protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber){
268
+        protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber) {
269 269
             $navbar = null;
270 270
             $query = $this->paginationQueryString;
271 271
             $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
272
-            for($i = $begin; $i <= $end; $i++){
273
-                if ($i == $currentPageNumber){
272
+            for ($i = $begin; $i <= $end; $i++) {
273
+                if ($i == $currentPageNumber) {
274 274
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
275 275
                 }
276
-                else{
276
+                else {
277 277
                     $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
278 278
                 }
279 279
             }
Please login to merge, or discard this patch.
tests/include/testsUtil.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 	/**
4 4
 	* Function to test private & protected method
5 5
 	*/
6
-	function run_private_protected_method($object, $method, array $args = array()){
6
+	function run_private_protected_method($object, $method, array $args = array()) {
7 7
 		$r = new ReflectionClass(get_class($object));
8 8
 		$m = $r->getMethod($method);
9 9
 		$m->setAccessible(true);
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     /**
14 14
 	* Function to return the correct database configuration
15 15
 	*/
16
-    function get_db_config(){
16
+    function get_db_config() {
17 17
         return array(
18 18
                     'driver'    =>  'sqlite',
19 19
                     'database'  =>  TESTS_PATH . 'assets/db_tests.db',
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 		
14 14
 		private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+		public function __construct() {
17 17
             $cfg = get_db_config();
18 18
 			$this->db = new Database($cfg);
19 19
             $qr = new DatabaseQueryRunner($this->db->getPdo());
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 		
50 50
 		
51
-		public function testUsingSessionConfiguration(){
51
+		public function testUsingSessionConfiguration() {
52 52
 			//using value in the configuration
53 53
 			self::$config->set('session_save_path', 'DBSessionModel');
54 54
 			self::$config->set('session_secret', $this->secret);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
75 75
 		}
76 76
 		
77
-		public function testWhenDataIsExpired(){
77
+		public function testWhenDataIsExpired() {
78 78
 			$dbsh = new DBSessionHandler($this->model);
79 79
 			$dbsh->setSessionSecret($this->secret);
80 80
 			
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$this->assertNull($dbsh->read('foo'));
88 88
 		}
89 89
 		
90
-		public function testWhenDataAlreadyExistDoUpdate(){
90
+		public function testWhenDataAlreadyExistDoUpdate() {
91 91
 			$dbsh = new DBSessionHandler($this->model);
92 92
 			$dbsh->setSessionSecret($this->secret);
93 93
 			
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			$this->assertEquals($dbsh->read('foo'), '445');	
101 101
 		}
102 102
 		
103
-		public function testUsingCustomModelInstance(){
103
+		public function testUsingCustomModelInstance() {
104 104
 			$dbsh = new DBSessionHandler($this->model);
105 105
 			$dbsh->setSessionSecret($this->secret);
106 106
 			
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		}
129 129
 			
130 130
 			
131
-		public function testUsingCustomLogInstance(){
131
+		public function testUsingCustomLogInstance() {
132 132
 			$dbsh = new DBSessionHandler($this->model, new Log());
133 133
 			$dbsh->setSessionSecret($this->secret);
134 134
 			
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
156 156
 		}
157 157
 		
158
-		public function testUsingCustomLoaderInstance(){
158
+		public function testUsingCustomLoaderInstance() {
159 159
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
160 160
 			$dbsh->setSessionSecret($this->secret);
161 161
 			
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		}
184 184
 		
185 185
 		
186
-		public function testWhenModelInsanceIsNotSet(){
186
+		public function testWhenModelInsanceIsNotSet() {
187 187
 			$dbsh = new DBSessionHandler(null, null, new Loader());
188 188
 			$dbsh->setSessionSecret($this->secret);
189 189
 			
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
212 212
 		}
213 213
 		
214
-		public function testWhenModelTableColumnsIsNotSet(){
214
+		public function testWhenModelTableColumnsIsNotSet() {
215 215
 			//session table is empty
216 216
 			$this->model->setSessionTableColumns(array());
217 217
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Spacing   +31 added lines, -31 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 object $logger the log object
58 58
 		 * @return object 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,39 +139,39 @@  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 176
 					$baseUrl = $protocol . $baseUrl . $port . substr(
177 177
 																		$_SERVER['SCRIPT_NAME'], 
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180 180
 																	);
181 181
 				}
182
-				else{
182
+				else {
183 183
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184 184
 					$baseUrl = 'http://localhost/';
185 185
 				}
186 186
 				self::set('base_url', $baseUrl);
187 187
 			}
188
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
188
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
189 189
 		}
190 190
 	}
Please login to merge, or discard this patch.