Test Failed
Push — 1.0.0-dev ( aa6afc...324983 )
by nguereza
04:25
created
tests/include/testsUtil.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 	/**
4 4
 	* Function to test private & protected method
5 5
 	*/
6
-	function runPrivateOrProtectedMethod($object, $method, array $args = array()){
6
+	function runPrivateOrProtectedMethod($object, $method, array $args = array()) {
7 7
 		$r = new ReflectionClass(get_class($object));
8 8
 		$m = $r->getMethod($method);
9 9
 		$m->setAccessible(true);
Please login to merge, or discard this patch.
tests/tnhfw/classes/EventTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 		
27 27
 		
28
-		public function testDefaultValue(){
28
+		public function testDefaultValue() {
29 29
 			$e = new Event('foo');
30 30
 			$this->assertSame($e->name, 'foo');
31 31
 			$this->assertSame($e->payload, array());
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			$this->assertFalse($e->stop);
34 34
 		}
35 35
 		
36
-		public function testPayloadValueIsSet(){
36
+		public function testPayloadValueIsSet() {
37 37
 			$e = new Event('foo', array('bar'));
38 38
 			$this->assertSame($e->name, 'foo');
39 39
 			$this->assertSame($e->payload, array('bar'));
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			$this->assertFalse($e->stop);
42 42
 		}
43 43
 		
44
-		public function testReturnBackValueIsSetToTrue(){
44
+		public function testReturnBackValueIsSetToTrue() {
45 45
 			$e = new Event('foo', array('bar'), true);
46 46
 			$this->assertSame($e->name, 'foo');
47 47
 			$this->assertSame($e->payload, array('bar'));
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			$this->assertFalse($e->stop);
50 50
 		}
51 51
 		
52
-		public function testStopValueIsSetToTue(){
52
+		public function testStopValueIsSetToTue() {
53 53
 			$e = new Event('foo', array('bar'), true, true);
54 54
 			$this->assertSame($e->name, 'foo');
55 55
 			$this->assertSame($e->payload, array('bar'));
Please login to merge, or discard this patch.
tests/tnhfw/classes/SessionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 			$this->assertEquals('bar', Session::get('foo'));
31 31
 		}
32 32
 		
33
-		public function testExc(){
33
+		public function testExc() {
34 34
 			 //$this->expectException(InvalidArgumentException::class);
35 35
 		}
36 36
 	}
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
core/common.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 		//put the first letter of class to upper case 
54 54
 		$class = ucfirst($class);
55 55
 		static $classes = array();
56
-		if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
56
+		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') {
57 57
 			return $classes[$class];
58 58
 		}
59 59
 		$found = false;
60 60
 		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
61 61
 			$file = $path . $dir . '/' . $class . '.php';
62
-			if(file_exists($file)){
63
-				if(class_exists($class, false) == false){
62
+			if (file_exists($file)) {
63
+				if (class_exists($class, false) == false) {
64 64
 					require_once $file;
65 65
 				}
66 66
 				//already found
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 				break;
69 69
 			}
70 70
 		}
71
-		if(! $found){
71
+		if (!$found) {
72 72
 			//can't use show_error() at this time because some dependencies not yet loaded
73 73
 			set_http_status_header(503);
74 74
 			echo 'Cannot find the class [' . $class . ']';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		/*
79 79
 		   TODO use the best method to get the Log instance
80 80
 		 */
81
-		if($class == 'Log'){
81
+		if ($class == 'Log') {
82 82
 			//can't use the instruction like "return new Log()" 
83 83
 			//because we need return the reference instance of the loaded class.
84 84
 			$log = new Log();
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	function & class_loaded($class = null){
104 104
 		static $list = array();
105
-		if($class != null){
105
+		if ($class != null) {
106 106
 			$list[strtolower($class)] = $class;
107 107
 		}
108 108
 		return $list;
@@ -117,22 +117,22 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	function & load_configurations(array $overwrite_values = array()){
119 119
 		static $config;
120
-		if(empty($config)){
120
+		if (empty($config)) {
121 121
 			$file = CONFIG_PATH . 'config.php';
122 122
 			$found = false;
123
-			if(file_exists($file)){
123
+			if (file_exists($file)) {
124 124
 				require_once $file;
125 125
 				$found = true;
126 126
 			}
127
-			if(! $found){
127
+			if (!$found) {
128 128
 				set_http_status_header(503);
129 129
 				echo 'Unable to find the configuration file [' . $file . ']';
130 130
 				exit(1);
131 131
 			}
132 132
 
133
-			if(! isset($config) || !is_array($config)){
133
+			if (!isset($config) || !is_array($config)) {
134 134
 				set_http_status_header(503);
135
-				echo 'No configuration found in file ['  . $file . ']';
135
+				echo 'No configuration found in file [' . $file . ']';
136 136
 				exit(1);
137 137
 			}
138 138
 		}
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 	 * 
151 151
 	 * @return mixed          the config value
152 152
 	 */
153
-	function get_config($key, $default = null){
153
+	function get_config($key, $default = null) {
154 154
 		static $cfg;
155
-		if(empty($cfg)){
155
+		if (empty($cfg)) {
156 156
 			$cfg[0] = & load_configurations();
157 157
 		}
158 158
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
 	 * 
167 167
 	 * @codeCoverageIgnore
168 168
 	 */
169
-	function save_to_log($level, $message, $logger = null){
170
-		$log =& class_loader('Log', 'classes');
171
-		if($logger){
169
+	function save_to_log($level, $message, $logger = null) {
170
+		$log = & class_loader('Log', 'classes');
171
+		if ($logger) {
172 172
 			$log->setLogger($logger);
173 173
 		}
174 174
 		$log->writeLog($message, $level);
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 	 * 
182 182
 	 * @codeCoverageIgnore
183 183
 	 */
184
-	function set_http_status_header($code = 200, $text = null){
185
-		if(! $code || !is_numeric($code)){
184
+	function set_http_status_header($code = 200, $text = null) {
185
+		if (!$code || !is_numeric($code)) {
186 186
 			show_error('HTTP status code must be an integer');
187 187
 		}
188
-		if(empty($text)){
188
+		if (empty($text)) {
189 189
 			$code = abs($code);
190 190
 			$http_status = array(
191 191
 								100 => 'Continue',
@@ -234,18 +234,18 @@  discard block
 block discarded – undo
234 234
 								504 => 'Gateway Timeout',
235 235
 								505 => 'HTTP Version Not Supported',
236 236
 							);
237
-			if(isset($http_status[$code])){
237
+			if (isset($http_status[$code])) {
238 238
 				$text = $http_status[$code];
239 239
 			}
240
-			else{
240
+			else {
241 241
 				show_error('No HTTP status text found for your code please check it.');
242 242
 			}
243 243
 		}
244 244
 		
245
-		if(strpos(php_sapi_name(), 'cgi') === 0){
245
+		if (strpos(php_sapi_name(), 'cgi') === 0) {
246 246
 			header('Status: ' . $code . ' ' . $text, TRUE);
247 247
 		}
248
-		else{
248
+		else {
249 249
 			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
250 250
 			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
251 251
 		}
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 	 *  
261 261
 	 *  @codeCoverageIgnore
262 262
 	 */
263
-	function show_error($msg, $title = 'error', $logging = true){
263
+	function show_error($msg, $title = 'error', $logging = true) {
264 264
 		$title = strtoupper($title);
265 265
 		$data['error'] = $msg;
266 266
 		$data['title'] = $title;
267
-		if($logging){
268
-			save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
267
+		if ($logging) {
268
+			save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR');
269 269
 		}
270 270
 		$response = & class_loader('Response', 'classes');
271 271
 		$response->sendError($data);
@@ -279,18 +279,18 @@  discard block
 block discarded – undo
279 279
 	 *  
280 280
 	 *  @return boolean true if the web server uses the https protocol, false if not.
281 281
 	 */
282
-	function is_https(){
282
+	function is_https() {
283 283
 		/*
284 284
 		* some servers pass the "HTTPS" parameter in the server variable,
285 285
 		* if is the case, check if the value is "on", "true", "1".
286 286
 		*/
287
-		if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
287
+		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
288 288
 			return true;
289 289
 		}
290
-		else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
290
+		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
291 291
 			return true;
292 292
 		}
293
-		else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
293
+		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
294 294
 			return true;
295 295
 		}
296 296
 		return false;
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 *  
306 306
 	 *  @return boolean true if is a valid URL address or false.
307 307
 	 */
308
-	function is_url($url){
308
+	function is_url($url) {
309 309
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url);
310 310
 	}
311 311
 	
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
 	 *  @param string $controllerClass the controller class name to be loaded
316 316
 	 *  @codeCoverageIgnore
317 317
 	 */
318
-	function autoload_controller($controllerClass){
319
-		if(file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
318
+	function autoload_controller($controllerClass) {
319
+		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) {
320 320
 			require_once $path;
321 321
 		}
322 322
 	}
@@ -330,11 +330,11 @@  discard block
 block discarded – undo
330 330
 	 *  
331 331
 	 *  @return boolean
332 332
 	 */
333
-	function php_exception_handler($ex){
334
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
335
-			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
333
+	function php_exception_handler($ex) {
334
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
335
+			show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
336 336
 		}
337
-		else{
337
+		else {
338 338
 			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
339 339
 		}
340 340
 		exit(1);
@@ -353,16 +353,16 @@  discard block
 block discarded – undo
353 353
 	 *  
354 354
 	 *  @return boolean	
355 355
 	 */
356
-	function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){
356
+	function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) {
357 357
 		$isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
358
-		if($isError){
358
+		if ($isError) {
359 359
 			set_http_status_header(500);
360 360
 		}
361
-		if (! (error_reporting() & $errno)) {
361
+		if (!(error_reporting() & $errno)) {
362 362
 			save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ' . $error_type, 'PHP ERROR');
363 363
 			return;
364 364
 		}
365
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
365
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
366 366
 			$errorType = 'error';
367 367
 			switch ($errno) {
368 368
 				case E_USER_ERROR:
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 					$errorType = 'error';
379 379
 					break;
380 380
 			}
381
-			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
381
+			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType);
382 382
 		}
383
-		if ($isError){
383
+		if ($isError) {
384 384
 			exit(1);
385 385
 		}
386 386
 		return true;
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 	 * This function is used to run in shutdown situation of the script
391 391
 	 * @codeCoverageIgnore
392 392
 	 */
393
-	function php_shudown_handler(){
393
+	function php_shudown_handler() {
394 394
 		$lastError = error_get_last();
395 395
 		if (isset($lastError) &&
396
-			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
396
+			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) {
397 397
 			php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
398 398
 		}
399 399
 	}
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
 	 *   
413 413
 	 *  @return string string of the HTML attribute.
414 414
 	 */
415
-	function attributes_to_string(array $attributes){
415
+	function attributes_to_string(array $attributes) {
416 416
 		$str = ' ';
417 417
 		//we check that the array passed as an argument is not empty.
418
-		if(! empty($attributes)){
419
-			foreach($attributes as $key => $value){
418
+		if (!empty($attributes)) {
419
+			foreach ($attributes as $key => $value) {
420 420
 				$key = trim(htmlspecialchars($key));
421 421
 				$value = trim(htmlspecialchars($value));
422 422
 				/*
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
 				* 	$attr = array('placeholder' => 'I am a "puple"')
427 427
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
428 428
 				 */
429
-				if($value && strpos('"', $value) !== false){
429
+				if ($value && strpos('"', $value) !== false) {
430 430
 					$value = addslashes($value);
431 431
 				}
432
-				$str .= $key.' = "'.$value.'" ';
432
+				$str .= $key . ' = "' . $value . '" ';
433 433
 			}
434 434
 		}
435 435
 		//remove the space after using rtrim()
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	*
446 446
 	* @return string the stringfy value
447 447
 	*/
448
-	function stringfy_vars($var){
448
+	function stringfy_vars($var) {
449 449
 		return print_r($var, true);
450 450
 	}
451 451
 
@@ -456,18 +456,18 @@  discard block
 block discarded – undo
456 456
 	 * 
457 457
 	 * @return mixed   the sanitize value
458 458
 	 */
459
-	function clean_input($str){
460
-		if(is_array($str)){
459
+	function clean_input($str) {
460
+		if (is_array($str)) {
461 461
 			$str = array_map('clean_input', $str);
462 462
 		}
463
-		else if(is_object($str)){
463
+		else if (is_object($str)) {
464 464
 			$obj = $str;
465 465
 			foreach ($str as $var => $value) {
466 466
 				$obj->$var = clean_input($value);
467 467
 			}
468 468
 			$str = $obj;
469 469
 		}
470
-		else{
470
+		else {
471 471
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
472 472
 		}
473 473
 		return $str;
@@ -485,11 +485,11 @@  discard block
 block discarded – undo
485 485
 	 * 
486 486
 	 * @return string the string with the hidden part.
487 487
 	 */
488
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
488
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
489 489
 		//get the string length
490 490
 		$len = strlen($str);
491 491
 		//if str is empty
492
-		if($len <= 0){
492
+		if ($len <= 0) {
493 493
 			return str_repeat($hiddenChar, 6);
494 494
 		}
495 495
 		//if the length is less than startCount and endCount
@@ -497,14 +497,14 @@  discard block
 block discarded – undo
497 497
 		//or startCount is negative or endCount is negative
498 498
 		//return the full string hidden
499 499
 		
500
-		if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
500
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
501 501
 			return str_repeat($hiddenChar, $len);
502 502
 		}
503 503
 		//the start non hidden string
504 504
 		$startNonHiddenStr = substr($str, 0, $startCount);
505 505
 		//the end non hidden string
506 506
 		$endNonHiddenStr = null;
507
-		if($endCount > 0){
507
+		if ($endCount > 0) {
508 508
 			$endNonHiddenStr = substr($str, - $endCount);
509 509
 		}
510 510
 		//the hidden string
@@ -517,31 +517,31 @@  discard block
 block discarded – undo
517 517
 	 * This function is used to set the initial session config regarding the configuration
518 518
 	 * @codeCoverageIgnore
519 519
 	 */
520
-	function set_session_config(){
520
+	function set_session_config() {
521 521
 		//$_SESSION is not available on cli mode 
522
-		if(! IS_CLI){
523
-			$logger =& class_loader('Log', 'classes');
522
+		if (!IS_CLI) {
523
+			$logger = & class_loader('Log', 'classes');
524 524
 			$logger->setLogger('PHPSession');
525 525
 			//set session params
526 526
 			$sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
527 527
 			$sessionName = get_config('session_name');
528
-			if($sessionName){
528
+			if ($sessionName) {
529 529
 				session_name($sessionName);
530 530
 			}
531 531
 			$logger->info('Session handler: ' . $sessionHandler);
532 532
 			$logger->info('Session name: ' . $sessionName);
533 533
 
534
-			if($sessionHandler == 'files'){
534
+			if ($sessionHandler == 'files') {
535 535
 				$sessionSavePath = get_config('session_save_path');
536
-				if($sessionSavePath){
537
-					if(! is_dir($sessionSavePath)){
536
+				if ($sessionSavePath) {
537
+					if (!is_dir($sessionSavePath)) {
538 538
 						mkdir($sessionSavePath, 1773);
539 539
 					}
540 540
 					session_save_path($sessionSavePath);
541 541
 					$logger->info('Session save path: ' . $sessionSavePath);
542 542
 				}
543 543
 			}
544
-			else if($sessionHandler == 'database'){
544
+			else if ($sessionHandler == 'database') {
545 545
 				//load database session handle library
546 546
 				//Model
547 547
 				require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
 				//Database Session handler Model
550 550
 				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
551 551
 
552
-				$DBS =& class_loader('DBSessionHandler', 'classes');
552
+				$DBS = & class_loader('DBSessionHandler', 'classes');
553 553
 				session_set_save_handler($DBS, true);
554 554
 				$logger->info('session save path: ' . get_config('session_save_path'));
555 555
 			}
556
-			else{
556
+			else {
557 557
 				show_error('Invalid session handler configuration');
558 558
 			}
559 559
 			$lifetime = get_config('session_cookie_lifetime', 0);
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
 			$logger->info('Session lifetime: ' . $lifetime);
577 577
 			$logger->info('Session cookie path: ' . $path);
578 578
 			$logger->info('Session domain: ' . $domain);
579
-			$logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
579
+			$logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE'));
580 580
 			
581
-			if((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
581
+			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) {
582 582
 				$logger->info('Session not yet start, start it now');
583 583
 				session_start();
584 584
 			}
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
44
+	if (!function_exists('get_ip')) {
45 45
 		/**
46 46
 		 *  Retrieves the user's IP address
47 47
 		 *  
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 *  
51 51
 		 *  @return string the IP address.
52 52
 		 */
53
-		function get_ip(){
53
+		function get_ip() {
54 54
 			$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
55 55
 
56 56
 			if (isset($_SERVER["HTTP_CLIENT_IP"])) {
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
84
+		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) {
85 85
 			/**
86 86
 	         * instance of the Log class
87 87
 	         */
88
-	        if(is_object($logger)){
88
+	        if (is_object($logger)) {
89 89
 	          $this->setLogger($logger);
90 90
 	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
91
+	        else {
92
+	            $this->logger = & class_loader('Log', 'classes');
93 93
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 94
 	        }
95 95
 
96
-	        if(is_object($loader)){
96
+	        if (is_object($loader)) {
97 97
 	          $this->setLoader($loader);
98 98
 	        }
99 99
 		    $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
102
+			if (is_object($modelInstance)) {
103 103
 				$this->setModelInstance($modelInstance);
104 104
 			}
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		 * Set the session secret used to encrypt the data in database 
109 109
 		 * @param string $secret the base64 string secret
110 110
 		 */
111
-		public function setSessionSecret($secret){
111
+		public function setSessionSecret($secret) {
112 112
 			$this->sessionSecret = $secret;
113 113
 			return $this;
114 114
 		}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Return the session secret
118 118
 		 * @return string 
119 119
 		 */
120
-		public function getSessionSecret(){
120
+		public function getSessionSecret() {
121 121
 			return $this->sessionSecret;
122 122
 		}
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * Set the initializer vector for openssl 
127 127
 		 * @param string $key the session secret used
128 128
 		 */
129
-		public function setInitializerVector($key){
129
+		public function setInitializerVector($key) {
130 130
 			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131 131
 			$key = base64_decode($key);
132 132
 			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * Return the initializer vector
138 138
 		 * @return string 
139 139
 		 */
140
-		public function getInitializerVector(){
140
+		public function getInitializerVector() {
141 141
 			return $this->iv;
142 142
 		}
143 143
 
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
 		 * @param  string $sessionName the session name
148 148
 		 * @return boolean 
149 149
 		 */
150
-		public function open($savePath, $sessionName){
150
+		public function open($savePath, $sessionName) {
151 151
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152 152
 			//try to check if session secret is set before
153
-			if(! $this->getSessionSecret()){
153
+			if (!$this->getSessionSecret()) {
154 154
 				$secret = get_config('session_secret', false);
155 155
 				$this->setSessionSecret($secret);
156 156
 			}
157 157
 			$this->logger->info('Session secret: ' . $this->getSessionSecret());
158 158
 
159
-			if(! $this->getModelInstance()){
159
+			if (!$this->getModelInstance()) {
160 160
 				$this->setModelInstanceFromConfig();
161 161
 			}
162 162
 			$this->setInitializerVector($this->getSessionSecret());
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			//set session tables columns
165 165
 			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
166 166
 
167
-			if(empty($this->sessionTableColumns)){
167
+			if (empty($this->sessionTableColumns)) {
168 168
 				show_error('The session handler is "database" but the table columns not set');
169 169
 			}
170 170
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		 * Close the session
181 181
 		 * @return boolean
182 182
 		 */
183
-		public function close(){
183
+		public function close() {
184 184
 			$this->logger->debug('Closing database session handler');
185 185
 			return true;
186 186
 		}
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
 		 * @param  string $sid the session id to use
191 191
 		 * @return mixed      the session data in serialiaze format
192 192
 		 */
193
-		public function read($sid){
193
+		public function read($sid) {
194 194
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
195 195
 			$instance = $this->getModelInstance();
196 196
 			$columns = $this->sessionTableColumns;
197
-			if($this->getLoader()){
197
+			if ($this->getLoader()) {
198 198
 				$this->getLoader()->functions('user_agent'); 
199 199
 				$this->getLoader()->library('Browser'); 
200 200
 			}
201
-			else{
201
+			else {
202 202
             	Loader::functions('user_agent');
203 203
             	Loader::library('Browser');
204 204
             }
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 			$ip = get_ip();
207 207
 			$keyValue = $instance->getKeyValue();
208 208
 			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
209
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
210 210
 			
211 211
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
212
+			if ($data && isset($data->{$columns['sdata']})) {
213 213
 				//checking inactivity 
214 214
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
215
+				if ($data->{$columns['stime']} < $timeInactivity) {
216 216
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217 217
 					$this->destroy($sid);
218 218
 					return false;
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 		 * @param  mixed $data the session data to save in serialize format
230 230
 		 * @return boolean 
231 231
 		 */
232
-		public function write($sid, $data){
232
+		public function write($sid, $data) {
233 233
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234 234
 			$instance = $this->getModelInstance();
235 235
 			$columns = $this->sessionTableColumns;
236 236
 
237
-			if($this->getLoader()){
237
+			if ($this->getLoader()) {
238 238
 				$this->getLoader()->functions('user_agent'); 
239 239
 				$this->getLoader()->library('Browser'); 
240 240
 			}
241
-			else{
241
+			else {
242 242
             	Loader::functions('user_agent');
243 243
             	Loader::library('Browser');
244 244
             }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			$ip = get_ip();
247 247
 			$keyValue = $instance->getKeyValue();
248 248
 			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
249
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
250 250
 			$data = $this->encode($data);
251 251
 			$params = array(
252 252
 							$columns['sid'] => $sid,
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 						);
260 260
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261 261
 			$exists = $instance->get($sid);
262
-			if($exists){
262
+			if ($exists) {
263 263
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264 264
 				//update
265 265
 				unset($params[$columns['sid']]);
266 266
 				$instance->update($sid, $params);
267 267
 			}
268
-			else{
268
+			else {
269 269
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 270
 				$instance->insert($params);
271 271
 			}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		 * @param  string $sid the session id value
279 279
 		 * @return boolean
280 280
 		 */
281
-		public function destroy($sid){
281
+		public function destroy($sid) {
282 282
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283 283
 			$instance = $this->modelInstanceName;
284 284
 			$instance->delete($sid);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		 * @param  ineteger $maxLifetime the max lifetime
291 291
 		 * @return boolean
292 292
 		 */
293
-		public function gc($maxLifetime){
293
+		public function gc($maxLifetime) {
294 294
 			$instance = $this->modelInstanceName;
295 295
 			$time = time() - $maxLifetime;
296 296
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 		 * @param  mixed $data the session data to encode
304 304
 		 * @return mixed the encoded session data
305 305
 		 */
306
-		public function encode($data){
306
+		public function encode($data) {
307 307
 			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
308
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309 309
 			$output = base64_encode($dataEncrypted);
310 310
 			return $output;
311 311
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		 * @param  mixed $data the data to decode
317 317
 		 * @return mixed       the decoded data
318 318
 		 */
319
-		public function decode($data){
319
+		public function decode($data) {
320 320
 			$key = base64_decode($this->sessionSecret);
321 321
 			$data = base64_decode($data);
322 322
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
          * Return the loader instance
329 329
          * @return Loader the loader instance
330 330
          */
331
-        public function getLoader(){
331
+        public function getLoader() {
332 332
             return $this->loader;
333 333
         }
334 334
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+         public function setLoader($loader) {
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
          * Return the model instance
346 346
          * @return DBSessionHandlerModel the model instance
347 347
          */
348
-        public function getModelInstance(){
348
+        public function getModelInstance() {
349 349
             return $this->modelInstanceName;
350 350
         }
351 351
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	     * Return the Log instance
363 363
 	     * @return Log
364 364
 	     */
365
-	    public function getLogger(){
365
+	    public function getLogger() {
366 366
 	      return $this->logger;
367 367
 	    }
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	     * Set the log instance
371 371
 	     * @param Log $logger the log object
372 372
 	     */
373
-	    public function setLogger(Log $logger){
373
+	    public function setLogger(Log $logger) {
374 374
 	      $this->logger = $logger;
375 375
 	      return $this;
376 376
 	    }
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
 	    /**
379 379
 	     * Set the model instance using the configuration for session
380 380
 	     */
381
-	    private function setModelInstanceFromConfig(){
381
+	    private function setModelInstanceFromConfig() {
382 382
 	    	$modelName = get_config('session_save_path');
383 383
 			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
384
+			if ($this->getLoader()) {
385 385
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386 386
 			}
387 387
 			//@codeCoverageIgnoreStart
388
-			else{
388
+			else {
389 389
             	Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
391
+            if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) {
392
+				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
393 393
 			}  
394 394
 			//@codeCoverageIgnoreEnd
395 395
 			
Please login to merge, or discard this patch.
core/classes/model/DBSessionHandlerModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		 */
46 46
 		protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(Database $db = null){
48
+		public function __construct(Database $db = null) {
49 49
 			parent::__construct($db);
50 50
 		}
51 51
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		 * Return the session database table columns
54 54
 		 * @return array 
55 55
 		 */
56
-		public function getSessionTableColumns(){
56
+		public function getSessionTableColumns() {
57 57
 			return $this->sessionTableColumns;
58 58
 		}
59 59
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		 * Set the session database table columns
62 62
 		 * @param array $columns the columns definition
63 63
 		 */
64
-		public function setSessionTableColumns(array $columns){
64
+		public function setSessionTableColumns(array $columns) {
65 65
 			$this->sessionTableColumns = $columns;
66 66
 			return $this;
67 67
 		}
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34 34
      */
35 35
 
36
-    class Model{
36
+    class Model {
37 37
 
38 38
         /* --------------------------------------------------------------
39 39
          * VARIABLES
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
          * Initialise the model, tie into the CodeIgniter superobject and
141 141
          * try our best to guess the table name.
142 142
          */
143
-        public function __construct(Database $db = null){
144
-            if(is_object($db)){
143
+        public function __construct(Database $db = null) {
144
+            if (is_object($db)) {
145 145
                 $this->setDatabaseInstance($db);
146 146
             }
147
-            else{
147
+            else {
148 148
                 $obj = & get_instance();
149
-        		if(isset($obj->database) && is_object($obj->database)){
149
+        		if (isset($obj->database) && is_object($obj->database)) {
150 150
                     /**
151 151
                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152 152
                     * to prevent duplication
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 
183 183
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184 184
             {
185
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
185
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
186 186
             }
187 187
 
188 188
     		$this->_set_where($where);
189 189
 
190 190
             $this->trigger('before_get');
191
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
191
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
192 192
             $row = $this->_database->from($this->_table)->get($type);
193 193
             $this->_temporary_return_type = $this->return_type;
194 194
             $row = $this->trigger('after_get', $row);
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
             $this->trigger('before_get');
225 225
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226 226
             {
227
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
227
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
228 228
             }
229
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
229
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
230 230
             $result = $this->_database->from($this->_table)->getAll($type);
231 231
             $this->_temporary_return_type = $this->return_type;
232 232
 
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
         {
333 333
             $args = func_get_args();
334 334
             $data = array();
335
-            if(count($args) == 2){
336
-                if(is_array($args[1])){
335
+            if (count($args) == 2) {
336
+                if (is_array($args[1])) {
337 337
                     $data = array_pop($args);
338 338
                 }
339 339
             }
340
-            else if(count($args) == 3){
341
-                if(is_array($args[2])){
340
+            else if (count($args) == 3) {
341
+                if (is_array($args[2])) {
342 342
                     $data = array_pop($args);
343 343
                 }
344 344
             }
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
             $this->_database->where($this->primary_key, $id);
377 377
             if ($this->soft_delete)
378 378
             {
379
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
379
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
380 380
             }
381 381
             else
382 382
             {
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
             $this->_set_where($where);
398 398
             if ($this->soft_delete)
399 399
             {
400
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
400
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
401 401
             }
402 402
             else
403 403
             {
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
             $this->_database->in($this->primary_key, $primary_values);
417 417
             if ($this->soft_delete)
418 418
             {
419
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
419
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
420 420
             }
421 421
             else
422 422
             {
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
                 if (is_string($value))
463 463
                 {
464 464
                     $relationship = $value;
465
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
465
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
466 466
                 }
467 467
                 else
468 468
                 {
@@ -472,10 +472,10 @@  discard block
 block discarded – undo
472 472
 
473 473
                 if (in_array($relationship, $this->_with))
474 474
                 {
475
-                    if(is_object($this->loaderInstance)){
475
+                    if (is_object($this->loaderInstance)) {
476 476
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
477 477
                     }
478
-                    else{
478
+                    else {
479 479
                         Loader::model($options['model'], $relationship . '_model');    
480 480
                     }
481 481
                     if (is_object($row))
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
                 if (is_string($value))
495 495
                 {
496 496
                     $relationship = $value;
497
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
497
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
498 498
                 }
499 499
                 else
500 500
                 {
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 
505 505
                 if (in_array($relationship, $this->_with))
506 506
                 {
507
-                    if(is_object($this->loaderInstance)){
507
+                    if (is_object($this->loaderInstance)) {
508 508
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
509 509
                     }
510
-                    else{
510
+                    else {
511 511
                         Loader::model($options['model'], $relationship . '_model');    
512 512
                     }
513 513
                     if (is_object($row))
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
         public function dropdown()
534 534
         {
535 535
             $args = func_get_args();
536
-            if(count($args) == 2)
536
+            if (count($args) == 2)
537 537
             {
538 538
                 list($key, $value) = $args;
539 539
             }
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
                 $key = $this->primary_key;
543 543
                 $value = $args[0];
544 544
             }
545
-            $this->trigger('before_dropdown', array( $key, $value ));
545
+            $this->trigger('before_dropdown', array($key, $value));
546 546
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547 547
             {
548 548
                 $this->_database->where($this->soft_delete_key, FALSE);
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
         {
567 567
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568 568
             {
569
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
569
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
570 570
             }
571 571
             $where = func_get_args();
572 572
             $this->_set_where($where);
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
         {
582 582
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583 583
             {
584
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
584
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
585 585
             }
586 586
             $this->_database->from($this->_table)->getAll();
587 587
             return $this->_database->numRows();
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 		/**
591 591
 		* Enabled cache temporary
592 592
 		*/
593
-		public function cached($ttl = 0){
594
-		  if($ttl > 0){
593
+		public function cached($ttl = 0) {
594
+		  if ($ttl > 0) {
595 595
 			$this->_database = $this->_database->cached($ttl);
596 596
 		  }
597 597
 		  return $this;
@@ -745,13 +745,13 @@  discard block
 block discarded – undo
745 745
             {
746 746
                 if (is_object($row))
747 747
                 {
748
-					if(isset($row->$attr)){
748
+					if (isset($row->$attr)) {
749 749
 						unset($row->$attr);
750 750
 					}
751 751
                 }
752 752
                 else
753 753
                 {
754
-					if(isset($row[$attr])){
754
+					if (isset($row[$attr])) {
755 755
 						unset($row[$attr]);
756 756
 					}
757 757
                 }
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
          * Return the database instance
764 764
          * @return Database the database instance
765 765
          */
766
-        public function getDatabaseInstance(){
766
+        public function getDatabaseInstance() {
767 767
             return $this->_database;
768 768
         }
769 769
 
@@ -771,9 +771,9 @@  discard block
 block discarded – undo
771 771
          * set the Database instance for future use
772 772
          * @param Database $db the database object
773 773
          */
774
-         public function setDatabaseInstance($db){
774
+         public function setDatabaseInstance($db) {
775 775
             $this->_database = $db;
776
-            if($this->dbCacheTime > 0){
776
+            if ($this->dbCacheTime > 0) {
777 777
                 $this->_database->setCache($this->dbCacheTime);
778 778
             }
779 779
             return $this;
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
          * Return the loader instance
784 784
          * @return Loader the loader instance
785 785
          */
786
-        public function getLoader(){
786
+        public function getLoader() {
787 787
             return $this->loaderInstance;
788 788
         }
789 789
 
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
          * set the loader instance for future use
792 792
          * @param Loader $loader the loader object
793 793
          */
794
-         public function setLoader($loader){
794
+         public function setLoader($loader) {
795 795
             $this->loaderInstance = $loader;
796 796
             return $this;
797 797
         }
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
          * Return the FormValidation instance
801 801
          * @return FormValidation the form validation instance
802 802
          */
803
-        public function getFormValidation(){
803
+        public function getFormValidation() {
804 804
             return $this->formValidationInstance;
805 805
         }
806 806
 
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
          * set the form validation instance for future use
809 809
          * @param FormValidation $fv the form validation object
810 810
          */
811
-         public function setFormValidation($fv){
811
+         public function setFormValidation($fv) {
812 812
             $this->formValidationInstance = $fv;
813 813
             return $this;
814 814
         }
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
          */
823 823
         public function order_by($criteria, $order = 'ASC')
824 824
         {
825
-            if ( is_array($criteria) )
825
+            if (is_array($criteria))
826 826
             {
827 827
                 foreach ($criteria as $key => $value)
828 828
                 {
@@ -878,22 +878,22 @@  discard block
 block discarded – undo
878 878
          */
879 879
         protected function validate(array $data)
880 880
         {
881
-            if($this->skip_validation)
881
+            if ($this->skip_validation)
882 882
             {
883 883
                 return $data;
884 884
             }
885
-            if(!empty($this->validate))
885
+            if (!empty($this->validate))
886 886
             {
887 887
                 $fv = null;
888
-                if(is_object($this->formValidationInstance)){
888
+                if (is_object($this->formValidationInstance)) {
889 889
                     $fv = $this->formValidationInstance;
890 890
                 }
891
-                else{
891
+                else {
892 892
                     Loader::library('FormValidation');
893 893
                     $fv = $this->formvalidation;
894 894
                     $this->setFormValidation($fv);
895 895
                 }
896
-                if(is_array($this->validate))
896
+                if (is_array($this->validate))
897 897
                 {
898 898
                     $fv->setData($data);
899 899
                     $fv->setRules($this->validate);
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
             {
949 949
                 $this->_database->where($params[0]);
950 950
             }
951
-        	else if(count($params) == 2)
951
+        	else if (count($params) == 2)
952 952
     		{
953 953
                 if (is_array($params[1]))
954 954
                 {
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
                     $this->_database->where($params[0], $params[1]);
960 960
                 }
961 961
     		}
962
-    		else if(count($params) == 3)
962
+    		else if (count($params) == 3)
963 963
     		{
964 964
     			$this->_database->where($params[0], $params[1], $params[2]);
965 965
     		}
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
         /**
980 980
             Shortcut to controller
981 981
         */
982
-        public function __get($key){
982
+        public function __get($key) {
983 983
             return get_instance()->{$key};
984 984
         }
985 985
 
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Spacing   +29 added lines, -29 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,9 +42,9 @@  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(static::$logger == null){
47
-				$logger[0] =& class_loader('Log', 'classes');
45
+		private static function getLogger() {
46
+			if (static::$logger == null) {
47
+				$logger[0] = & class_loader('Log', 'classes');
48 48
 				$logger[0]->setLogger('Library::Config');
49 49
 				static::$logger = $logger[0];
50 50
 			}
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		 * @param Log $logger the log object
57 57
 		 * @return Log the log instance
58 58
 		 */
59
-		public static function setLogger($logger){
59
+		public static function setLogger($logger) {
60 60
 			static::$logger = $logger;
61 61
 			return static::$logger;
62 62
 		}
@@ -64,35 +64,35 @@  discard block
 block discarded – undo
64 64
 		/**
65 65
 		 * Initialize the configuration by loading all the configuration from config file
66 66
 		 */
67
-		public static function init(){
67
+		public static function init() {
68 68
 			$logger = static::getLogger();
69 69
 			$logger->debug('Initialization of the configuration');
70 70
 			static::$config = & load_configurations();
71
-			if(! static::$config['base_url'] || ! is_url(static::$config['base_url'])){
72
-				if(ENVIRONMENT == 'production'){
71
+			if (!static::$config['base_url'] || !is_url(static::$config['base_url'])) {
72
+				if (ENVIRONMENT == 'production') {
73 73
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
74 74
 				}
75 75
 				$baseUrl = null;
76
-				if (isset($_SERVER['SERVER_ADDR'])){
76
+				if (isset($_SERVER['SERVER_ADDR'])) {
77 77
 					//check if the server is running under IPv6
78
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
79
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
78
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
79
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
80 80
 					}
81
-					else{
81
+					else {
82 82
 						$baseUrl = $_SERVER['SERVER_ADDR'];
83 83
 					}
84
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
85
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
84
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
85
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
86 86
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
87 87
 				}
88
-				else{
88
+				else {
89 89
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
90 90
 					$baseUrl = 'http://localhost/';
91 91
 				}
92 92
 				self::set('base_url', $baseUrl);
93 93
 			}
94
-			static::$config['base_url'] = rtrim(static::$config['base_url'], '/') .'/';
95
-			if(ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info','all'))){
94
+			static::$config['base_url'] = rtrim(static::$config['base_url'], '/') . '/';
95
+			if (ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info', 'all'))) {
96 96
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
97 97
 			}
98 98
 			$logger->info('Configuration initialized successfully');
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 		 * @param  mixed $default the default value to use if can not find the config item in the list
106 106
 		 * @return mixed          the config value if exist or the default value
107 107
 		 */
108
-		public static function get($item, $default = null){
108
+		public static function get($item, $default = null) {
109 109
 			$logger = static::getLogger();
110
-			if(array_key_exists($item, static::$config)){
110
+			if (array_key_exists($item, static::$config)) {
111 111
 				return static::$config[$item];
112 112
 			}
113
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
113
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
114 114
 			return $default;
115 115
 		}
116 116
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		 * @param string $item  the config item name to set
120 120
 		 * @param mixed $value the config item value
121 121
 		 */
122
-		public static function set($item, $value){
122
+		public static function set($item, $value) {
123 123
 			static::$config[$item] = $value;
124 124
 		}
125 125
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		 * Get all the configuration values
128 128
 		 * @return array the config values
129 129
 		 */
130
-		public static function getAll(){
130
+		public static function getAll() {
131 131
 			return static::$config;
132 132
 		}
133 133
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		 * Set the configuration values bu merged with the existing configuration
136 136
 		 * @param array $config the config values to add in the configuration list
137 137
 		 */
138
-		public static function setAll(array $config = array()){
138
+		public static function setAll(array $config = array()) {
139 139
 			static::$config = array_merge(static::$config, $config);
140 140
 		}
141 141
 
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
 		 * @param  string $item the config item name to be deleted
145 145
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
146 146
 		 */
147
-		public static function delete($item){
147
+		public static function delete($item) {
148 148
 			$logger = static::getLogger();
149
-			if(array_key_exists($item, static::$config)){
150
-				$logger->info('Delete config item ['.$item.']');
149
+			if (array_key_exists($item, static::$config)) {
150
+				$logger->info('Delete config item [' . $item . ']');
151 151
 				unset(static::$config[$item]);
152 152
 				return true;
153 153
 			}
154
-			else{
155
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
154
+			else {
155
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
156 156
 				return false;
157 157
 			}
158 158
 		}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		 * Load the configuration file. This an alias to Loader::config()
162 162
 		 * @param  string $config the config name to be loaded
163 163
 		 */
164
-		public static function load($config){
164
+		public static function load($config) {
165 165
 			Loader::config($config);
166 166
 		}
167 167
 	}
Please login to merge, or discard this patch.