Passed
Push — 1.0.0-dev ( ead601...e21083 )
by nguereza
04:39
created
tests/bootstrap.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	* Custom application path for tests 
62 62
 	*/
63
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
63
+	define('APPS_PATH', TESTS_PATH . 'hmvc' . DS);
64 64
 
65 65
 	/**
66 66
 	* The path to the controller directory of your application.
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
197 197
 	* in HMVC architecture (hierichical, controllers, models, views).
198 198
 	*/
199
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
199
+	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS);
200 200
 
201 201
 	/**
202 202
 	* The path to the directory of sources external to your application.
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
 	//Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available
236 236
 	$_SESSION = array();
237 237
 	
238
-	if(! isset($_SERVER['REMOTE_ADDR'])){ 
238
+	if (!isset($_SERVER['REMOTE_ADDR'])) { 
239 239
 		$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
240 240
 	}
241 241
 	
242 242
 	//check for composer autoload file if exists include it
243
-	if (file_exists(VENDOR_PATH . 'autoload.php')){
243
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
244 244
 		require_once VENDOR_PATH . 'autoload.php';
245 245
 		
246 246
 		//define the class alias for vstream
Please login to merge, or discard this patch.
tests/hmvc/models/DBSessionModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	class DBSessionModel extends DBSessionHandlerModel{
2
+	class DBSessionModel extends DBSessionHandlerModel {
3 3
 		
4 4
 		protected $_table = 'ses';
5 5
 		protected $primary_key = 's_id';
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 			'skey' => 'test_id' //VARCHAR(255) 
15 15
 		);
16 16
 		
17
-		public function deleteByTime($time){
17
+		public function deleteByTime($time) {
18 18
 			$this->getQueryBuilder()->from($this->_table)
19 19
 									->where('s_time', '<', $time);
20 20
 			$this->_database->delete();
21 21
 		}
22 22
 
23 23
 		
24
-		public function getKeyValue(){
24
+		public function getKeyValue() {
25 25
 			$user_id = 0;
26 26
 			return $user_id;
27 27
 		}
Please login to merge, or discard this patch.
tests/include/autoloader.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 	//Autoload function
3
-	function tests_autoload($class){
3
+	function tests_autoload($class) {
4 4
 		$classesMap = array(
5 5
 			//Caches
6 6
 			'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php',
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 			'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php',
41 41
 			'Upload' => CORE_LIBRARY_PATH . 'Upload.php',
42 42
 		);
43
-		if(isset($classesMap[$class])){
44
-			if(file_exists($classesMap[$class])){
43
+		if (isset($classesMap[$class])) {
44
+			if (file_exists($classesMap[$class])) {
45 45
 				require_once $classesMap[$class];
46 46
 			}
47
-			else{
47
+			else {
48 48
 				echo 'File for class ' . $class . ' not found';
49 49
 			}
50 50
 		}
Please login to merge, or discard this patch.
core/common.php 1 patch
Spacing   +68 added lines, -68 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,14 +117,14 @@  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
 				die();
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 	 * 
145 145
 	 * @return mixed          the config value
146 146
 	 */
147
-	function get_config($key, $default = null){
147
+	function get_config($key, $default = null) {
148 148
 		static $cfg;
149
-		if (empty($cfg)){
149
+		if (empty($cfg)) {
150 150
 			$cfg[0] = & load_configurations();
151 151
 		}
152 152
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * 
161 161
 	 * @codeCoverageIgnore
162 162
 	 */
163
-	function save_to_log($level, $message, $logger = null){
164
-		$log =& class_loader('Log', 'classes');
165
-		if ($logger){
163
+	function save_to_log($level, $message, $logger = null) {
164
+		$log = & class_loader('Log', 'classes');
165
+		if ($logger) {
166 166
 			$log->setLogger($logger);
167 167
 		}
168 168
 		$log->writeLog($message, $level);
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * 
176 176
 	 * @codeCoverageIgnore
177 177
 	 */
178
-	function set_http_status_header($code = 200, $text = null){
179
-		if (empty($text)){
178
+	function set_http_status_header($code = 200, $text = null) {
179
+		if (empty($text)) {
180 180
 			$http_status = array(
181 181
 								100 => 'Continue',
182 182
 								101 => 'Switching Protocols',
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 								504 => 'Gateway Timeout',
225 225
 								505 => 'HTTP Version Not Supported',
226 226
 							);
227
-			if (isset($http_status[$code])){
227
+			if (isset($http_status[$code])) {
228 228
 				$text = $http_status[$code];
229 229
 			}
230
-			else{
230
+			else {
231 231
 				show_error('No HTTP status text found for your code please check it.');
232 232
 			}
233 233
 		}
234 234
 		
235
-		if (strpos(php_sapi_name(), 'cgi') === 0){
235
+		if (strpos(php_sapi_name(), 'cgi') === 0) {
236 236
 			header('Status: ' . $code . ' ' . $text, TRUE);
237 237
 		}
238
-		else{
238
+		else {
239 239
 			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240 240
 			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241 241
 		}
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 *  
251 251
 	 *  @codeCoverageIgnore
252 252
 	 */
253
-	function show_error($msg, $title = 'error', $logging = true){
253
+	function show_error($msg, $title = 'error', $logging = true) {
254 254
 		$title = strtoupper($title);
255 255
 		$data = array();
256 256
 		$data['error'] = $msg;
257 257
 		$data['title'] = $title;
258
-		if ($logging){
259
-			save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
258
+		if ($logging) {
259
+			save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR');
260 260
 		}
261 261
 		$response = & class_loader('Response', 'classes');
262 262
 		$response->sendError($data);
@@ -270,18 +270,18 @@  discard block
 block discarded – undo
270 270
 	 *  
271 271
 	 *  @return boolean true if the web server uses the https protocol, false if not.
272 272
 	 */
273
-	function is_https(){
273
+	function is_https() {
274 274
 		/*
275 275
 		* some servers pass the "HTTPS" parameter in the server variable,
276 276
 		* if is the case, check if the value is "on", "true", "1".
277 277
 		*/
278
-		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
278
+		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
279 279
 			return true;
280 280
 		}
281
-		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
281
+		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
282 282
 			return true;
283 283
 		}
284
-		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
284
+		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
285 285
 			return true;
286 286
 		}
287 287
 		return false;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 *  
297 297
 	 *  @return boolean true if is a valid URL address or false.
298 298
 	 */
299
-	function is_url($url){
299
+	function is_url($url) {
300 300
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1;
301 301
 	}
302 302
 	
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 	 *  @param string $controllerClass the controller class name to be loaded
307 307
 	 *  @codeCoverageIgnore
308 308
 	 */
309
-	function autoload_controller($controllerClass){
310
-		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
309
+	function autoload_controller($controllerClass) {
310
+		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) {
311 311
 			require_once $path;
312 312
 		}
313 313
 	}
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 	 *  
322 322
 	 *  @return boolean
323 323
 	 */
324
-	function php_exception_handler($ex){
325
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326
-			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
324
+	function php_exception_handler($ex) {
325
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
326
+			show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327 327
 		}
328
-		else{
328
+		else {
329 329
 			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330 330
 		}
331 331
 		return true;
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
 	 *  
343 343
 	 *  @return boolean	
344 344
 	 */
345
-	function php_error_handler($errno , $errstr, $errfile , $errline){
345
+	function php_error_handler($errno, $errstr, $errfile, $errline) {
346 346
 		$isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
347
-		if ($isError){
347
+		if ($isError) {
348 348
 			set_http_status_header(500);
349 349
 		}
350
-		if (! (error_reporting() & $errno)) {
350
+		if (!(error_reporting() & $errno)) {
351 351
 			save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR');
352 352
 			return;
353 353
 		}
354
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
354
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
355 355
 			$errorType = 'error';
356 356
 			switch ($errno) {
357 357
 				case E_USER_ERROR:
@@ -367,9 +367,9 @@  discard block
 block discarded – undo
367 367
 					$errorType = 'error';
368 368
 					break;
369 369
 			}
370
-			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
370
+			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType);
371 371
 		}
372
-		if ($isError){
372
+		if ($isError) {
373 373
 			die();
374 374
 		}
375 375
 		return true;
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
 	 * This function is used to run in shutdown situation of the script
380 380
 	 * @codeCoverageIgnore
381 381
 	 */
382
-	function php_shudown_handler(){
382
+	function php_shudown_handler() {
383 383
 		$lastError = error_get_last();
384 384
 		if (isset($lastError) &&
385
-			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
385
+			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) {
386 386
 			php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
387 387
 		}
388 388
 	}
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 *   
401 401
 	 *  @return string string of the HTML attribute.
402 402
 	 */
403
-	function attributes_to_string(array $attributes){
403
+	function attributes_to_string(array $attributes) {
404 404
 		$str = ' ';
405 405
 		//we check that the array passed as an argument is not empty.
406
-		if (! empty($attributes)){
407
-			foreach($attributes as $key => $value){
406
+		if (!empty($attributes)) {
407
+			foreach ($attributes as $key => $value) {
408 408
 				$key = trim(htmlspecialchars($key));
409 409
 				$value = trim(htmlspecialchars($value));
410 410
 				/*
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
 				* 	$attr = array('placeholder' => 'I am a "puple"')
415 415
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
416 416
 				 */
417
-				if ($value && strpos('"', $value) !== false){
417
+				if ($value && strpos('"', $value) !== false) {
418 418
 					$value = addslashes($value);
419 419
 				}
420
-				$str .= $key.' = "'.$value.'" ';
420
+				$str .= $key . ' = "' . $value . '" ';
421 421
 			}
422 422
 		}
423 423
 		//remove the space after using rtrim()
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	*
434 434
 	* @return string the stringfy value
435 435
 	*/
436
-	function stringfy_vars($var){
436
+	function stringfy_vars($var) {
437 437
 		return print_r($var, true);
438 438
 	}
439 439
 
@@ -444,18 +444,18 @@  discard block
 block discarded – undo
444 444
 	 * 
445 445
 	 * @return mixed   the sanitize value
446 446
 	 */
447
-	function clean_input($str){
448
-		if (is_array($str)){
447
+	function clean_input($str) {
448
+		if (is_array($str)) {
449 449
 			$str = array_map('clean_input', $str);
450 450
 		}
451
-		else if (is_object($str)){
451
+		else if (is_object($str)) {
452 452
 			$obj = $str;
453 453
 			foreach ($str as $var => $value) {
454 454
 				$obj->$var = clean_input($value);
455 455
 			}
456 456
 			$str = $obj;
457 457
 		}
458
-		else{
458
+		else {
459 459
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460 460
 		}
461 461
 		return $str;
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
 	 * 
474 474
 	 * @return string the string with the hidden part.
475 475
 	 */
476
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
476
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
477 477
 		//get the string length
478 478
 		$len = strlen($str);
479 479
 		//if str is empty
480
-		if ($len <= 0){
480
+		if ($len <= 0) {
481 481
 			return str_repeat($hiddenChar, 6);
482 482
 		}
483 483
 		//if the length is less than startCount and endCount
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 		//or startCount is negative or endCount is negative
486 486
 		//return the full string hidden
487 487
 		
488
-		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
488
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
489 489
 			return str_repeat($hiddenChar, $len);
490 490
 		}
491 491
 		//the start non hidden string
492 492
 		$startNonHiddenStr = substr($str, 0, $startCount);
493 493
 		//the end non hidden string
494 494
 		$endNonHiddenStr = null;
495
-		if ($endCount > 0){
495
+		if ($endCount > 0) {
496 496
 			$endNonHiddenStr = substr($str, - $endCount);
497 497
 		}
498 498
 		//the hidden string
@@ -505,40 +505,40 @@  discard block
 block discarded – undo
505 505
 	 * This function is used to set the initial session config regarding the configuration
506 506
 	 * @codeCoverageIgnore
507 507
 	 */
508
-	function set_session_config(){
508
+	function set_session_config() {
509 509
 		//$_SESSION is not available on cli mode 
510
-		if (! IS_CLI){
511
-			$logger =& class_loader('Log', 'classes');
510
+		if (!IS_CLI) {
511
+			$logger = & class_loader('Log', 'classes');
512 512
 			$logger->setLogger('PHPSession');
513 513
 			//set session params
514 514
 			$sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
515 515
 			$sessionName = get_config('session_name');
516
-			if ($sessionName){
516
+			if ($sessionName) {
517 517
 				session_name($sessionName);
518 518
 			}
519 519
 			$logger->info('Session handler: ' . $sessionHandler);
520 520
 			$logger->info('Session name: ' . $sessionName);
521 521
 
522
-			if ($sessionHandler == 'files'){
522
+			if ($sessionHandler == 'files') {
523 523
 				$sessionSavePath = get_config('session_save_path');
524
-				if ($sessionSavePath){
525
-					if (! is_dir($sessionSavePath)){
524
+				if ($sessionSavePath) {
525
+					if (!is_dir($sessionSavePath)) {
526 526
 						mkdir($sessionSavePath, 1773);
527 527
 					}
528 528
 					session_save_path($sessionSavePath);
529 529
 					$logger->info('Session save path: ' . $sessionSavePath);
530 530
 				}
531 531
 			}
532
-			else if ($sessionHandler == 'database'){
532
+			else if ($sessionHandler == 'database') {
533 533
 				//load database session handle library
534 534
 				//Database Session handler Model
535 535
 				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
536 536
 
537
-				$DBS =& class_loader('DBSessionHandler', 'classes');
537
+				$DBS = & class_loader('DBSessionHandler', 'classes');
538 538
 				session_set_save_handler($DBS, true);
539 539
 				$logger->info('session save path: ' . get_config('session_save_path'));
540 540
 			}
541
-			else{
541
+			else {
542 542
 				show_error('Invalid session handler configuration');
543 543
 			}
544 544
 			$lifetime = get_config('session_cookie_lifetime', 0);
@@ -561,9 +561,9 @@  discard block
 block discarded – undo
561 561
 			$logger->info('Session lifetime: ' . $lifetime);
562 562
 			$logger->info('Session cookie path: ' . $path);
563 563
 			$logger->info('Session domain: ' . $domain);
564
-			$logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
564
+			$logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE'));
565 565
 			
566
-			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
566
+			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) {
567 567
 				$logger->info('Session not yet start, start it now');
568 568
 				session_start();
569 569
 			}
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Spacing   +45 added lines, -45 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,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184 184
             {
185
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
185
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
186 186
             }
187 187
     		$this->_set_where($where);
188 188
 
@@ -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->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
227
+                $this->getQueryBuilder()->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
             $this->getQueryBuilder()->from($this->_table);
231 231
 			$result = $this->_database->getAll($type);
232 232
             $this->_temporary_return_type = $this->return_type;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                 $insert_id = $this->_database->insertId();
260 260
                 $this->trigger('after_create', $insert_id);
261 261
 				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
262
-				return ! $insert_id ? true : $insert_id;
262
+				return !$insert_id ? true : $insert_id;
263 263
             }
264 264
             else
265 265
             {
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
         {
337 337
             $args = func_get_args();
338 338
             $data = array();
339
-            if (count($args) == 2){
340
-                if (is_array($args[1])){
339
+            if (count($args) == 2) {
340
+                if (is_array($args[1])) {
341 341
                     $data = array_pop($args);
342 342
                 }
343 343
             }
344
-            else if (count($args) == 3){
345
-                if (is_array($args[2])){
344
+            else if (count($args) == 3) {
345
+                if (is_array($args[2])) {
346 346
                     $data = array_pop($args);
347 347
                 }
348 348
             }
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
             if ($this->soft_delete)
385 385
             {
386 386
                 $this->getQueryBuilder()->from($this->_table);	
387
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
387
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
388 388
             }
389 389
             else
390 390
             {
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             if ($this->soft_delete)
409 409
             {
410 410
                 $this->getQueryBuilder()->from($this->_table);	
411
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
411
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
412 412
             }
413 413
             else
414 414
             {
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
             if ($this->soft_delete)
431 431
             {
432 432
                 $this->getQueryBuilder()->from($this->_table);	
433
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
433
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
434 434
             }
435 435
             else
436 436
             {
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
                 $key = $this->primary_key;
501 501
                 $value = $args[0];
502 502
             }
503
-            $this->trigger('before_dropdown', array( $key, $value ));
503
+            $this->trigger('before_dropdown', array($key, $value));
504 504
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
505 505
             {
506 506
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         {
526 526
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
527 527
             {
528
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
528
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
529 529
             }
530 530
             $where = func_get_args();
531 531
             $this->_set_where($where);
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         {
542 542
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
543 543
             {
544
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
544
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
545 545
             }
546 546
 			$this->getQueryBuilder()->from($this->_table);
547 547
 			$this->_database->getAll();
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 		/**
552 552
 		* Enabled cache temporary
553 553
 		*/
554
-		public function cached($ttl = 0){
555
-		  if ($ttl > 0){
554
+		public function cached($ttl = 0) {
555
+		  if ($ttl > 0) {
556 556
 			$this->_database = $this->_database->cached($ttl);
557 557
 		  }
558 558
 		  return $this;
@@ -706,13 +706,13 @@  discard block
 block discarded – undo
706 706
             {
707 707
                 if (is_object($row))
708 708
                 {
709
-					if (isset($row->$attr)){
709
+					if (isset($row->$attr)) {
710 710
 						unset($row->$attr);
711 711
 					}
712 712
                 }
713 713
                 else
714 714
                 {
715
-					if (isset($row[$attr])){
715
+					if (isset($row[$attr])) {
716 716
 						unset($row[$attr]);
717 717
 					}
718 718
                 }
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
          * Return the database instance
725 725
          * @return Database the database instance
726 726
          */
727
-        public function getDatabaseInstance(){
727
+        public function getDatabaseInstance() {
728 728
             return $this->_database;
729 729
         }
730 730
 
@@ -732,9 +732,9 @@  discard block
 block discarded – undo
732 732
          * set the Database instance for future use
733 733
          * @param Database $db the database object
734 734
          */
735
-         public function setDatabaseInstance($db){
735
+         public function setDatabaseInstance($db) {
736 736
             $this->_database = $db;
737
-            if ($this->dbCacheTime > 0){
737
+            if ($this->dbCacheTime > 0) {
738 738
                 $this->_database->setCache($this->dbCacheTime);
739 739
             }
740 740
             return $this;
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
          * Return the loader instance
745 745
          * @return Loader the loader instance
746 746
          */
747
-        public function getLoader(){
747
+        public function getLoader() {
748 748
             return $this->loaderInstance;
749 749
         }
750 750
 
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
          * @param Loader $loader the loader object
754 754
 		 * @return object
755 755
          */
756
-         public function setLoader($loader){
756
+         public function setLoader($loader) {
757 757
             $this->loaderInstance = $loader;
758 758
             return $this;
759 759
         }
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
763 763
          * @return object the DatabaseQueryBuilder instance
764 764
          */
765
-        public function getQueryBuilder(){
765
+        public function getQueryBuilder() {
766 766
             return $this->_database->getQueryBuilder();
767 767
         }
768 768
 
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
          * @param object $queryBuilder the DatabaseQueryBuilder object
772 772
 		 * @return object
773 773
          */
774
-         public function setQueryBuilder($queryBuilder){
774
+         public function setQueryBuilder($queryBuilder) {
775 775
             $this->_database->setQueryBuilder($queryBuilder);
776 776
             return $this;
777 777
         }
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
          * Return the FormValidation instance
782 782
          * @return FormValidation the form validation instance
783 783
          */
784
-        public function getFormValidation(){
784
+        public function getFormValidation() {
785 785
             return $this->formValidationInstance;
786 786
         }
787 787
 
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
          * @param FormValidation $fv the form validation object
791 791
 		 * @return object
792 792
          */
793
-         public function setFormValidation($fv){
793
+         public function setFormValidation($fv) {
794 794
             $this->formValidationInstance = $fv;
795 795
             return $this;
796 796
         }
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
          */
805 805
         public function order_by($criteria, $order = 'ASC')
806 806
         {
807
-            if ( is_array($criteria) )
807
+            if (is_array($criteria))
808 808
             {
809 809
                 foreach ($criteria as $key => $value)
810 810
                 {
@@ -835,13 +835,13 @@  discard block
 block discarded – undo
835 835
 		* relate for the relation "belongs_to"
836 836
 		* @return mixed
837 837
 		*/
838
-		protected function relateBelongsTo($row){
838
+		protected function relateBelongsTo($row) {
839 839
 			foreach ($this->belongs_to as $key => $value)
840 840
             {
841 841
                 if (is_string($value))
842 842
                 {
843 843
                     $relationship = $value;
844
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
844
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
845 845
                 }
846 846
                 else
847 847
                 {
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
 
852 852
                 if (in_array($relationship, $this->_with))
853 853
                 {
854
-                    if (is_object($this->loaderInstance)){
854
+                    if (is_object($this->loaderInstance)) {
855 855
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
856 856
                     }
857
-                    else{
857
+                    else {
858 858
                         Loader::model($options['model'], $relationship . '_model');    
859 859
                     }
860 860
                     if (is_object($row))
@@ -874,13 +874,13 @@  discard block
 block discarded – undo
874 874
 		* relate for the relation "has_many"
875 875
 		* @return mixed
876 876
 		*/
877
-		protected function relateHasMany($row){
877
+		protected function relateHasMany($row) {
878 878
 			foreach ($this->has_many as $key => $value)
879 879
             {
880 880
                 if (is_string($value))
881 881
                 {
882 882
                     $relationship = $value;
883
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
883
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
884 884
                 }
885 885
                 else
886 886
                 {
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
 
891 891
                 if (in_array($relationship, $this->_with))
892 892
                 {
893
-                    if (is_object($this->loaderInstance)){
893
+                    if (is_object($this->loaderInstance)) {
894 894
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
895 895
                     }
896
-                    else{
896
+                    else {
897 897
                         Loader::model($options['model'], $relationship . '_model');    
898 898
                     }
899 899
                     if (is_object($row))
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
             if (!empty($this->validate))
945 945
             {
946 946
                 $fv = null;
947
-                if (is_object($this->formValidationInstance)){
947
+                if (is_object($this->formValidationInstance)) {
948 948
                     $fv = $this->formValidationInstance;
949 949
                 }
950
-                else{
950
+                else {
951 951
                     Loader::library('FormValidation');
952 952
                     $fv = $this->formvalidation;
953 953
                     $this->setFormValidation($fv);
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
 		* Set WHERE parameters, when is array
977 977
 		* @param array $params
978 978
 		*/
979
-		protected function _set_where_array(array $params){
979
+		protected function _set_where_array(array $params) {
980 980
 			foreach ($params as $field => $filter)
981 981
 			{
982 982
 				if (is_array($filter))
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
         /**
1043 1043
             Shortcut to controller
1044 1044
         */
1045
-        public function __get($key){
1045
+        public function __get($key) {
1046 1046
             return get_instance()->{$key};
1047 1047
         }
1048 1048
 
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -23,110 +23,110 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class Database{
26
+  class Database {
27 27
 	
28 28
 	/**
29 29
 	 * The PDO instance
30 30
 	 * @var object
31 31
 	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
 	/**
35 35
 	 * The database name used for the application
36 36
 	 * @var string
37 37
 	*/
38
-	private $databaseName        = null;
38
+	private $databaseName = null;
39 39
 	
40 40
 	/**
41 41
 	 * The number of rows returned by the last query
42 42
 	 * @var int
43 43
 	*/
44
-    private $numRows             = 0;
44
+    private $numRows = 0;
45 45
 	
46 46
 	/**
47 47
 	 * The last insert id for the primary key column that have auto increment or sequence
48 48
 	 * @var mixed
49 49
 	*/
50
-    private $insertId            = null;
50
+    private $insertId = null;
51 51
 	
52 52
 	/**
53 53
 	 * The full SQL query statment after build for each command
54 54
 	 * @var string
55 55
 	*/
56
-    private $query               = null;
56
+    private $query = null;
57 57
 	
58 58
 	/**
59 59
 	 * The error returned for the last query
60 60
 	 * @var string
61 61
 	*/
62
-    private $error               = null;
62
+    private $error = null;
63 63
 	
64 64
 	/**
65 65
 	 * The result returned for the last query
66 66
 	 * @var mixed
67 67
 	*/
68
-    private $result              = array();
68
+    private $result = array();
69 69
 	
70 70
 	/**
71 71
 	 * The cache default time to live in second. 0 means no need to use the cache feature
72 72
 	 * @var int
73 73
 	*/
74
-	private $cacheTtl              = 0;
74
+	private $cacheTtl = 0;
75 75
 	
76 76
 	/**
77 77
 	 * The cache current time to live. 0 means no need to use the cache feature
78 78
 	 * @var int
79 79
 	*/
80
-    private $temporaryCacheTtl   = 0;
80
+    private $temporaryCacheTtl = 0;
81 81
 	
82 82
 	/**
83 83
 	 * The number of executed query for the current request
84 84
 	 * @var int
85 85
 	*/
86
-    private $queryCount          = 0;
86
+    private $queryCount = 0;
87 87
 	
88 88
 	/**
89 89
 	 * The default data to be used in the statments query INSERT, UPDATE
90 90
 	 * @var array
91 91
 	*/
92
-    private $data                = array();
92
+    private $data = array();
93 93
 	
94 94
 	/**
95 95
 	 * The database configuration
96 96
 	 * @var array
97 97
 	*/
98
-    private $config              = array();
98
+    private $config = array();
99 99
 	
100 100
 	/**
101 101
 	 * The logger instance
102 102
 	 * @var object
103 103
 	 */
104
-    private $logger              = null;
104
+    private $logger = null;
105 105
 
106 106
     /**
107 107
     * The cache instance
108 108
     * @var object
109 109
     */
110
-    private $cacheInstance       = null;
110
+    private $cacheInstance = null;
111 111
 
112 112
     /**
113 113
     * The benchmark instance
114 114
     * @var object
115 115
     */
116
-    private $benchmarkInstance   = null;
116
+    private $benchmarkInstance = null;
117 117
 	
118 118
 	/**
119 119
     * The DatabaseQueryBuilder instance
120 120
     * @var object
121 121
     */
122
-    private $queryBuilder        = null;
122
+    private $queryBuilder = null;
123 123
 
124 124
 
125 125
     /**
126 126
      * Construct new database
127 127
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
128 128
      */
129
-    public function __construct($overwriteConfig = array()){
129
+    public function __construct($overwriteConfig = array()) {
130 130
         //Set Log instance to use
131 131
         $this->setLoggerFromParamOrCreateNewInstance(null);
132 132
 		
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
      * This is used to connect to database
145 145
      * @return bool 
146 146
      */
147
-    public function connect(){
147
+    public function connect() {
148 148
       $config = $this->getDatabaseConfiguration();
149
-      if (! empty($config)){
150
-        try{
149
+      if (!empty($config)) {
150
+        try {
151 151
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
152 152
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
153 153
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
154 154
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
155 155
             return true;
156 156
           }
157
-          catch (PDOException $e){
157
+          catch (PDOException $e) {
158 158
             $this->logger->fatal($e->getMessage());
159 159
             show_error('Cannot connect to Database.');
160 160
             return false;
161 161
           }
162 162
       }
163
-      else{
163
+      else {
164 164
         show_error('Database configuration is not set.');
165 165
         return false;
166 166
       }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * Return the number of rows returned by the current query
172 172
      * @return int
173 173
      */
174
-    public function numRows(){
174
+    public function numRows() {
175 175
       return $this->numRows;
176 176
     }
177 177
 
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
      * Return the last insert id value
180 180
      * @return mixed
181 181
      */
182
-    public function insertId(){
182
+    public function insertId() {
183 183
       return $this->insertId;
184 184
     }
185 185
 
186 186
     /**
187 187
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
188 188
      */
189
-    public function error(){
190
-  		if ($this->error){
189
+    public function error() {
190
+  		if ($this->error) {
191 191
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
192 192
   		}
193 193
     }
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
      * If is string will determine the result type "array" or "object"
199 199
      * @return mixed       the query SQL string or the record result
200 200
      */
201
-    public function get($returnSQLQueryOrResultType = false){
201
+    public function get($returnSQLQueryOrResultType = false) {
202 202
       $this->getQueryBuilder()->limit(1);
203 203
       $query = $this->getAll(true);
204
-      if ($returnSQLQueryOrResultType === true){
204
+      if ($returnSQLQueryOrResultType === true) {
205 205
         return $query;
206 206
       }
207
-      else{
207
+      else {
208 208
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
209 209
       }
210 210
     }
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
      * If is string will determine the result type "array" or "object"
216 216
      * @return mixed       the query SQL string or the record result
217 217
      */
218
-    public function getAll($returnSQLQueryOrResultType = false){
218
+    public function getAll($returnSQLQueryOrResultType = false) {
219 219
 	   $query = $this->getQueryBuilder()->getQuery();
220
-	   if ($returnSQLQueryOrResultType === true){
220
+	   if ($returnSQLQueryOrResultType === true) {
221 221
       	return $query;
222 222
       }
223 223
       return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -229,18 +229,18 @@  discard block
 block discarded – undo
229 229
      * @param  boolean $escape  whether to escape or not the values
230 230
      * @return mixed          the insert id of the new record or null
231 231
      */
232
-    public function insert($data = array(), $escape = true){
233
-      if (empty($data) && $this->getData()){
232
+    public function insert($data = array(), $escape = true) {
233
+      if (empty($data) && $this->getData()) {
234 234
         //as when using $this->setData() may be the data already escaped
235 235
         $escape = false;
236 236
         $data = $this->getData();
237 237
       }
238 238
       $query = $this->getQueryBuilder()->insert($data, $escape)->getQuery();
239 239
       $result = $this->query($query);
240
-      if ($result){
240
+      if ($result) {
241 241
         $this->insertId = $this->pdo->lastInsertId();
242 242
 		//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
243
-        return ! $this->insertId() ? true : $this->insertId();
243
+        return !$this->insertId() ? true : $this->insertId();
244 244
       }
245 245
       return false;
246 246
     }
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
      * @param  boolean $escape  whether to escape or not the values
252 252
      * @return mixed          the update status
253 253
      */
254
-    public function update($data = array(), $escape = true){
255
-      if (empty($data) && $this->getData()){
254
+    public function update($data = array(), $escape = true) {
255
+      if (empty($data) && $this->getData()) {
256 256
         //as when using $this->setData() may be the data already escaped
257 257
         $escape = false;
258 258
         $data = $this->getData();
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      * Delete the record in database
266 266
      * @return mixed the delete status
267 267
      */
268
-    public function delete(){
268
+    public function delete() {
269 269
 		$query = $this->getQueryBuilder()->delete()->getQuery();
270 270
     	return $this->query($query);
271 271
     }
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
      * @param integer $ttl the cache time to live in second
276 276
      * @return object        the current Database instance
277 277
      */
278
-    public function setCache($ttl = 0){
279
-      if ($ttl > 0){
278
+    public function setCache($ttl = 0) {
279
+      if ($ttl > 0) {
280 280
         $this->cacheTtl = $ttl;
281 281
         $this->temporaryCacheTtl = $ttl;
282 282
       }
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
 	 * @param  integer $ttl the cache time to live in second
289 289
 	 * @return object        the current Database instance
290 290
 	 */
291
-  	public function cached($ttl = 0){
292
-        if ($ttl > 0){
291
+  	public function cached($ttl = 0) {
292
+        if ($ttl > 0) {
293 293
           $this->temporaryCacheTtl = $ttl;
294 294
         }
295 295
         return $this;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * @param boolean $escaped whether we can do escape of not 
302 302
      * @return mixed       the data after escaped or the same data if not
303 303
      */
304
-    public function escape($data, $escaped = true){
304
+    public function escape($data, $escaped = true) {
305 305
       return $escaped ? 
306 306
                       $this->getPdo()->quote(trim($data)) 
307 307
                       : $data; 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
      * Return the number query executed count for the current request
312 312
      * @return int
313 313
      */
314
-    public function queryCount(){
314
+    public function queryCount() {
315 315
       return $this->queryCount;
316 316
     }
317 317
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      * Return the current query SQL string
320 320
      * @return string
321 321
      */
322
-    public function getQuery(){
322
+    public function getQuery() {
323 323
       return $this->query;
324 324
     }
325 325
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * Return the application database name
328 328
      * @return string
329 329
      */
330
-    public function getDatabaseName(){
330
+    public function getDatabaseName() {
331 331
       return $this->databaseName;
332 332
     }
333 333
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * Return the PDO instance
336 336
      * @return object
337 337
      */
338
-    public function getPdo(){
338
+    public function getPdo() {
339 339
       return $this->pdo;
340 340
     }
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @param object $pdo the pdo object
345 345
 	 * @return object Database
346 346
      */
347
-    public function setPdo(PDO $pdo){
347
+    public function setPdo(PDO $pdo) {
348 348
       $this->pdo = $pdo;
349 349
       return $this;
350 350
     }
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
      * Return the Log instance
355 355
      * @return Log
356 356
      */
357
-    public function getLogger(){
357
+    public function getLogger() {
358 358
       return $this->logger;
359 359
     }
360 360
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @param Log $logger the log object
364 364
 	 * @return object Database
365 365
      */
366
-    public function setLogger($logger){
366
+    public function setLogger($logger) {
367 367
       $this->logger = $logger;
368 368
       return $this;
369 369
     }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
      * Return the cache instance
373 373
      * @return CacheInterface
374 374
      */
375
-    public function getCacheInstance(){
375
+    public function getCacheInstance() {
376 376
       return $this->cacheInstance;
377 377
     }
378 378
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      * @param CacheInterface $cache the cache object
382 382
 	 * @return object Database
383 383
      */
384
-    public function setCacheInstance($cache){
384
+    public function setCacheInstance($cache) {
385 385
       $this->cacheInstance = $cache;
386 386
       return $this;
387 387
     }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      * Return the benchmark instance
391 391
      * @return Benchmark
392 392
      */
393
-    public function getBenchmark(){
393
+    public function getBenchmark() {
394 394
       return $this->benchmarkInstance;
395 395
     }
396 396
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @param Benchmark $benchmark the benchmark object
400 400
 	 * @return object Database
401 401
      */
402
-    public function setBenchmark($benchmark){
402
+    public function setBenchmark($benchmark) {
403 403
       $this->benchmarkInstance = $benchmark;
404 404
       return $this;
405 405
     }
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
      * Return the DatabaseQueryBuilder instance
410 410
      * @return object DatabaseQueryBuilder
411 411
      */
412
-    public function getQueryBuilder(){
412
+    public function getQueryBuilder() {
413 413
       return $this->queryBuilder;
414 414
     }
415 415
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      * Set the DatabaseQueryBuilder instance
418 418
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
419 419
      */
420
-    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
420
+    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) {
421 421
       $this->queryBuilder = $queryBuilder;
422 422
       return $this;
423 423
     }
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
      * Return the data to be used for insert, update, etc.
427 427
      * @return array
428 428
      */
429
-    public function getData(){
429
+    public function getData() {
430 430
       return $this->data;
431 431
     }
432 432
 
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
      * @param boolean $escape whether to escape or not the $value
438 438
      * @return object        the current Database instance
439 439
      */
440
-    public function setData($key, $value = null, $escape = true){
441
-  	  if(is_array($key)){
442
-    		foreach($key as $k => $v){
440
+    public function setData($key, $value = null, $escape = true) {
441
+  	  if (is_array($key)) {
442
+    		foreach ($key as $k => $v) {
443 443
     			$this->setData($k, $v, $escape);
444 444
     		}	
445 445
   	  } else {
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      * @param  boolean $array return the result as array
457 457
      * @return mixed         the query result
458 458
      */
459
-    public function query($query, $all = true, $array = false){
459
+    public function query($query, $all = true, $array = false) {
460 460
       $this->reset();
461 461
       $query = $this->getPreparedQuery($query, $all);
462 462
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
       $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
465 465
 
466 466
       $this->logger->info(
467
-                          'Execute SQL query ['.$this->query.'], return type: ' 
468
-                          . ($array?'ARRAY':'OBJECT') .', return as list: ' 
469
-                          . (is_bool($all) && $all ? 'YES':'NO')
467
+                          'Execute SQL query [' . $this->query . '], return type: ' 
468
+                          . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' 
469
+                          . (is_bool($all) && $all ? 'YES' : 'NO')
470 470
                         );
471 471
       //cache expire time
472 472
       $cacheExpire = $this->temporaryCacheTtl;
@@ -483,15 +483,15 @@  discard block
 block discarded – undo
483 483
       //if can use cache feature for this query
484 484
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
485 485
     
486
-      if ($dbCacheStatus && $isSqlSELECTQuery){
486
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
487 487
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
488 488
           $cacheContent = $this->getCacheContentForQuery($query, $all, $array);  
489 489
       }
490 490
       
491
-      if ( !$cacheContent){
491
+      if (!$cacheContent) {
492 492
         $sqlQuery = $this->runSqlQuery($query, $all, $array);
493
-        if (is_object($sqlQuery)){
494
-          if ($isSqlSELECTQuery){
493
+        if (is_object($sqlQuery)) {
494
+          if ($isSqlSELECTQuery) {
495 495
             $this->setQueryResultForSelect($sqlQuery, $all, $array);
496 496
             $this->setCacheContentForQuery(
497 497
                                             $this->query, 
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
                                             $dbCacheStatus && $isSqlSELECTQuery, 
501 501
                                             $cacheExpire
502 502
                                           );
503
-            if (! $this->result){
503
+            if (!$this->result) {
504 504
               $this->logger->info('No result where found for the query [' . $query . ']');
505 505
             }
506 506
           } else {
507 507
               $this->setQueryResultForNonSelect($sqlQuery);
508
-              if (! $this->result){
508
+              if (!$this->result) {
509 509
                 $this->setQueryError();
510 510
               }
511 511
           }
512 512
         }
513
-      } else if ($isSqlSELECTQuery){
514
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
513
+      } else if ($isSqlSELECTQuery) {
514
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
515 515
           $this->result = $cacheContent;
516 516
           $this->numRows = count($this->result);
517 517
       }
@@ -524,11 +524,11 @@  discard block
 block discarded – undo
524 524
      * 
525 525
      * @return object|void
526 526
      */
527
-    public function runSqlQuery($query, $all, $array){
527
+    public function runSqlQuery($query, $all, $array) {
528 528
        //for database query execution time
529 529
         $benchmarkMarkerKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
530 530
         $benchmarkInstance = $this->getBenchmark();
531
-        if (! is_object($benchmarkInstance)){
531
+        if (!is_object($benchmarkInstance)) {
532 532
           $obj = & get_instance();
533 533
           $benchmarkInstance = $obj->benchmark; 
534 534
           $this->setBenchmark($benchmarkInstance);
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
         //get response time for this query
542 542
         $responseTime = $benchmarkInstance->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
543 543
 		    //TODO use the configuration value for the high response time currently is 1 second
544
-        if ($responseTime >= 1 ){
545
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
544
+        if ($responseTime >= 1) {
545
+            $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.');
546 546
         }
547 547
 		    //count the number of query execution to server
548 548
         $this->queryCount++;
549 549
 		
550
-        if ($sqlQuery !== false){
550
+        if ($sqlQuery !== false) {
551 551
           return $sqlQuery;
552 552
         }
553 553
         $this->setQueryError();
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 	 * Return the database configuration
559 559
 	 * @return array
560 560
 	 */
561
-	public  function getDatabaseConfiguration(){
561
+	public  function getDatabaseConfiguration() {
562 562
 	  return $this->config;
563 563
 	}
564 564
 
@@ -568,14 +568,14 @@  discard block
 block discarded – undo
568 568
     * @param boolean $useConfigFile whether to use database configuration file
569 569
 	  * @return object Database
570 570
     */
571
-    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
571
+    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
572 572
         $db = array();
573
-        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
573
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) {
574 574
             //here don't use require_once because somewhere user can create database instance directly
575 575
             require CONFIG_PATH . 'database.php';
576 576
         }
577 577
           
578
-        if (! empty($overwriteConfig)){
578
+        if (!empty($overwriteConfig)) {
579 579
           $db = array_merge($db, $overwriteConfig);
580 580
         }
581 581
         $config = array(
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
         );
592 592
 		
593 593
 		$config = array_merge($config, $db);
594
-		if (strstr($config['hostname'], ':')){
594
+		if (strstr($config['hostname'], ':')) {
595 595
 			$p = explode(':', $config['hostname']);
596
-			if (count($p) >= 2){
596
+			if (count($p) >= 2) {
597 597
 			  $config['hostname'] = $p[0];
598 598
 			  $config['port'] = $p[1];
599 599
 			}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 		 $this->connect();
613 613
 		 
614 614
 		 //update queryBuilder with some properties needed
615
-		 if(is_object($this->getQueryBuilder())){
615
+		 if (is_object($this->getQueryBuilder())) {
616 616
 			  $this->getQueryBuilder()->setDriver($config['driver']);
617 617
 			  $this->getQueryBuilder()->setPrefix($config['prefix']);
618 618
 			  $this->getQueryBuilder()->setPdo($this->getPdo());
@@ -624,19 +624,19 @@  discard block
 block discarded – undo
624 624
    * Set the result for SELECT query using PDOStatment
625 625
    * @see Database::query
626 626
    */
627
-    protected function setQueryResultForSelect($pdoStatment, $all, $array){
627
+    protected function setQueryResultForSelect($pdoStatment, $all, $array) {
628 628
       //if need return all result like list of record
629
-      if (is_bool($all) && $all){
629
+      if (is_bool($all) && $all) {
630 630
           $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC);
631 631
       }
632
-      else{
632
+      else {
633 633
           $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC);
634 634
       }
635 635
       //Sqlite and pgsql always return 0 when using rowCount()
636
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
636
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
637 637
         $this->numRows = count($this->result);  
638 638
       }
639
-      else{
639
+      else {
640 640
         $this->numRows = $pdoStatment->rowCount(); 
641 641
       }
642 642
     }
@@ -645,13 +645,13 @@  discard block
 block discarded – undo
645 645
      * Set the result for other command than SELECT query using PDOStatment
646 646
      * @see Database::query
647 647
      */
648
-    protected function setQueryResultForNonSelect($pdoStatment){
648
+    protected function setQueryResultForNonSelect($pdoStatment) {
649 649
       //Sqlite and pgsql always return 0 when using rowCount()
650
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
650
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
651 651
         $this->result = true; //to test the result for the query like UPDATE, INSERT, DELETE
652 652
         $this->numRows = 1; //TODO use the correct method to get the exact affected row
653 653
       }
654
-      else{
654
+      else {
655 655
           $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
656 656
           $this->numRows = $pdoStatment->rowCount(); 
657 657
       }
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
      * This method is used to get the PDO DSN string using the configured driver
664 664
      * @return string the DSN string
665 665
      */
666
-    protected function getDsnFromDriver(){
666
+    protected function getDsnFromDriver() {
667 667
       $config = $this->getDatabaseConfiguration();
668
-      if (! empty($config)){
668
+      if (!empty($config)) {
669 669
         $driver = $config['driver'];
670 670
         $driverDsnMap = array(
671 671
                                 'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
      *
691 691
      * @return string
692 692
      */
693
-    protected function getPreparedQuery($query, $data){
694
-      if (is_array($data)){
693
+    protected function getPreparedQuery($query, $data) {
694
+      if (is_array($data)) {
695 695
   			$x = explode('?', $query);
696 696
   			$q = '';
697
-  			foreach($x as $k => $v){
698
-  			  if (! empty($v)){
697
+  			foreach ($x as $k => $v) {
698
+  			  if (!empty($v)) {
699 699
   				  $q .= $v . (isset($data[$k]) ? $this->escape($data[$k]) : '');
700 700
   			  }
701 701
   			}
@@ -710,9 +710,9 @@  discard block
 block discarded – undo
710 710
      *      
711 711
      * @return mixed
712 712
      */
713
-    protected function getCacheContentForQuery($query, $all, $array){
713
+    protected function getCacheContentForQuery($query, $all, $array) {
714 714
         $cacheKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
715
-        if (! is_object($this->getCacheInstance())){
715
+        if (!is_object($this->getCacheInstance())) {
716 716
     			//can not call method with reference in argument
717 717
     			//like $this->setCacheInstance(& get_instance()->cache);
718 718
     			//use temporary variable
@@ -730,10 +730,10 @@  discard block
 block discarded – undo
730 730
      * @param boolean $status whether can save the query result into cache
731 731
      * @param int $expire the cache TTL
732 732
      */
733
-     protected function setCacheContentForQuery($query, $key, $result, $status, $expire){
734
-        if ($status){
735
-            $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
736
-            if (! is_object($this->getCacheInstance())){
733
+     protected function setCacheContentForQuery($query, $key, $result, $status, $expire) {
734
+        if ($status) {
735
+            $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
736
+            if (!is_object($this->getCacheInstance())) {
737 737
       				//can not call method with reference in argument
738 738
       				//like $this->setCacheInstance(& get_instance()->cache);
739 739
       				//use temporary variable
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
     /**
749 749
      * Set error for database query execution
750 750
      */
751
-    protected function setQueryError(){
751
+    protected function setQueryError() {
752 752
       $error = $this->pdo->errorInfo();
753 753
       $this->error = isset($error[2]) ? $error[2] : '';
754 754
       $this->logger->error('The database query execution got error: ' . stringfy_vars($error));
@@ -762,8 +762,8 @@  discard block
 block discarded – undo
762 762
      * 
763 763
      *  @return string
764 764
      */
765
-    protected function getCacheBenchmarkKeyForQuery($query, $all, $array){
766
-      if (is_array($all)){
765
+    protected function getCacheBenchmarkKeyForQuery($query, $all, $array) {
766
+      if (is_array($all)) {
767 767
         $all = 'array';
768 768
       }
769 769
       return md5($query . $all . $array);
@@ -773,12 +773,12 @@  discard block
 block discarded – undo
773 773
      * Set the Log instance using argument or create new instance
774 774
      * @param object $logger the Log instance if not null
775 775
      */
776
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
777
-      if ($logger !== null){
776
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
777
+      if ($logger !== null) {
778 778
         $this->setLogger($logger);
779 779
       }
780
-      else{
781
-          $this->logger =& class_loader('Log', 'classes');
780
+      else {
781
+          $this->logger = & class_loader('Log', 'classes');
782 782
           $this->logger->setLogger('Library::Database');
783 783
       }
784 784
     }
@@ -787,19 +787,19 @@  discard block
 block discarded – undo
787 787
    * Set the DatabaseQueryBuilder instance using argument or create new instance
788 788
    * @param object $queryBuilder the DatabaseQueryBuilder instance if not null
789 789
    */
790
-	protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null){
791
-	  if ($queryBuilder !== null){
790
+	protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null) {
791
+	  if ($queryBuilder !== null) {
792 792
       $this->setQueryBuilder($queryBuilder);
793 793
 	  }
794
-	  else{
795
-		  $this->queryBuilder =& class_loader('DatabaseQueryBuilder', 'classes');
794
+	  else {
795
+		  $this->queryBuilder = & class_loader('DatabaseQueryBuilder', 'classes');
796 796
 	  }
797 797
 	}
798 798
 
799 799
     /**
800 800
      * Reset the database class attributs to the initail values before each query.
801 801
      */
802
-    private function reset(){
802
+    private function reset() {
803 803
 	   //query builder reset
804 804
       $this->getQueryBuilder()->reset();
805 805
       $this->numRows  = 0;
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     /**
814 814
      * The class destructor
815 815
      */
816
-    public function __destruct(){
816
+    public function __destruct() {
817 817
       $this->pdo = null;
818 818
     }
819 819
 
Please login to merge, or discard this patch.
core/classes/DatabaseQueryBuilder.php 1 patch
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryBuilder{
26
+  class DatabaseQueryBuilder {
27 27
   	/**
28 28
   	 * The SQL SELECT statment
29 29
   	 * @var string
30 30
   	*/
31
-  	private $select              = '*';
31
+  	private $select = '*';
32 32
   	
33 33
   	/**
34 34
   	 * The SQL FROM statment
35 35
   	 * @var string
36 36
   	*/
37
-      private $from                = null;
37
+      private $from = null;
38 38
   	
39 39
   	/**
40 40
   	 * The SQL WHERE statment
41 41
   	 * @var string
42 42
   	*/
43
-      private $where               = null;
43
+      private $where = null;
44 44
   	
45 45
   	/**
46 46
   	 * The SQL LIMIT statment
47 47
   	 * @var string
48 48
   	*/
49
-      private $limit               = null;
49
+      private $limit = null;
50 50
   	
51 51
   	/**
52 52
   	 * The SQL JOIN statment
53 53
   	 * @var string
54 54
   	*/
55
-      private $join                = null;
55
+      private $join = null;
56 56
   	
57 57
   	/**
58 58
   	 * The SQL ORDER BY statment
59 59
   	 * @var string
60 60
   	*/
61
-      private $orderBy             = null;
61
+      private $orderBy = null;
62 62
   	
63 63
   	/**
64 64
   	 * The SQL GROUP BY statment
65 65
   	 * @var string
66 66
   	*/
67
-      private $groupBy             = null;
67
+      private $groupBy = null;
68 68
   	
69 69
   	/**
70 70
   	 * The SQL HAVING statment
71 71
   	 * @var string
72 72
   	*/
73
-      private $having              = null;
73
+      private $having = null;
74 74
   	
75 75
   	/**
76 76
   	 * The full SQL query statment after build for each command
77 77
   	 * @var string
78 78
   	*/
79
-      private $query               = null;
79
+      private $query = null;
80 80
   	
81 81
   	/**
82 82
   	 * The list of SQL valid operators
83 83
   	 * @var array
84 84
   	*/
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
85
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
86 86
   	
87 87
 	
88 88
 	/**
89 89
 	 * The prefix used in each database table
90 90
 	 * @var string
91 91
 	*/
92
-    private $prefix              = null;
92
+    private $prefix = null;
93 93
     
94 94
 
95 95
   /**
96 96
 	 * The PDO instance
97 97
 	 * @var object
98 98
 	*/
99
-  private $pdo                 = null;
99
+  private $pdo = null;
100 100
 	
101 101
   	/**
102 102
   	 * The database driver name used
103 103
   	 * @var string
104 104
   	*/
105
-  	private $driver              = null;
105
+  	private $driver = null;
106 106
   	
107 107
 	
108 108
     /**
109 109
      * Construct new DatabaseQueryBuilder
110 110
      * @param object $pdo the PDO object
111 111
      */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
112
+    public function __construct(PDO $pdo = null) {
113
+        if (is_object($pdo)) {
114 114
           $this->setPdo($pdo);
115 115
         }
116 116
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
      * @param  string|array $table the table name or array of table list
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123
-    public function from($table){
124
-	  if (is_array($table)){
123
+    public function from($table) {
124
+	  if (is_array($table)) {
125 125
         $froms = '';
126
-        foreach($table as $key){
126
+        foreach ($table as $key) {
127 127
           $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  string|array $fields the field name or array of field list
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141
-    public function select($fields){
141
+    public function select($fields) {
142 142
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143 143
       $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144 144
       return $this;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param  string $field the field name to distinct
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152
-    public function distinct($field){
152
+    public function distinct($field) {
153 153
       $distinct = ' DISTINCT ' . $field;
154 154
       $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155 155
       return $this;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * @param  string $name  if is not null represent the alias used for this field in the result
162 162
      * @return object        the current DatabaseQueryBuilder instance
163 163
      */
164
-    public function count($field = '*', $name = null){
164
+    public function count($field = '*', $name = null) {
165 165
       return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param  string $name  if is not null represent the alias used for this field in the result
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174
-    public function min($field, $name = null){
174
+    public function min($field, $name = null) {
175 175
       return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param  string $name  if is not null represent the alias used for this field in the result
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184
-    public function max($field, $name = null){
184
+    public function max($field, $name = null) {
185 185
       return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param  string $name  if is not null represent the alias used for this field in the result
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194
-    public function sum($field, $name = null){
194
+    public function sum($field, $name = null) {
195 195
       return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param  string $name  if is not null represent the alias used for this field in the result
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204
-    public function avg($field, $name = null){
204
+    public function avg($field, $name = null) {
205 205
       return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
       $on = $field1;
220 220
       $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+      if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
       }
226
-      if (empty($this->join)){
226
+      if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228 228
       }
229
-      else{
229
+      else {
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 231
       }
232 232
       return $this;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      * @see  DatabaseQueryBuilder::join()
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
240
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
241 241
       return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @see  DatabaseQueryBuilder::join()
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
249
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
250 250
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
251 251
 	}
252 252
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
258
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
259 259
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @see  DatabaseQueryBuilder::join()
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
267
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
268 268
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * @see  DatabaseQueryBuilder::join()
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
276
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
277 277
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      * @see  DatabaseQueryBuilder::join()
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
285
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
286 286
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295
-    public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
297
-        foreach($field as $f){
295
+    public function whereIsNull($field, $andOr = 'AND') {
296
+      if (is_array($field)) {
297
+        foreach ($field as $f) {
298 298
         	$this->whereIsNull($f, $andOr);
299 299
         }
300 300
       } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
301
+          $this->setWhereStr($field . ' IS NULL ', $andOr);
302 302
       }
303 303
       return $this;
304 304
     }
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312
-    public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
314
-        foreach($field as $f){
312
+    public function whereIsNotNull($field, $andOr = 'AND') {
313
+      if (is_array($field)) {
314
+        foreach ($field as $f) {
315 315
           $this->whereIsNotNull($f, $andOr);
316 316
         }
317 317
       } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
318
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
319 319
       }
320 320
       return $this;
321 321
     }
@@ -330,13 +330,13 @@  discard block
 block discarded – undo
330 330
      * @param  boolean $escape whether to escape or not the $val
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
333
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
334 334
       $whereStr = '';
335
-      if (is_array($where)){
335
+      if (is_array($where)) {
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337 337
       }
338
-      else{
339
-        if (is_array($op)){
338
+      else {
339
+        if (is_array($op)) {
340 340
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342 342
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @see  DatabaseQueryBuilder::where()
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354
-    public function orWhere($where, $op = null, $val = null, $escape = true){
354
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
355 355
       return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * @see  DatabaseQueryBuilder::where()
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364
-    public function notWhere($where, $op = null, $val = null, $escape = true){
364
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
365 365
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      * @see  DatabaseQueryBuilder::where()
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
373
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
374 374
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383
-    public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
383
+    public function groupStart($type = '', $andOr = ' AND') {
384
+      if (empty($this->where)) {
385 385
         $this->where = $type . ' (';
386 386
       } else {
387
-          if (substr(trim($this->where), -1) == '('){
387
+          if (substr(trim($this->where), -1) == '(') {
388 388
             $this->where .= $type . ' (';
389 389
           } else {
390 390
           	$this->where .= $andOr . ' ' . $type . ' (';
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * @see  DatabaseQueryBuilder::groupStart()
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401
-    public function notGroupStart(){
401
+    public function notGroupStart() {
402 402
       return $this->groupStart('NOT');
403 403
     }
404 404
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      * @see  DatabaseQueryBuilder::groupStart()
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410
-    public function orGroupStart(){
410
+    public function orGroupStart() {
411 411
       return $this->groupStart('', ' OR');
412 412
     }
413 413
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @see  DatabaseQueryBuilder::groupStart()
417 417
      * @return object        the current DatabaseQueryBuilder instance
418 418
      */
419
-    public function orNotGroupStart(){
419
+    public function orNotGroupStart() {
420 420
       return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * Close the parenthesis for the grouped SQL
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427
-    public function groupEnd(){
427
+    public function groupEnd() {
428 428
       $this->where .= ')';
429 429
       return $this;
430 430
     }
@@ -438,10 +438,10 @@  discard block
 block discarded – undo
438 438
      * @param  boolean $escape whether to escape or not the values
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
441
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
442 442
       $_keys = array();
443
-      foreach ($keys as $k => $v){
444
-        if (is_null($v)){
443
+      foreach ($keys as $k => $v) {
444
+        if (is_null($v)) {
445 445
           $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      * @see  DatabaseQueryBuilder::in()
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460
-    public function notIn($field, array $keys, $escape = true){
460
+    public function notIn($field, array $keys, $escape = true) {
461 461
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  DatabaseQueryBuilder::in()
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469
-    public function orIn($field, array $keys, $escape = true){
469
+    public function orIn($field, array $keys, $escape = true) {
470 470
       return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @see  DatabaseQueryBuilder::in()
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478
-    public function orNotIn($field, array $keys, $escape = true){
478
+    public function orNotIn($field, array $keys, $escape = true) {
479 479
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
      * @param  boolean $escape whether to escape or not the values
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
492
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
493
+      if (is_null($value1)) {
494 494
         $value1 = '';
495 495
       }
496
-      if (is_null($value2)){
496
+      if (is_null($value2)) {
497 497
         $value2 = '';
498 498
       }
499 499
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @see  DatabaseQueryBuilder::between()
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509
-    public function notBetween($field, $value1, $value2, $escape = true){
509
+    public function notBetween($field, $value1, $value2, $escape = true) {
510 510
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  DatabaseQueryBuilder::between()
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518
-    public function orBetween($field, $value1, $value2, $escape = true){
518
+    public function orBetween($field, $value1, $value2, $escape = true) {
519 519
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  DatabaseQueryBuilder::between()
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527
-    public function orNotBetween($field, $value1, $value2, $escape = true){
527
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
528 528
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
      * @param  boolean $escape whether to escape or not the values
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
540
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
541
+      if (empty($data)) {
542 542
         $data = '';
543 543
       }
544 544
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
      * @see  DatabaseQueryBuilder::like()
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553
-    public function orLike($field, $data, $escape = true){
553
+    public function orLike($field, $data, $escape = true) {
554 554
       return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      * @see  DatabaseQueryBuilder::like()
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562
-    public function notLike($field, $data, $escape = true){
562
+    public function notLike($field, $data, $escape = true) {
563 563
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
      * @see  DatabaseQueryBuilder::like()
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571
-    public function orNotLike($field, $data, $escape = true){
571
+    public function orNotLike($field, $data, $escape = true) {
572 572
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
      * @param  int $limitEnd the limit count
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582
-    public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
582
+    public function limit($limit, $limitEnd = null) {
583
+      if (empty($limit)) {
584 584
         $limit = 0;
585 585
       }
586
-      if (! is_null($limitEnd)){
586
+      if (!is_null($limitEnd)) {
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588 588
       }
589
-      else{
589
+      else {
590 590
         $this->limit = $limit;
591 591
       }
592 592
       return $this;
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
      * @param  string $orderDir the order direction (ASC or DESC)
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601
-    public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
601
+    public function orderBy($orderBy, $orderDir = ' ASC') {
602
+      if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604 604
       }
605
-      else{
605
+      else {
606 606
         $this->orderBy = empty($this->orderBy) 
607 607
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 608
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
      * @param  string|array $field the field name used or array of field list
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618
-    public function groupBy($field){
619
-      if (is_array($field)){
618
+    public function groupBy($field) {
619
+      if (is_array($field)) {
620 620
         $this->groupBy = implode(', ', $field);
621 621
       }
622
-      else{
622
+      else {
623 623
         $this->groupBy = $field;
624 624
       }
625 625
       return $this;
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
      * @param  boolean $escape whether to escape or not the values
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636
-    public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
636
+    public function having($field, $op = null, $val = null, $escape = true) {
637
+      if (is_array($op)) {
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639 639
       }
640
-      else if (! in_array($op, $this->operatorList)){
641
-        if (is_null($op)){
640
+      else if (!in_array($op, $this->operatorList)) {
641
+        if (is_null($op)) {
642 642
           $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645 645
       }
646
-      else{
647
-        if (is_null($val)){
646
+      else {
647
+        if (is_null($val)) {
648 648
           $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      * @param  boolean $escape  whether to escape or not the values
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661
-    public function insert($data = array(), $escape = true){
661
+    public function insert($data = array(), $escape = true) {
662 662
       $columns = array_keys($data);
663 663
       $column = implode(',', $columns);
664 664
       $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
      * @param  boolean $escape  whether to escape or not the values
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676
-    public function update($data = array(), $escape = true){
676
+    public function update($data = array(), $escape = true) {
677 677
       $query = 'UPDATE ' . $this->from . ' SET ';
678 678
       $values = array();
679
-      foreach ($data as $column => $val){
679
+      foreach ($data as $column => $val) {
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681 681
       }
682 682
       $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
683
+      if (!empty($this->where)) {
684 684
         $query .= ' WHERE ' . $this->where;
685 685
       }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+      if (!empty($this->orderBy)) {
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689 689
       }
690 690
 
691
-      if (! empty($this->limit)){
691
+      if (!empty($this->limit)) {
692 692
         $query .= ' LIMIT ' . $this->limit;
693 693
       }
694 694
       $this->query = $query;
@@ -699,22 +699,22 @@  discard block
 block discarded – undo
699 699
      * Delete the record in database
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702
-    public function delete(){
702
+    public function delete() {
703 703
     	$query = 'DELETE FROM ' . $this->from;
704 704
       $isTruncate = $query;
705
-    	if (! empty($this->where)){
705
+    	if (!empty($this->where)) {
706 706
   		  $query .= ' WHERE ' . $this->where;
707 707
     	}
708 708
 
709
-    	if (! empty($this->orderBy)){
709
+    	if (!empty($this->orderBy)) {
710 710
     	  $query .= ' ORDER BY ' . $this->orderBy;
711 711
       }
712 712
 
713
-    	if (! empty($this->limit)){
713
+    	if (!empty($this->limit)) {
714 714
     		$query .= ' LIMIT ' . $this->limit;
715 715
       }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
717
+  		if ($isTruncate == $query && $this->driver != 'sqlite') {  
718 718
       	$query = 'TRUNCATE TABLE ' . $this->from;
719 719
   		}
720 720
 	   $this->query = $query;
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
      * @param boolean $escaped whether we can do escape of not 
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730
-    public function escape($data, $escaped = true){
730
+    public function escape($data, $escaped = true) {
731 731
       return $escaped 
732 732
                     ? $this->getPdo()->quote(trim($data)) 
733 733
                     : $data; 
@@ -738,31 +738,31 @@  discard block
 block discarded – undo
738 738
      * Return the current SQL query string
739 739
      * @return string
740 740
      */
741
-    public function getQuery(){
741
+    public function getQuery() {
742 742
   	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
743
-  	  if(empty($this->query)){
743
+  	  if (empty($this->query)) {
744 744
   		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
745
-  		  if (! empty($this->join)){
745
+  		  if (!empty($this->join)) {
746 746
           $query .= $this->join;
747 747
   		  }
748 748
   		  
749
-  		  if (! empty($this->where)){
749
+  		  if (!empty($this->where)) {
750 750
           $query .= ' WHERE ' . $this->where;
751 751
   		  }
752 752
 
753
-  		  if (! empty($this->groupBy)){
753
+  		  if (!empty($this->groupBy)) {
754 754
           $query .= ' GROUP BY ' . $this->groupBy;
755 755
   		  }
756 756
 
757
-  		  if (! empty($this->having)){
757
+  		  if (!empty($this->having)) {
758 758
           $query .= ' HAVING ' . $this->having;
759 759
   		  }
760 760
 
761
-  		  if (! empty($this->orderBy)){
761
+  		  if (!empty($this->orderBy)) {
762 762
   			  $query .= ' ORDER BY ' . $this->orderBy;
763 763
   		  }
764 764
 
765
-  		  if (! empty($this->limit)){
765
+  		  if (!empty($this->limit)) {
766 766
           $query .= ' LIMIT ' . $this->limit;
767 767
   		  }
768 768
   		  $this->query = $query;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      * Return the PDO instance
776 776
      * @return PDO
777 777
      */
778
-    public function getPdo(){
778
+    public function getPdo() {
779 779
       return $this->pdo;
780 780
     }
781 781
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
      * @param PDO $pdo the pdo object
785 785
 	 * @return object DatabaseQueryBuilder
786 786
      */
787
-    public function setPdo(PDO $pdo = null){
787
+    public function setPdo(PDO $pdo = null) {
788 788
       $this->pdo = $pdo;
789 789
       return $this;
790 790
     }
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
    * Return the database table prefix
794 794
    * @return string
795 795
    */
796
-    public function getPrefix(){
796
+    public function getPrefix() {
797 797
       return $this->prefix;
798 798
     }
799 799
 
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
      * @param string $prefix the new prefix
803 803
 	   * @return object DatabaseQueryBuilder
804 804
      */
805
-    public function setPrefix($prefix){
805
+    public function setPrefix($prefix) {
806 806
       $this->prefix = $prefix;
807 807
       return $this;
808 808
     }
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
      * Return the database driver
812 812
      * @return string
813 813
      */
814
-    public function getDriver(){
814
+    public function getDriver() {
815 815
       return $this->driver;
816 816
     }
817 817
 
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
      * @param string $driver the new driver
821 821
 	   * @return object DatabaseQueryBuilder
822 822
      */
823
-    public function setDriver($driver){
823
+    public function setDriver($driver) {
824 824
       $this->driver = $driver;
825 825
       return $this;
826 826
     }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
      * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
830 830
 	   * @return object  the current DatabaseQueryBuilder instance 
831 831
      */
832
-    public function reset(){
832
+    public function reset() {
833 833
       $this->select   = '*';
834 834
       $this->from     = null;
835 835
       $this->where    = null;
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
      *
849 849
      * @return string
850 850
      */
851
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
851
+    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) {
852 852
         $x = explode('?', $field);
853 853
         $w = '';
854
-        foreach($x as $k => $v){
855
-  	      if (!empty($v)){
856
-            if (! isset($op[$k])){
854
+        foreach ($x as $k => $v) {
855
+  	      if (!empty($v)) {
856
+            if (!isset($op[$k])) {
857 857
               $op[$k] = '';
858 858
             }
859 859
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -869,15 +869,15 @@  discard block
 block discarded – undo
869 869
      *
870 870
      * @return string
871 871
      */
872
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
872
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
873 873
       $_where = array();
874
-      foreach ($where as $column => $data){
875
-        if (is_null($data)){
874
+      foreach ($where as $column => $data) {
875
+        if (is_null($data)) {
876 876
           $data = '';
877 877
         }
878 878
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
879 879
       }
880
-      $where = implode(' '.$andOr.' ', $_where);
880
+      $where = implode(' ' . $andOr . ' ', $_where);
881 881
       return $where;
882 882
     }
883 883
 
@@ -887,12 +887,12 @@  discard block
 block discarded – undo
887 887
      *
888 888
      * @return string
889 889
      */
890
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
890
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
891 891
      $x = explode('?', $where);
892 892
      $w = '';
893
-      foreach($x as $k => $v){
894
-        if (! empty($v)){
895
-            if (isset($op[$k]) && is_null($op[$k])){
893
+      foreach ($x as $k => $v) {
894
+        if (!empty($v)) {
895
+            if (isset($op[$k]) && is_null($op[$k])) {
896 896
               $op[$k] = '';
897 897
             }
898 898
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -907,15 +907,15 @@  discard block
 block discarded – undo
907 907
      *
908 908
      * @return string
909 909
      */
910
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
910
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
911 911
        $w = '';
912
-       if (! in_array((string)$op, $this->operatorList)){
913
-          if (is_null($op)){
912
+       if (!in_array((string) $op, $this->operatorList)) {
913
+          if (is_null($op)) {
914 914
             $op = '';
915 915
           }
916 916
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917 917
         } else {
918
-          if (is_null($val)){
918
+          if (is_null($val)) {
919 919
             $val = '';
920 920
           }
921 921
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -928,14 +928,14 @@  discard block
 block discarded – undo
928 928
        * @param string $whereStr the WHERE clause string
929 929
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
930 930
        */
931
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
932
-        if (empty($this->where)){
931
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
932
+        if (empty($this->where)) {
933 933
           $this->where = $whereStr;
934 934
         } else {
935
-          if (substr(trim($this->where), -1) == '('){
935
+          if (substr(trim($this->where), -1) == '(') {
936 936
             $this->where = $this->where . ' ' . $whereStr;
937 937
           } else {
938
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
938
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
939 939
           }
940 940
         }
941 941
       }
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
      * @see  DatabaseQueryBuilder::avg
952 952
      * @return object
953 953
      */
954
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
954
+    protected function select_min_max_sum_count_avg($clause, $field, $name = null) {
955 955
       $clause = strtoupper($clause);
956 956
       $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
957 957
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
Please login to merge, or discard this patch.
core/classes/Loader.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,33 +332,33 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			if(file_exists($configFilePath)){
354
+			if (file_exists($configFilePath)) {
355 355
 				require_once $configFilePath;
356
-				if(! empty($config) && is_array($config)){
356
+				if (!empty($config) && is_array($config)) {
357 357
 					Config::setAll($config);
358 358
 				}
359 359
 			}
360
-			else{
361
-				show_error('Unable to find config file ['. $configFilePath . ']');
360
+			else {
361
+				show_error('Unable to find config file [' . $configFilePath . ']');
362 362
 			}
363 363
 			static::$loaded['config_' . $filename] = $configFilePath;
364 364
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 		 *
375 375
 		 * @return void
376 376
 		 */
377
-		public static function lang($language){
377
+		public static function lang($language) {
378 378
 			$logger = static::getLogger();
379 379
 			$language = str_ireplace('.php', '', $language);
380 380
 			$language = trim($language, '/\\');
381 381
 			$language = str_ireplace('lang_', '', $language);
382
-			$file = 'lang_'.$language.'.php';
382
+			$file = 'lang_' . $language . '.php';
383 383
 			$logger->debug('Loading language [' . $language . '] ...');
384
-			if(isset(static::$loaded['lang_' . $language])){
384
+			if (isset(static::$loaded['lang_' . $language])) {
385 385
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
386 386
 				return;
387 387
 			}
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			$cfgKey = get_config('language_cookie_name');
392 392
 			$objCookie = & class_loader('Cookie');
393 393
 			$cookieLang = $objCookie->get($cfgKey);
394
-			if($cookieLang){
394
+			if ($cookieLang) {
395 395
 				$appLang = $cookieLang;
396 396
 			}
397 397
 			$languageFilePath = null;
@@ -400,30 +400,30 @@  discard block
 block discarded – undo
400 400
 			$searchModuleName = null;
401 401
 			$obj = & get_instance();
402 402
 			//check if the request class contains module name
403
-			if(strpos($language, '/') !== false){
403
+			if (strpos($language, '/') !== false) {
404 404
 				$path = explode('/', $language);
405
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
405
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
406 406
 					$searchModuleName = $path[0];
407 407
 					$language = 'lang_' . $path[1] . '.php';
408
-					$file = $path[0] . DS .$language;
408
+					$file = $path[0] . DS . $language;
409 409
 				}
410 410
 			}
411
-			if(! $searchModuleName && !empty($obj->moduleName)){
411
+			if (!$searchModuleName && !empty($obj->moduleName)) {
412 412
 				$searchModuleName = $obj->moduleName;
413 413
 			}
414 414
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
415
-			if($moduleLanguagePath){
416
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
415
+			if ($moduleLanguagePath) {
416
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
417 417
 				$languageFilePath = $moduleLanguagePath;
418 418
 			}
419
-			else{
419
+			else {
420 420
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
421 421
 			}
422
-			if(! $languageFilePath){
422
+			if (!$languageFilePath) {
423 423
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
424
-				foreach($searchDir as $dir){
424
+				foreach ($searchDir as $dir) {
425 425
 					$filePath = $dir . $appLang . DS . $file;
426
-					if(file_exists($filePath)){
426
+					if (file_exists($filePath)) {
427 427
 						$languageFilePath = $filePath;
428 428
 						//is already found not to continue
429 429
 						break;
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 				}
432 432
 			}
433 433
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
434
-			if($languageFilePath){
434
+			if ($languageFilePath) {
435 435
 				require_once $languageFilePath;
436
-				if(! empty($lang) && is_array($lang)){
437
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
436
+				if (!empty($lang) && is_array($lang)) {
437
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
438 438
 					//Note: may be here the class 'Lang' not yet loaded
439
-					$langObj =& class_loader('Lang', 'classes');
439
+					$langObj = & class_loader('Lang', 'classes');
440 440
 					$langObj->addLangMessages($lang);
441 441
 					//free the memory
442 442
 					unset($lang);
@@ -444,13 +444,13 @@  discard block
 block discarded – undo
444 444
 				static::$loaded['lang_' . $language] = $languageFilePath;
445 445
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
446 446
 			}
447
-			else{
447
+			else {
448 448
 				show_error('Unable to find language file [' . $file . ']');
449 449
 			}
450 450
 		}
451 451
 
452 452
 
453
-		private function getResourcesFromAutoloadConfig(){
453
+		private function getResourcesFromAutoloadConfig() {
454 454
 			$autoloads = array();
455 455
 			$autoloads['config']    = array();
456 456
 			$autoloads['languages'] = array();
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
 			$autoloads['models']    = array();
459 459
 			$autoloads['functions'] = array();
460 460
 			//loading of the resources in autoload.php configuration file
461
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
461
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
462 462
 				require_once CONFIG_PATH . 'autoload.php';
463
-				if(! empty($autoload) && is_array($autoload)){
463
+				if (!empty($autoload) && is_array($autoload)) {
464 464
 					$autoloads = array_merge($autoloads, $autoload);
465 465
 					unset($autoload);
466 466
 				}
467 467
 			}
468 468
 			//loading autoload configuration for modules
469 469
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
470
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
470
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
471 471
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
472 472
 			}
473 473
 			return $autoloads;
474 474
 		}
475 475
 
476
-		private function loadResourcesFromAutoloadConfig(){
476
+		private function loadResourcesFromAutoloadConfig() {
477 477
 			$autoloads = array();
478 478
 			$autoloads['config']    = array();
479 479
 			$autoloads['languages'] = array();
@@ -485,28 +485,28 @@  discard block
 block discarded – undo
485 485
 
486 486
 			$autoloads = array_merge($autoloads, $list);
487 487
 			//config autoload
488
-			foreach($autoloads['config'] as $c){
488
+			foreach ($autoloads['config'] as $c) {
489 489
 				$this->config($c);
490 490
 			}
491 491
 			
492 492
 			//languages autoload
493
-			foreach($autoloads['languages'] as $language){
493
+			foreach ($autoloads['languages'] as $language) {
494 494
 				$this->lang($language);
495 495
 			}
496 496
 			
497 497
 			//libraries autoload
498
-			foreach($autoloads['libraries'] as $library){
498
+			foreach ($autoloads['libraries'] as $library) {
499 499
 				$this->library($library);
500 500
 			}
501 501
 
502 502
 			//models autoload
503
-			if(! empty($autoloads['models']) && is_array($autoloads['models'])){
504
-				foreach($autoloads['models'] as $model){
503
+			if (!empty($autoloads['models']) && is_array($autoloads['models'])) {
504
+				foreach ($autoloads['models'] as $model) {
505 505
 					$this->model($model);
506 506
 				}
507 507
 			}
508 508
 			
509
-			foreach($autoloads['functions'] as $function){
509
+			foreach ($autoloads['functions'] as $function) {
510 510
 				$this->functions($function);
511 511
 			}
512 512
 		}
Please login to merge, or discard this patch.