Passed
Branch php-cs-fixer (b9836a)
by Fabio
15:58
created
framework/Data/ActiveRecord/TActiveRecord.php 2 patches
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function __construct($data = [], $connection = null)
230 230
 	{
231
-		if($connection !== null)
231
+		if ($connection !== null)
232 232
 			$this->setDbConnection($connection);
233 233
 		$this->setupColumnMapping();
234 234
 		$this->setupRelations();
235
-		if(!empty($data)) //$data may be an object
235
+		if (!empty($data)) //$data may be an object
236 236
 			$this->copyFrom($data);
237 237
 	}
238 238
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 	 */
247 247
 	public function __get($name)
248 248
 	{
249
-		if($this->hasRecordRelation($name) && !$this->canGetProperty($name))
249
+		if ($this->hasRecordRelation($name) && !$this->canGetProperty($name))
250 250
 		{
251 251
 			$this->fetchResultsFor($name);
252 252
 			return $this->$name;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 */
265 265
 	public function __set($name, $value)
266 266
 	{
267
-		if($this->hasRecordRelation($name) && !$this->canSetProperty($name))
267
+		if ($this->hasRecordRelation($name) && !$this->canSetProperty($name))
268 268
 			$this->$name = $value;
269 269
 		else
270 270
 			parent::__set($name, $value);
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	private function setupColumnMapping()
277 277
 	{
278 278
 		$className = get_class($this);
279
-		if(!isset(self::$_columnMapping[$className]))
279
+		if (!isset(self::$_columnMapping[$className]))
280 280
 		{
281 281
 			$class = new ReflectionClass($className);
282 282
 			self::$_columnMapping[$className] = $class->getStaticPropertyValue('COLUMN_MAPPING');
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	private function setupRelations()
290 290
 	{
291 291
 		$className = get_class($this);
292
-		if(!isset(self::$_relations[$className]))
292
+		if (!isset(self::$_relations[$className]))
293 293
 		{
294 294
 			$class = new ReflectionClass($className);
295 295
 			$relations = [];
296
-			foreach($class->getStaticPropertyValue('RELATIONS') as $key => $value)
297
-				$relations[strtolower($key)] = [$key,$value];
296
+			foreach ($class->getStaticPropertyValue('RELATIONS') as $key => $value)
297
+				$relations[strtolower($key)] = [$key, $value];
298 298
 			self::$_relations[$className] = $relations;
299 299
 		}
300 300
 	}
@@ -305,18 +305,18 @@  discard block
 block discarded – undo
305 305
 	 */
306 306
 	public function copyFrom($data)
307 307
 	{
308
-		if(is_object($data))
308
+		if (is_object($data))
309 309
 			$data = get_object_vars($data);
310
-		if(!is_array($data))
310
+		if (!is_array($data))
311 311
 			throw new TActiveRecordException('ar_data_invalid', get_class($this));
312
-		foreach($data as $name => $value)
312
+		foreach ($data as $name => $value)
313 313
 			$this->setColumnValue($name, $value);
314 314
 	}
315 315
 
316 316
 
317 317
 	public static function getActiveDbConnection()
318 318
 	{
319
-		if(($db = self::getRecordManager()->getDbConnection()) !== null)
319
+		if (($db = self::getRecordManager()->getDbConnection()) !== null)
320 320
 			$db->setActive(true);
321 321
 		return $db;
322 322
 	}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	 */
329 329
 	public function getDbConnection()
330 330
 	{
331
-		if($this->_connection === null)
331
+		if ($this->_connection === null)
332 332
 			$this->_connection = self::getActiveDbConnection();
333 333
 		return $this->_connection;
334 334
 	}
@@ -359,19 +359,19 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	public function equals(TActiveRecord $record, $strict = false)
361 361
 	{
362
-		if($record === null || get_class($this) !== get_class($record))
362
+		if ($record === null || get_class($this) !== get_class($record))
363 363
 			return false;
364 364
 		$tableInfo = $this->getRecordTableInfo();
365 365
 		$pks = $tableInfo->getPrimaryKeys();
366 366
 		$properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys();
367 367
 		$equals = true;
368
-		foreach($properties as $prop)
368
+		foreach ($properties as $prop)
369 369
 		{
370
-			if($strict)
370
+			if ($strict)
371 371
 				$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
372 372
 			else
373 373
 				$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
374
-			if(!$equals)
374
+			if (!$equals)
375 375
 				return false;
376 376
 		}
377 377
 		return $equals;
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	public static function finder($className = __CLASS__)
390 390
 	{
391 391
 		static $finders = [];
392
-		if(!isset($finders[$className]))
392
+		if (!isset($finders[$className]))
393 393
 		{
394 394
 			$f = Prado::createComponent($className);
395 395
 			$finders[$className] = $f;
@@ -423,19 +423,19 @@  discard block
 block discarded – undo
423 423
 	{
424 424
 		$gateway = $this->getRecordGateway();
425 425
 		$param = new TActiveRecordChangeEventParameter();
426
-		if($this->_recordState === self::STATE_NEW)
426
+		if ($this->_recordState === self::STATE_NEW)
427 427
 		{
428 428
 			$this->onInsert($param);
429
-			if($param->getIsValid() && $gateway->insert($this))
429
+			if ($param->getIsValid() && $gateway->insert($this))
430 430
 			{
431 431
 				$this->_recordState = self::STATE_LOADED;
432 432
 				return true;
433 433
 			}
434 434
 		}
435
-		elseif($this->_recordState === self::STATE_LOADED)
435
+		elseif ($this->_recordState === self::STATE_LOADED)
436 436
 		{
437 437
 			$this->onUpdate($param);
438
-			if($param->getIsValid() && $gateway->update($this))
438
+			if ($param->getIsValid() && $gateway->update($this))
439 439
 				return true;
440 440
 		}
441 441
 		else
@@ -451,12 +451,12 @@  discard block
 block discarded – undo
451 451
 	 */
452 452
 	public function delete()
453 453
 	{
454
-		if($this->_recordState === self::STATE_LOADED)
454
+		if ($this->_recordState === self::STATE_LOADED)
455 455
 		{
456 456
 			$gateway = $this->getRecordGateway();
457 457
 			$param = new TActiveRecordChangeEventParameter();
458 458
 			$this->onDelete($param);
459
-			if($param->getIsValid() && $gateway->delete($this))
459
+			if ($param->getIsValid() && $gateway->delete($this))
460 460
 			{
461 461
 				$this->_recordState = self::STATE_DELETED;
462 462
 				return true;
@@ -493,9 +493,9 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function deleteByPk($keys)
495 495
 	{
496
-		if(func_num_args() > 1)
496
+		if (func_num_args() > 1)
497 497
 			$keys = func_get_args();
498
-		return $this->getRecordGateway()->deleteRecordsByPk($this, (array)$keys);
498
+		return $this->getRecordGateway()->deleteRecordsByPk($this, (array) $keys);
499 499
 	}
500 500
 
501 501
 	/**
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	public function deleteAllByPks($keys)
505 505
 	{
506
-		if(func_num_args() > 1)
506
+		if (func_num_args() > 1)
507 507
 			$keys = func_get_args();
508 508
 		return $this->deleteByPk($keys);
509 509
 	}
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	protected function populateObjects($reader)
540 540
 	{
541 541
 		$result = [];
542
-		foreach($reader as $data)
542
+		foreach ($reader as $data)
543 543
 			$result[] = $this->populateObject($data);
544 544
 		return $result;
545 545
 	}
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 	 */
556 556
 	public static function createRecord($type, $data)
557 557
 	{
558
-		if(empty($data))
558
+		if (empty($data))
559 559
 			return null;
560 560
 		$record = new $type($data);
561 561
 		$record->_recordState = self::STATE_LOADED;
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	public function findAll($criteria = null, $parameters = [])
599 599
 	{
600 600
 		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
601
-		if($criteria !== null)
601
+		if ($criteria !== null)
602 602
 			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
603 603
 		$result = $this->getRecordGateway()->findRecordsByCriteria($this, $criteria, true);
604 604
 		return $this->populateObjects($result);
@@ -618,9 +618,9 @@  discard block
 block discarded – undo
618 618
 	 */
619 619
 	public function findByPk($keys)
620 620
 	{
621
-		if($keys === null)
621
+		if ($keys === null)
622 622
 			return null;
623
-		if(func_num_args() > 1)
623
+		if (func_num_args() > 1)
624 624
 			$keys = func_get_args();
625 625
 		$data = $this->getRecordGateway()->findRecordByPK($this, $keys);
626 626
 		return $this->populateObject($data);
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 	 */
646 646
 	public function findAllByPks($keys)
647 647
 	{
648
-		if(func_num_args() > 1)
648
+		if (func_num_args() > 1)
649 649
 			$keys = func_get_args();
650
-		$result = $this->getRecordGateway()->findRecordsByPks($this, (array)$keys);
650
+		$result = $this->getRecordGateway()->findRecordsByPks($this, (array) $keys);
651 651
 		return $this->populateObjects($result);
652 652
 	}
653 653
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	public function count($criteria = null, $parameters = [])
712 712
 	{
713 713
 		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
714
-		if($criteria !== null)
714
+		if ($criteria !== null)
715 715
 			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
716 716
 		return $this->getRecordGateway()->countRecords($this, $criteria);
717 717
 	}
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 */
726 726
 	protected function getRelationHandler($name, $args = [])
727 727
 	{
728
-		if(($context = $this->createRelationContext($name)) !== null)
728
+		if (($context = $this->createRelationContext($name)) !== null)
729 729
 		{
730 730
 			$criteria = $this->getRecordCriteria(count($args) > 0 ? $args[0] : null, array_slice($args, 1));
731 731
 			return $context->getRelationHandler($criteria);
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 	 */
746 746
 	protected function createRelationContext($name)
747 747
 	{
748
-		if(($definition = $this->getRecordRelation($name)) !== null)
748
+		if (($definition = $this->getRecordRelation($name)) !== null)
749 749
 		{
750 750
 			list($property, $relation) = $definition;
751 751
 			return new TActiveRecordRelationContext($this, $property, $relation);
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 */
792 792
 	protected function fetchResultsFor($property)
793 793
 	{
794
-		if(($context = $this->createRelationContext($property)) !== null)
794
+		if (($context = $this->createRelationContext($property)) !== null)
795 795
 			return $context->getRelationHandler()->fetchResultsInto($this);
796 796
 		else
797 797
 			return false;
@@ -829,29 +829,29 @@  discard block
 block discarded – undo
829 829
 	public function __call($method, $args)
830 830
 	{
831 831
 		$delete = false;
832
-		if(strncasecmp($method, 'with', 4) === 0)
832
+		if (strncasecmp($method, 'with', 4) === 0)
833 833
 		{
834 834
 			$property = $method[4] === '_' ? substr($method, 5) : substr($method, 4);
835 835
 			return $this->getRelationHandler($property, $args);
836 836
 		}
837
-		elseif($findOne = strncasecmp($method, 'findby', 6) === 0)
837
+		elseif ($findOne = strncasecmp($method, 'findby', 6) === 0)
838 838
 			$condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6);
839
-		elseif(strncasecmp($method, 'findallby', 9) === 0)
839
+		elseif (strncasecmp($method, 'findallby', 9) === 0)
840 840
 			$condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9);
841
-		elseif($delete = strncasecmp($method, 'deleteby', 8) === 0)
841
+		elseif ($delete = strncasecmp($method, 'deleteby', 8) === 0)
842 842
 			$condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8);
843
-		elseif($delete = strncasecmp($method, 'deleteallby', 11) === 0)
843
+		elseif ($delete = strncasecmp($method, 'deleteallby', 11) === 0)
844 844
 			$condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11);
845 845
 		else
846 846
 		{
847
-			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
847
+			if ($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
848 848
 				throw new TActiveRecordException('ar_invalid_finder_method', $method);
849 849
 			else
850 850
 				return null;
851 851
 		}
852 852
 
853 853
 		$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
854
-		if($delete)
854
+		if ($delete)
855 855
 			return $this->deleteAll($criteria);
856 856
 		else
857 857
 			return $findOne ? $this->find($criteria) : $this->findAll($criteria);
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 	 */
865 865
 	public function getInvalidFinderResult()
866 866
 	{
867
-		if($this->_invalidFinderResult !== null)
867
+		if ($this->_invalidFinderResult !== null)
868 868
 			return $this->_invalidFinderResult;
869 869
 
870 870
 		return self::getRecordManager()->getInvalidFinderResult();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 	 */
880 880
 	public function setInvalidFinderResult($value)
881 881
 	{
882
-		if($value === null)
882
+		if ($value === null)
883 883
 			$this->_invalidFinderResult = null;
884 884
 		else
885 885
 			$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'Prado\\Data\\ActiveRecord\\TActiveRecordInvalidFinderResult');
@@ -896,12 +896,12 @@  discard block
 block discarded – undo
896 896
 	 */
897 897
 	protected function getRecordCriteria($criteria, $parameters, $args = [])
898 898
 	{
899
-		if(is_string($criteria))
899
+		if (is_string($criteria))
900 900
 		{
901 901
 			$useArgs = !is_array($parameters) && is_array($args);
902 902
 			return new TActiveRecordCriteria($criteria, $useArgs ? $args : $parameters);
903 903
 		}
904
-		elseif($criteria instanceof TSqlCriteria)
904
+		elseif ($criteria instanceof TSqlCriteria)
905 905
 			return $criteria;
906 906
 		else
907 907
 			return new TActiveRecordCriteria();
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
 	public function getColumnValue($columnName)
982 982
 	{
983 983
 		$className = get_class($this);
984
-		if(isset(self::$_columnMapping[$className][$columnName]))
984
+		if (isset(self::$_columnMapping[$className][$columnName]))
985 985
 			$columnName = self::$_columnMapping[$className][$columnName];
986 986
 		return $this->$columnName;
987 987
 	}
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 	public function setColumnValue($columnName, $value)
997 997
 	{
998 998
 		$className = get_class($this);
999
-		if(isset(self::$_columnMapping[$className][$columnName]))
999
+		if (isset(self::$_columnMapping[$className][$columnName]))
1000 1000
 			$columnName = self::$_columnMapping[$className][$columnName];
1001 1001
 		$this->$columnName = $value;
1002 1002
 	}
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 	{
1011 1011
 		$className = get_class($this);
1012 1012
 		$property = strtolower($property);
1013
-		return isset(self::$_relations[$className][$property])?self::$_relations[$className][$property]:null;
1013
+		return isset(self::$_relations[$className][$property]) ?self::$_relations[$className][$property] : null;
1014 1014
 	}
1015 1015
 
1016 1016
 	/**
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
 		 * @return array of column name and column values
1038 1038
 		 * @since 3.2.4
1039 1039
 		 */
1040
-		public function toArray(){
1040
+		public function toArray() {
1041 1041
 			$result = [];
1042
-			foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){
1042
+			foreach ($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName) {
1043 1043
 					$result[$columnName] = $this->getColumnValue($columnName);
1044 1044
 			   }
1045 1045
 		
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 		 * @return JSON
1052 1052
 		 * @since 3.2.4
1053 1053
 		 */
1054
-		public function toJSON(){
1054
+		public function toJSON() {
1055 1055
 			return json_encode($this->toArray());
1056 1056
 		}
1057 1057
 }
1058 1058
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +121 added lines, -93 removed lines patch added patch discarded remove patch
@@ -228,12 +228,15 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function __construct($data = [], $connection = null)
230 230
 	{
231
-		if($connection !== null)
232
-			$this->setDbConnection($connection);
231
+		if($connection !== null) {
232
+					$this->setDbConnection($connection);
233
+		}
233 234
 		$this->setupColumnMapping();
234 235
 		$this->setupRelations();
235
-		if(!empty($data)) //$data may be an object
236
+		if(!empty($data)) {
237
+			//$data may be an object
236 238
 			$this->copyFrom($data);
239
+		}
237 240
 	}
238 241
 
239 242
 	/**
@@ -264,10 +267,11 @@  discard block
 block discarded – undo
264 267
 	 */
265 268
 	public function __set($name, $value)
266 269
 	{
267
-		if($this->hasRecordRelation($name) && !$this->canSetProperty($name))
268
-			$this->$name = $value;
269
-		else
270
-			parent::__set($name, $value);
270
+		if($this->hasRecordRelation($name) && !$this->canSetProperty($name)) {
271
+					$this->$name = $value;
272
+		} else {
273
+					parent::__set($name, $value);
274
+		}
271 275
 	}
272 276
 
273 277
 	/**
@@ -293,8 +297,9 @@  discard block
 block discarded – undo
293 297
 		{
294 298
 			$class = new ReflectionClass($className);
295 299
 			$relations = [];
296
-			foreach($class->getStaticPropertyValue('RELATIONS') as $key => $value)
297
-				$relations[strtolower($key)] = [$key,$value];
300
+			foreach($class->getStaticPropertyValue('RELATIONS') as $key => $value) {
301
+							$relations[strtolower($key)] = [$key,$value];
302
+			}
298 303
 			self::$_relations[$className] = $relations;
299 304
 		}
300 305
 	}
@@ -305,19 +310,23 @@  discard block
 block discarded – undo
305 310
 	 */
306 311
 	public function copyFrom($data)
307 312
 	{
308
-		if(is_object($data))
309
-			$data = get_object_vars($data);
310
-		if(!is_array($data))
311
-			throw new TActiveRecordException('ar_data_invalid', get_class($this));
312
-		foreach($data as $name => $value)
313
-			$this->setColumnValue($name, $value);
313
+		if(is_object($data)) {
314
+					$data = get_object_vars($data);
315
+		}
316
+		if(!is_array($data)) {
317
+					throw new TActiveRecordException('ar_data_invalid', get_class($this));
318
+		}
319
+		foreach($data as $name => $value) {
320
+					$this->setColumnValue($name, $value);
321
+		}
314 322
 	}
315 323
 
316 324
 
317 325
 	public static function getActiveDbConnection()
318 326
 	{
319
-		if(($db = self::getRecordManager()->getDbConnection()) !== null)
320
-			$db->setActive(true);
327
+		if(($db = self::getRecordManager()->getDbConnection()) !== null) {
328
+					$db->setActive(true);
329
+		}
321 330
 		return $db;
322 331
 	}
323 332
 
@@ -328,8 +337,9 @@  discard block
 block discarded – undo
328 337
 	 */
329 338
 	public function getDbConnection()
330 339
 	{
331
-		if($this->_connection === null)
332
-			$this->_connection = self::getActiveDbConnection();
340
+		if($this->_connection === null) {
341
+					$this->_connection = self::getActiveDbConnection();
342
+		}
333 343
 		return $this->_connection;
334 344
 	}
335 345
 
@@ -359,20 +369,23 @@  discard block
 block discarded – undo
359 369
 	 */
360 370
 	public function equals(TActiveRecord $record, $strict = false)
361 371
 	{
362
-		if($record === null || get_class($this) !== get_class($record))
363
-			return false;
372
+		if($record === null || get_class($this) !== get_class($record)) {
373
+					return false;
374
+		}
364 375
 		$tableInfo = $this->getRecordTableInfo();
365 376
 		$pks = $tableInfo->getPrimaryKeys();
366 377
 		$properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys();
367 378
 		$equals = true;
368 379
 		foreach($properties as $prop)
369 380
 		{
370
-			if($strict)
371
-				$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
372
-			else
373
-				$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
374
-			if(!$equals)
375
-				return false;
381
+			if($strict) {
382
+							$equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop);
383
+			} else {
384
+							$equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop);
385
+			}
386
+			if(!$equals) {
387
+							return false;
388
+			}
376 389
 		}
377 390
 		return $equals;
378 391
 	}
@@ -431,15 +444,15 @@  discard block
 block discarded – undo
431 444
 				$this->_recordState = self::STATE_LOADED;
432 445
 				return true;
433 446
 			}
434
-		}
435
-		elseif($this->_recordState === self::STATE_LOADED)
447
+		} elseif($this->_recordState === self::STATE_LOADED)
436 448
 		{
437 449
 			$this->onUpdate($param);
438
-			if($param->getIsValid() && $gateway->update($this))
439
-				return true;
450
+			if($param->getIsValid() && $gateway->update($this)) {
451
+							return true;
452
+			}
453
+		} else {
454
+					throw new TActiveRecordException('ar_save_invalid', get_class($this));
440 455
 		}
441
-		else
442
-			throw new TActiveRecordException('ar_save_invalid', get_class($this));
443 456
 
444 457
 		return false;
445 458
 	}
@@ -461,9 +474,9 @@  discard block
 block discarded – undo
461 474
 				$this->_recordState = self::STATE_DELETED;
462 475
 				return true;
463 476
 			}
477
+		} else {
478
+					throw new TActiveRecordException('ar_delete_invalid', get_class($this));
464 479
 		}
465
-		else
466
-			throw new TActiveRecordException('ar_delete_invalid', get_class($this));
467 480
 
468 481
 		return false;
469 482
 	}
@@ -493,8 +506,9 @@  discard block
 block discarded – undo
493 506
 	 */
494 507
 	public function deleteByPk($keys)
495 508
 	{
496
-		if(func_num_args() > 1)
497
-			$keys = func_get_args();
509
+		if(func_num_args() > 1) {
510
+					$keys = func_get_args();
511
+		}
498 512
 		return $this->getRecordGateway()->deleteRecordsByPk($this, (array)$keys);
499 513
 	}
500 514
 
@@ -503,8 +517,9 @@  discard block
 block discarded – undo
503 517
 	 */
504 518
 	public function deleteAllByPks($keys)
505 519
 	{
506
-		if(func_num_args() > 1)
507
-			$keys = func_get_args();
520
+		if(func_num_args() > 1) {
521
+					$keys = func_get_args();
522
+		}
508 523
 		return $this->deleteByPk($keys);
509 524
 	}
510 525
 	/**
@@ -539,8 +554,9 @@  discard block
 block discarded – undo
539 554
 	protected function populateObjects($reader)
540 555
 	{
541 556
 		$result = [];
542
-		foreach($reader as $data)
543
-			$result[] = $this->populateObject($data);
557
+		foreach($reader as $data) {
558
+					$result[] = $this->populateObject($data);
559
+		}
544 560
 		return $result;
545 561
 	}
546 562
 
@@ -555,8 +571,9 @@  discard block
 block discarded – undo
555 571
 	 */
556 572
 	public static function createRecord($type, $data)
557 573
 	{
558
-		if(empty($data))
559
-			return null;
574
+		if(empty($data)) {
575
+					return null;
576
+		}
560 577
 		$record = new $type($data);
561 578
 		$record->_recordState = self::STATE_LOADED;
562 579
 		return $record;
@@ -598,8 +615,9 @@  discard block
 block discarded – undo
598 615
 	public function findAll($criteria = null, $parameters = [])
599 616
 	{
600 617
 		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
601
-		if($criteria !== null)
602
-			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
618
+		if($criteria !== null) {
619
+					$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
620
+		}
603 621
 		$result = $this->getRecordGateway()->findRecordsByCriteria($this, $criteria, true);
604 622
 		return $this->populateObjects($result);
605 623
 	}
@@ -618,10 +636,12 @@  discard block
 block discarded – undo
618 636
 	 */
619 637
 	public function findByPk($keys)
620 638
 	{
621
-		if($keys === null)
622
-			return null;
623
-		if(func_num_args() > 1)
624
-			$keys = func_get_args();
639
+		if($keys === null) {
640
+					return null;
641
+		}
642
+		if(func_num_args() > 1) {
643
+					$keys = func_get_args();
644
+		}
625 645
 		$data = $this->getRecordGateway()->findRecordByPK($this, $keys);
626 646
 		return $this->populateObject($data);
627 647
 	}
@@ -645,8 +665,9 @@  discard block
 block discarded – undo
645 665
 	 */
646 666
 	public function findAllByPks($keys)
647 667
 	{
648
-		if(func_num_args() > 1)
649
-			$keys = func_get_args();
668
+		if(func_num_args() > 1) {
669
+					$keys = func_get_args();
670
+		}
650 671
 		$result = $this->getRecordGateway()->findRecordsByPks($this, (array)$keys);
651 672
 		return $this->populateObjects($result);
652 673
 	}
@@ -711,8 +732,9 @@  discard block
 block discarded – undo
711 732
 	public function count($criteria = null, $parameters = [])
712 733
 	{
713 734
 		$args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null;
714
-		if($criteria !== null)
715
-			$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
735
+		if($criteria !== null) {
736
+					$criteria = $this->getRecordCriteria($criteria, $parameters, $args);
737
+		}
716 738
 		return $this->getRecordGateway()->countRecords($this, $criteria);
717 739
 	}
718 740
 
@@ -729,9 +751,9 @@  discard block
 block discarded – undo
729 751
 		{
730 752
 			$criteria = $this->getRecordCriteria(count($args) > 0 ? $args[0] : null, array_slice($args, 1));
731 753
 			return $context->getRelationHandler($criteria);
754
+		} else {
755
+					return null;
732 756
 		}
733
-		else
734
-			return null;
735 757
 	}
736 758
 
737 759
 	/**
@@ -749,9 +771,9 @@  discard block
 block discarded – undo
749 771
 		{
750 772
 			list($property, $relation) = $definition;
751 773
 			return new TActiveRecordRelationContext($this, $property, $relation);
774
+		} else {
775
+					return null;
752 776
 		}
753
-		else
754
-			return null;
755 777
 	}
756 778
 
757 779
 	/**
@@ -791,10 +813,11 @@  discard block
 block discarded – undo
791 813
 	 */
792 814
 	protected function fetchResultsFor($property)
793 815
 	{
794
-		if(($context = $this->createRelationContext($property)) !== null)
795
-			return $context->getRelationHandler()->fetchResultsInto($this);
796
-		else
797
-			return false;
816
+		if(($context = $this->createRelationContext($property)) !== null) {
817
+					return $context->getRelationHandler()->fetchResultsInto($this);
818
+		} else {
819
+					return false;
820
+		}
798 821
 	}
799 822
 
800 823
 	/**
@@ -833,28 +856,29 @@  discard block
 block discarded – undo
833 856
 		{
834 857
 			$property = $method[4] === '_' ? substr($method, 5) : substr($method, 4);
835 858
 			return $this->getRelationHandler($property, $args);
836
-		}
837
-		elseif($findOne = strncasecmp($method, 'findby', 6) === 0)
838
-			$condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6);
839
-		elseif(strncasecmp($method, 'findallby', 9) === 0)
840
-			$condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9);
841
-		elseif($delete = strncasecmp($method, 'deleteby', 8) === 0)
842
-			$condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8);
843
-		elseif($delete = strncasecmp($method, 'deleteallby', 11) === 0)
844
-			$condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11);
845
-		else
859
+		} elseif($findOne = strncasecmp($method, 'findby', 6) === 0) {
860
+					$condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6);
861
+		} elseif(strncasecmp($method, 'findallby', 9) === 0) {
862
+					$condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9);
863
+		} elseif($delete = strncasecmp($method, 'deleteby', 8) === 0) {
864
+					$condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8);
865
+		} elseif($delete = strncasecmp($method, 'deleteallby', 11) === 0) {
866
+					$condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11);
867
+		} else
846 868
 		{
847
-			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
848
-				throw new TActiveRecordException('ar_invalid_finder_method', $method);
849
-			else
850
-				return null;
869
+			if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception) {
870
+							throw new TActiveRecordException('ar_invalid_finder_method', $method);
871
+			} else {
872
+							return null;
873
+			}
851 874
 		}
852 875
 
853 876
 		$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
854
-		if($delete)
855
-			return $this->deleteAll($criteria);
856
-		else
857
-			return $findOne ? $this->find($criteria) : $this->findAll($criteria);
877
+		if($delete) {
878
+					return $this->deleteAll($criteria);
879
+		} else {
880
+					return $findOne ? $this->find($criteria) : $this->findAll($criteria);
881
+		}
858 882
 	}
859 883
 
860 884
 	/**
@@ -864,8 +888,9 @@  discard block
 block discarded – undo
864 888
 	 */
865 889
 	public function getInvalidFinderResult()
866 890
 	{
867
-		if($this->_invalidFinderResult !== null)
868
-			return $this->_invalidFinderResult;
891
+		if($this->_invalidFinderResult !== null) {
892
+					return $this->_invalidFinderResult;
893
+		}
869 894
 
870 895
 		return self::getRecordManager()->getInvalidFinderResult();
871 896
 	}
@@ -879,10 +904,11 @@  discard block
 block discarded – undo
879 904
 	 */
880 905
 	public function setInvalidFinderResult($value)
881 906
 	{
882
-		if($value === null)
883
-			$this->_invalidFinderResult = null;
884
-		else
885
-			$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'Prado\\Data\\ActiveRecord\\TActiveRecordInvalidFinderResult');
907
+		if($value === null) {
908
+					$this->_invalidFinderResult = null;
909
+		} else {
910
+					$this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'Prado\\Data\\ActiveRecord\\TActiveRecordInvalidFinderResult');
911
+		}
886 912
 	}
887 913
 
888 914
 	/**
@@ -900,11 +926,11 @@  discard block
 block discarded – undo
900 926
 		{
901 927
 			$useArgs = !is_array($parameters) && is_array($args);
902 928
 			return new TActiveRecordCriteria($criteria, $useArgs ? $args : $parameters);
929
+		} elseif($criteria instanceof TSqlCriteria) {
930
+					return $criteria;
931
+		} else {
932
+					return new TActiveRecordCriteria();
903 933
 		}
904
-		elseif($criteria instanceof TSqlCriteria)
905
-			return $criteria;
906
-		else
907
-			return new TActiveRecordCriteria();
908 934
 			//throw new TActiveRecordException('ar_invalid_criteria');
909 935
 	}
910 936
 
@@ -981,8 +1007,9 @@  discard block
 block discarded – undo
981 1007
 	public function getColumnValue($columnName)
982 1008
 	{
983 1009
 		$className = get_class($this);
984
-		if(isset(self::$_columnMapping[$className][$columnName]))
985
-			$columnName = self::$_columnMapping[$className][$columnName];
1010
+		if(isset(self::$_columnMapping[$className][$columnName])) {
1011
+					$columnName = self::$_columnMapping[$className][$columnName];
1012
+		}
986 1013
 		return $this->$columnName;
987 1014
 	}
988 1015
 
@@ -996,8 +1023,9 @@  discard block
 block discarded – undo
996 1023
 	public function setColumnValue($columnName, $value)
997 1024
 	{
998 1025
 		$className = get_class($this);
999
-		if(isset(self::$_columnMapping[$className][$columnName]))
1000
-			$columnName = self::$_columnMapping[$className][$columnName];
1026
+		if(isset(self::$_columnMapping[$className][$columnName])) {
1027
+					$columnName = self::$_columnMapping[$className][$columnName];
1028
+		}
1001 1029
 		$this->$columnName = $value;
1002 1030
 	}
1003 1031
 
Please login to merge, or discard this patch.
framework/Data/ActiveRecord/TActiveRecordGateway.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	protected function getRecordTableName(TActiveRecord $record)
73 73
 	{
74 74
 		$class = new ReflectionClass($record);
75
-		if($class->hasConstant(self::TABLE_CONST))
75
+		if ($class->hasConstant(self::TABLE_CONST))
76 76
 		{
77 77
 			$value = $class->getConstant(self::TABLE_CONST);
78
-			if(empty($value))
78
+			if (empty($value))
79 79
 				throw new TActiveRecordException('ar_invalid_tablename_property',
80 80
 					get_class($record), self::TABLE_CONST);
81 81
 			return $value;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		elseif ($class->hasMethod(self::TABLE_METHOD))
84 84
 		{
85 85
 			$value = $record->{self::TABLE_METHOD}();
86
-			if(empty($value))
86
+			if (empty($value))
87 87
 				throw new TActiveRecordException('ar_invalid_tablename_method',
88 88
 					get_class($record), self::TABLE_METHOD);
89 89
 			return $value;
@@ -112,23 +112,23 @@  discard block
 block discarded – undo
112 112
 	public function getTableInfo(TDbConnection $connection, $tableName)
113 113
 	{
114 114
 		$connStr = $connection->getConnectionString();
115
-		$key = $connStr . $tableName;
116
-		if(!isset($this->_tables[$key]))
115
+		$key = $connStr.$tableName;
116
+		if (!isset($this->_tables[$key]))
117 117
 		{
118 118
 			//call this first to ensure that unserializing the cache
119 119
 			//will find the correct driver dependent classes.
120
-			if(!isset($this->_meta[$connStr]))
120
+			if (!isset($this->_meta[$connStr]))
121 121
 			{
122 122
 				$this->_meta[$connStr] = TDbMetaData::getInstance($connection);
123 123
 			}
124 124
 
125 125
 			$tableInfo = null;
126
-			if(($cache = $this->getManager()->getCache()) !== null)
126
+			if (($cache = $this->getManager()->getCache()) !== null)
127 127
 				$tableInfo = $cache->get($key);
128
-			if(empty($tableInfo))
128
+			if (empty($tableInfo))
129 129
 			{
130 130
 				$tableInfo = $this->_meta[$connStr]->getTableInfo($tableName);
131
-				if($cache !== null)
131
+				if ($cache !== null)
132 132
 					$cache->set($key, $tableInfo);
133 133
 			}
134 134
 			$this->_tables[$key] = $tableInfo;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$conn = $record->getDbConnection();
146 146
 		$connStr = $conn->getConnectionString();
147 147
 		$tableInfo = $this->getRecordTableInfo($record);
148
-		if(!isset($this->_commandBuilders[$connStr]))
148
+		if (!isset($this->_commandBuilders[$connStr]))
149 149
 		{
150 150
 			$builder = $tableInfo->createCommandBuilder($record->getDbConnection());
151 151
 			$command = new TDataGatewayCommand($builder);
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	public function onCreateCommand($sender, $param)
173 173
 	{
174 174
 		$this->raiseEvent('OnCreateCommand', $this, $param);
175
-		if($this->_currentRecord !== null)
175
+		if ($this->_currentRecord !== null)
176 176
 			$this->_currentRecord->onCreateCommand($param);
177 177
 	}
178 178
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	public function onExecuteCommand($sender, $param)
191 191
 	{
192 192
 		$this->raiseEvent('OnExecuteCommand', $this, $param);
193
-		if($this->_currentRecord !== null)
193
+		if ($this->_currentRecord !== null)
194 194
 			$this->_currentRecord->onExecuteCommand($param);
195 195
 	}
196 196
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	{
281 281
 		//$this->updateAssociatedRecords($record,true);
282 282
 		$result = $this->getCommand($record)->insert($this->getInsertValues($record));
283
-		if($result)
283
+		if ($result)
284 284
 			$this->updatePostInsert($record);
285 285
 		//$this->updateAssociatedRecords($record);
286 286
 		return $result;
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	{
295 295
 		$command = $this->getCommand($record);
296 296
 		$tableInfo = $command->getTableInfo();
297
-		foreach($tableInfo->getColumns() as $name => $column)
297
+		foreach ($tableInfo->getColumns() as $name => $column)
298 298
 		{
299
-			if($column->hasSequence())
299
+			if ($column->hasSequence())
300 300
 				$record->setColumnValue($name, $command->getLastInsertID($column->getSequenceName()));
301 301
 		}
302 302
 	}
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
 	{
310 310
 		$values = [];
311 311
 		$tableInfo = $this->getCommand($record)->getTableInfo();
312
-		foreach($tableInfo->getColumns() as $name => $column)
312
+		foreach ($tableInfo->getColumns() as $name => $column)
313 313
 		{
314
-			if($column->getIsExcluded())
314
+			if ($column->getIsExcluded())
315 315
 				continue;
316 316
 			$value = $record->getColumnValue($name);
317
-			if(!$column->getAllowNull() && $value === null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
317
+			if (!$column->getAllowNull() && $value === null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
318 318
 			{
319 319
 				throw new TActiveRecordException(
320 320
 					'ar_value_must_not_be_null', get_class($record),
321 321
 					$tableInfo->getTableFullName(), $name);
322 322
 			}
323
-			if($value !== null)
323
+			if ($value !== null)
324 324
 				$values[$name] = $value;
325 325
 		}
326 326
 		return $values;
@@ -345,23 +345,23 @@  discard block
 block discarded – undo
345 345
 		$values = [];
346 346
 		$tableInfo = $this->getCommand($record)->getTableInfo();
347 347
 		$primary = [];
348
-		foreach($tableInfo->getColumns() as $name => $column)
348
+		foreach ($tableInfo->getColumns() as $name => $column)
349 349
 		{
350
-			if($column->getIsExcluded())
350
+			if ($column->getIsExcluded())
351 351
 				continue;
352 352
 			$value = $record->getColumnValue($name);
353
-			if(!$column->getAllowNull() && $value === null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
353
+			if (!$column->getAllowNull() && $value === null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
354 354
 			{
355 355
 				throw new TActiveRecordException(
356 356
 					'ar_value_must_not_be_null', get_class($record),
357 357
 					$tableInfo->getTableFullName(), $name);
358 358
 			}
359
-			if($column->getIsPrimaryKey())
359
+			if ($column->getIsPrimaryKey())
360 360
 				$primary[$name] = $value;
361 361
 			else
362 362
 				$values[$name] = $value;
363 363
 		}
364
-		return [$values,$primary];
364
+		return [$values, $primary];
365 365
 	}
366 366
 
367 367
 	protected function updateAssociatedRecords(TActiveRecord $record, $updateBelongsTo = false)
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 	{
385 385
 		$tableInfo = $this->getCommand($record)->getTableInfo();
386 386
 		$primary = [];
387
-		foreach($tableInfo->getColumns() as $name => $column)
387
+		foreach ($tableInfo->getColumns() as $name => $column)
388 388
 		{
389
-			if($column->getIsPrimaryKey())
389
+			if ($column->getIsPrimaryKey())
390 390
 				$primary[$name] = $record->getColumnValue($name);
391 391
 		}
392 392
 		return $primary;
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	 */
423 423
 	protected function raiseCommandEvent($event, $command, $record, $criteria)
424 424
 	{
425
-		if(!($criteria instanceof TSqlCriteria))
425
+		if (!($criteria instanceof TSqlCriteria))
426 426
 			$criteria = new TActiveRecordCriteria(null, $criteria);
427 427
 		$param = new TActiveRecordEventParameter($command, $record, $criteria);
428 428
 		$manager = $record->getRecordManager();
Please login to merge, or discard this patch.
Braces   +47 added lines, -34 removed lines patch added patch discarded remove patch
@@ -75,21 +75,22 @@  discard block
 block discarded – undo
75 75
 		if($class->hasConstant(self::TABLE_CONST))
76 76
 		{
77 77
 			$value = $class->getConstant(self::TABLE_CONST);
78
-			if(empty($value))
79
-				throw new TActiveRecordException('ar_invalid_tablename_property',
78
+			if(empty($value)) {
79
+							throw new TActiveRecordException('ar_invalid_tablename_property',
80 80
 					get_class($record), self::TABLE_CONST);
81
+			}
81 82
 			return $value;
82
-		}
83
-		elseif ($class->hasMethod(self::TABLE_METHOD))
83
+		} elseif ($class->hasMethod(self::TABLE_METHOD))
84 84
 		{
85 85
 			$value = $record->{self::TABLE_METHOD}();
86
-			if(empty($value))
87
-				throw new TActiveRecordException('ar_invalid_tablename_method',
86
+			if(empty($value)) {
87
+							throw new TActiveRecordException('ar_invalid_tablename_method',
88 88
 					get_class($record), self::TABLE_METHOD);
89
+			}
89 90
 			return $value;
91
+		} else {
92
+					return strtolower(get_class($record));
90 93
 		}
91
-		else
92
-			return strtolower(get_class($record));
93 94
 	}
94 95
 
95 96
 	/**
@@ -123,13 +124,15 @@  discard block
 block discarded – undo
123 124
 			}
124 125
 
125 126
 			$tableInfo = null;
126
-			if(($cache = $this->getManager()->getCache()) !== null)
127
-				$tableInfo = $cache->get($key);
127
+			if(($cache = $this->getManager()->getCache()) !== null) {
128
+							$tableInfo = $cache->get($key);
129
+			}
128 130
 			if(empty($tableInfo))
129 131
 			{
130 132
 				$tableInfo = $this->_meta[$connStr]->getTableInfo($tableName);
131
-				if($cache !== null)
132
-					$cache->set($key, $tableInfo);
133
+				if($cache !== null) {
134
+									$cache->set($key, $tableInfo);
135
+				}
133 136
 			}
134 137
 			$this->_tables[$key] = $tableInfo;
135 138
 		}
@@ -172,8 +175,9 @@  discard block
 block discarded – undo
172 175
 	public function onCreateCommand($sender, $param)
173 176
 	{
174 177
 		$this->raiseEvent('OnCreateCommand', $this, $param);
175
-		if($this->_currentRecord !== null)
176
-			$this->_currentRecord->onCreateCommand($param);
178
+		if($this->_currentRecord !== null) {
179
+					$this->_currentRecord->onCreateCommand($param);
180
+		}
177 181
 	}
178 182
 
179 183
 	/**
@@ -190,8 +194,9 @@  discard block
 block discarded – undo
190 194
 	public function onExecuteCommand($sender, $param)
191 195
 	{
192 196
 		$this->raiseEvent('OnExecuteCommand', $this, $param);
193
-		if($this->_currentRecord !== null)
194
-			$this->_currentRecord->onExecuteCommand($param);
197
+		if($this->_currentRecord !== null) {
198
+					$this->_currentRecord->onExecuteCommand($param);
199
+		}
195 200
 	}
196 201
 
197 202
 	/**
@@ -280,8 +285,9 @@  discard block
 block discarded – undo
280 285
 	{
281 286
 		//$this->updateAssociatedRecords($record,true);
282 287
 		$result = $this->getCommand($record)->insert($this->getInsertValues($record));
283
-		if($result)
284
-			$this->updatePostInsert($record);
288
+		if($result) {
289
+					$this->updatePostInsert($record);
290
+		}
285 291
 		//$this->updateAssociatedRecords($record);
286 292
 		return $result;
287 293
 	}
@@ -296,8 +302,9 @@  discard block
 block discarded – undo
296 302
 		$tableInfo = $command->getTableInfo();
297 303
 		foreach($tableInfo->getColumns() as $name => $column)
298 304
 		{
299
-			if($column->hasSequence())
300
-				$record->setColumnValue($name, $command->getLastInsertID($column->getSequenceName()));
305
+			if($column->hasSequence()) {
306
+							$record->setColumnValue($name, $command->getLastInsertID($column->getSequenceName()));
307
+			}
301 308
 		}
302 309
 	}
303 310
 
@@ -311,8 +318,9 @@  discard block
 block discarded – undo
311 318
 		$tableInfo = $this->getCommand($record)->getTableInfo();
312 319
 		foreach($tableInfo->getColumns() as $name => $column)
313 320
 		{
314
-			if($column->getIsExcluded())
315
-				continue;
321
+			if($column->getIsExcluded()) {
322
+							continue;
323
+			}
316 324
 			$value = $record->getColumnValue($name);
317 325
 			if(!$column->getAllowNull() && $value === null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
318 326
 			{
@@ -320,8 +328,9 @@  discard block
 block discarded – undo
320 328
 					'ar_value_must_not_be_null', get_class($record),
321 329
 					$tableInfo->getTableFullName(), $name);
322 330
 			}
323
-			if($value !== null)
324
-				$values[$name] = $value;
331
+			if($value !== null) {
332
+							$values[$name] = $value;
333
+			}
325 334
 		}
326 335
 		return $values;
327 336
 	}
@@ -347,8 +356,9 @@  discard block
 block discarded – undo
347 356
 		$primary = [];
348 357
 		foreach($tableInfo->getColumns() as $name => $column)
349 358
 		{
350
-			if($column->getIsExcluded())
351
-				continue;
359
+			if($column->getIsExcluded()) {
360
+							continue;
361
+			}
352 362
 			$value = $record->getColumnValue($name);
353 363
 			if(!$column->getAllowNull() && $value === null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE))
354 364
 			{
@@ -356,10 +366,11 @@  discard block
 block discarded – undo
356 366
 					'ar_value_must_not_be_null', get_class($record),
357 367
 					$tableInfo->getTableFullName(), $name);
358 368
 			}
359
-			if($column->getIsPrimaryKey())
360
-				$primary[$name] = $value;
361
-			else
362
-				$values[$name] = $value;
369
+			if($column->getIsPrimaryKey()) {
370
+							$primary[$name] = $value;
371
+			} else {
372
+							$values[$name] = $value;
373
+			}
363 374
 		}
364 375
 		return [$values,$primary];
365 376
 	}
@@ -386,8 +397,9 @@  discard block
 block discarded – undo
386 397
 		$primary = [];
387 398
 		foreach($tableInfo->getColumns() as $name => $column)
388 399
 		{
389
-			if($column->getIsPrimaryKey())
390
-				$primary[$name] = $record->getColumnValue($name);
400
+			if($column->getIsPrimaryKey()) {
401
+							$primary[$name] = $record->getColumnValue($name);
402
+			}
391 403
 		}
392 404
 		return $primary;
393 405
 	}
@@ -422,8 +434,9 @@  discard block
 block discarded – undo
422 434
 	 */
423 435
 	protected function raiseCommandEvent($event, $command, $record, $criteria)
424 436
 	{
425
-		if(!($criteria instanceof TSqlCriteria))
426
-			$criteria = new TActiveRecordCriteria(null, $criteria);
437
+		if(!($criteria instanceof TSqlCriteria)) {
438
+					$criteria = new TActiveRecordCriteria(null, $criteria);
439
+		}
427 440
 		$param = new TActiveRecordEventParameter($command, $record, $criteria);
428 441
 		$manager = $record->getRecordManager();
429 442
 		$manager->{$event}($param);
Please login to merge, or discard this patch.
framework/Data/Common/TDbCommandBuilder.php 2 patches
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function getLastInsertID()
78 78
 	{
79
-		foreach($this->getTableInfo()->getColumns() as $column)
79
+		foreach ($this->getTableInfo()->getColumns() as $column)
80 80
 		{
81
-			if($column->hasSequence())
81
+			if ($column->hasSequence())
82 82
 				return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
83 83
 		}
84 84
 	}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	 */
94 94
 	public function applyLimitOffset($sql, $limit = -1, $offset = -1)
95 95
 	{
96
-		$limit = $limit !== null ? (int)$limit : -1;
97
-		$offset = $offset !== null ? (int)$offset : -1;
98
-		$limitStr = $limit >= 0 ? ' LIMIT ' . $limit : '';
99
-		$offsetStr = $offset >= 0 ? ' OFFSET ' . $offset : '';
100
-		return $sql . $limitStr . $offsetStr;
96
+		$limit = $limit !== null ? (int) $limit : -1;
97
+		$offset = $offset !== null ? (int) $offset : -1;
98
+		$limitStr = $limit >= 0 ? ' LIMIT '.$limit : '';
99
+		$offsetStr = $offset >= 0 ? ' OFFSET '.$offset : '';
100
+		return $sql.$limitStr.$offsetStr;
101 101
 	}
102 102
 
103 103
 	/**
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 	public function applyOrdering($sql, $ordering)
109 109
 	{
110 110
 		$orders = [];
111
-		foreach($ordering as $name => $direction)
111
+		foreach ($ordering as $name => $direction)
112 112
 		{
113 113
 			$direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC';
114
-			if(false !== strpos($name, '(') && false !== strpos($name, ')')) {
114
+			if (false !== strpos($name, '(') && false !== strpos($name, ')')) {
115 115
 				// key is a function (bad practice, but we need to handle it)
116 116
 				$key = $name;
117 117
 			} else {
118 118
 				// key is a column
119 119
 				$key = $this->getTableInfo()->getColumn($name)->getColumnName();
120 120
 			}
121
-			$orders[] = $key . ' ' . $direction;
121
+			$orders[] = $key.' '.$direction;
122 122
 		}
123
-		if(count($orders) > 0)
124
-			$sql .= ' ORDER BY ' . implode(', ', $orders);
123
+		if (count($orders) > 0)
124
+			$sql .= ' ORDER BY '.implode(', ', $orders);
125 125
 		return $sql;
126 126
 	}
127 127
 
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public function getSearchExpression($fields, $keywords)
137 137
 	{
138
-		if(strlen(trim($keywords)) == 0) return '';
138
+		if (strlen(trim($keywords)) == 0) return '';
139 139
 		$words = preg_split('/\s/u', $keywords);
140 140
 		$conditions = [];
141
-		foreach($fields as $field)
141
+		foreach ($fields as $field)
142 142
 		{
143 143
 			$column = $this->getTableInfo()->getColumn($field)->getColumnName();
144 144
 			$conditions[] = $this->getSearchCondition($column, $words);
145 145
 		}
146
-		return '(' . implode(' OR ', $conditions) . ')';
146
+		return '('.implode(' OR ', $conditions).')';
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	protected function getSearchCondition($column, $words)
155 155
 	{
156 156
 		$conditions = [];
157
-		foreach($words as $word)
158
-			$conditions[] = $column . ' LIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%');
159
-		return '(' . implode(' AND ', $conditions) . ')';
157
+		foreach ($words as $word)
158
+			$conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%');
159
+		return '('.implode(' AND ', $conditions).')';
160 160
 	}
161 161
 
162 162
 	/**
@@ -199,102 +199,102 @@  discard block
 block discarded – undo
199 199
 	 * @todo add support for quoting of column aliasing
200 200
 	 */
201 201
 	public function getSelectFieldList($data = '*') {
202
-		if(is_scalar($data)) {
202
+		if (is_scalar($data)) {
203 203
 			$tmp = explode(',', $data);
204 204
 			$result = [];
205
-			foreach($tmp as $v)
205
+			foreach ($tmp as $v)
206 206
 				$result[] = trim($v);
207 207
 			return $result;
208 208
 		}
209 209
 
210 210
 		$bHasWildcard = false;
211 211
 		$result = [];
212
-		if(is_array($data) || $data instanceof Traversable) {
212
+		if (is_array($data) || $data instanceof Traversable) {
213 213
 			$columns = $this->getTableInfo()->getColumns();
214
-			foreach($data as $key => $value) {
215
-				if($key === '*' || $value === '*') {
214
+			foreach ($data as $key => $value) {
215
+				if ($key === '*' || $value === '*') {
216 216
 					$bHasWildcard = true;
217 217
 					continue;
218 218
 				}
219 219
 
220
-				if(strToUpper($key) === 'NULL') {
220
+				if (strToUpper($key) === 'NULL') {
221 221
 					$result[] = 'NULL';
222 222
 					continue;
223 223
 				}
224 224
 
225
-				if(strpos($key, '(') !== false && strpos($key, ')') !== false) {
225
+				if (strpos($key, '(') !== false && strpos($key, ')') !== false) {
226 226
 					$result[] = $key;
227 227
 					continue;
228 228
 				}
229 229
 
230
-				if(stripos($key, 'AS') !== false) {
230
+				if (stripos($key, 'AS') !== false) {
231 231
 					$result[] = $key;
232 232
 					continue;
233 233
 				}
234 234
 
235
-				if(stripos($value, 'AS') !== false) {
235
+				if (stripos($value, 'AS') !== false) {
236 236
 					$result[] = $value;
237 237
 					continue;
238 238
 				}
239 239
 
240 240
 				$v = isset($columns[$value]);
241 241
 				$k = isset($columns[$key]);
242
-				if(is_int($key) && $v) {
242
+				if (is_int($key) && $v) {
243 243
 					$key = $value;
244 244
 					$k = $v;
245 245
 				}
246 246
 
247
-				if(strToUpper($value) === 'NULL') {
248
-					if($k)
249
-						$result[] = 'NULL AS ' . $columns[$key]->getColumnName();
247
+				if (strToUpper($value) === 'NULL') {
248
+					if ($k)
249
+						$result[] = 'NULL AS '.$columns[$key]->getColumnName();
250 250
 					else
251
-						$result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : '');
251
+						$result[] = 'NULL'.(is_string($key) ? (' AS '.(string) $key) : '');
252 252
 					continue;
253 253
 				}
254 254
 
255
-				if(strpos($value, '(') !== false && strpos($value, ')') !== false) {
256
-					if($k)
257
-						$result[] = $value . ' AS ' . $columns[$key]->getColumnName();
255
+				if (strpos($value, '(') !== false && strpos($value, ')') !== false) {
256
+					if ($k)
257
+						$result[] = $value.' AS '.$columns[$key]->getColumnName();
258 258
 					else
259
-						$result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : '');
259
+						$result[] = $value.(is_string($key) ? (' AS '.(string) $key) : '');
260 260
 					continue;
261 261
 				}
262 262
 
263
-				if($v && $key == $value) {
263
+				if ($v && $key == $value) {
264 264
 					$result[] = $columns[$value]->getColumnName();
265 265
 					continue;
266 266
 				}
267 267
 
268
-				if($k && $value == null) {
268
+				if ($k && $value == null) {
269 269
 					$result[] = $columns[$key]->getColumnName();
270 270
 					continue;
271 271
 				}
272 272
 
273
-				if(is_string($key) && $v) {
274
-					$result[] = $columns[$value]->getColumnName() . ' AS ' . $key;
273
+				if (is_string($key) && $v) {
274
+					$result[] = $columns[$value]->getColumnName().' AS '.$key;
275 275
 					continue;
276 276
 				}
277 277
 
278
-				if(is_numeric($value) && $k) {
279
-					$result[] = $value . ' AS ' . $columns[$key]->getColumnName();
278
+				if (is_numeric($value) && $k) {
279
+					$result[] = $value.' AS '.$columns[$key]->getColumnName();
280 280
 					continue;
281 281
 				}
282 282
 
283
-				if(is_string($value) && $k) {
284
-					$result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName();
283
+				if (is_string($value) && $k) {
284
+					$result[] = $this->getDbConnection()->quoteString($value).' AS '.$columns[$key]->getColumnName();
285 285
 					continue;
286 286
 				}
287 287
 
288
-				if(!$v && !$k && is_int($key)) {
289
-					$result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value);
288
+				if (!$v && !$k && is_int($key)) {
289
+					$result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value);
290 290
 					continue;
291 291
 				}
292 292
 
293
-				$result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key;
293
+				$result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value)).' AS '.$key;
294 294
 			}
295 295
 		}
296 296
 
297
-		if($data === null || count($result) == 0 || $bHasWildcard)
297
+		if ($data === null || count($result) == 0 || $bHasWildcard)
298 298
 			$result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result);
299 299
 
300 300
 		return $result;
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
 		$table = $this->getTableInfo()->getTableFullName();
313 313
 		$fields = implode(', ', $this -> getSelectFieldList($select));
314 314
 		$sql = "SELECT {$fields} FROM {$table}";
315
-		if(!empty($where))
315
+		if (!empty($where))
316 316
 			$sql .= " WHERE {$where}";
317 317
 		return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset);
318 318
 	}
319 319
 
320 320
 	public function applyCriterias($sql, $parameters = [], $ordering = [], $limit = -1, $offset = -1)
321 321
 	{
322
-		if(count($ordering) > 0)
322
+		if (count($ordering) > 0)
323 323
 			$sql = $this->applyOrdering($sql, $ordering);
324
-		if($limit >= 0 || $offset >= 0)
324
+		if ($limit >= 0 || $offset >= 0)
325 325
 			$sql = $this->applyLimitOffset($sql, $limit, $offset);
326 326
 		$command = $this->createCommand($sql);
327 327
 		$this->bindArrayValues($command, $parameters);
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 	{
352 352
 		$table = $this->getTableInfo()->getTableFullName();
353 353
 		if (!empty($where))
354
-			$where = ' WHERE ' . $where;
355
-		$command = $this->createCommand("DELETE FROM {$table}" . $where);
354
+			$where = ' WHERE '.$where;
355
+		$command = $this->createCommand("DELETE FROM {$table}".$where);
356 356
 		$this->bindArrayValues($command, $parameters);
357 357
 		return $command;
358 358
 	}
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
 	public function createUpdateCommand($data, $where, $parameters = [])
386 386
 	{
387 387
 		$table = $this->getTableInfo()->getTableFullName();
388
-		if($this->hasIntegerKey($parameters))
388
+		if ($this->hasIntegerKey($parameters))
389 389
 			$fields = implode(', ', $this->getColumnBindings($data, true));
390 390
 		else
391 391
 			$fields = implode(', ', $this->getColumnBindings($data));
392 392
 
393 393
 		if (!empty($where))
394
-			$where = ' WHERE ' . $where;
395
-		$command = $this->createCommand("UPDATE {$table} SET {$fields}" . $where);
394
+			$where = ' WHERE '.$where;
395
+		$command = $this->createCommand("UPDATE {$table} SET {$fields}".$where);
396 396
 		$this->bindArrayValues($command, array_merge($data, $parameters));
397 397
 		return $command;
398 398
 	}
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
 	protected function getInsertFieldBindings($values)
406 406
 	{
407 407
 		$fields = []; $bindings = [];
408
-		foreach(array_keys($values) as $name)
408
+		foreach (array_keys($values) as $name)
409 409
 		{
410 410
 			$fields[] = $this->getTableInfo()->getColumn($name)->getColumnName();
411
-			$bindings[] = ':' . $name;
411
+			$bindings[] = ':'.$name;
412 412
 		}
413 413
 		return [implode(', ', $fields), implode(', ', $bindings)];
414 414
 	}
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
 	protected function getColumnBindings($values, $position = false)
423 423
 	{
424 424
 		$bindings = [];
425
-		foreach(array_keys($values) as $name)
425
+		foreach (array_keys($values) as $name)
426 426
 		{
427 427
 			$column = $this->getTableInfo()->getColumn($name)->getColumnName();
428
-			$bindings[] = $position ? $column . ' = ?' : $column . ' = :' . $name;
428
+			$bindings[] = $position ? $column.' = ?' : $column.' = :'.$name;
429 429
 		}
430 430
 		return $bindings;
431 431
 	}
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
 	 */
448 448
 	public function bindColumnValues($command, $values)
449 449
 	{
450
-		foreach($values as $name => $value)
450
+		foreach ($values as $name => $value)
451 451
 		{
452 452
 			$column = $this->getTableInfo()->getColumn($name);
453
-			if($value === null && $column->getAllowNull())
454
-				$command->bindValue(':' . $name, null, PDO::PARAM_NULL);
453
+			if ($value === null && $column->getAllowNull())
454
+				$command->bindValue(':'.$name, null, PDO::PARAM_NULL);
455 455
 			else
456
-				$command->bindValue(':' . $name, $value, $column->getPdoType());
456
+				$command->bindValue(':'.$name, $value, $column->getPdoType());
457 457
 		}
458 458
 	}
459 459
 
@@ -463,17 +463,17 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	public function bindArrayValues($command, $values)
465 465
 	{
466
-		if($this->hasIntegerKey($values))
466
+		if ($this->hasIntegerKey($values))
467 467
 		{
468 468
 			$values = array_values($values);
469
-			for($i = 0, $max = count($values); $i < $max; $i++)
469
+			for ($i = 0, $max = count($values); $i < $max; $i++)
470 470
 				$command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i]));
471 471
 		}
472 472
 		else
473 473
 		{
474
-			foreach($values as $name => $value)
474
+			foreach ($values as $name => $value)
475 475
 			{
476
-				$prop = $name[0] === ':' ? $name : ':' . $name;
476
+				$prop = $name[0] === ':' ? $name : ':'.$name;
477 477
 				$command->bindValue($prop, $value, $this->getPdoType($value));
478 478
 			}
479 479
 		}
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	 */
486 486
 	public static function getPdoType($value)
487 487
 	{
488
-		switch(gettype($value))
488
+		switch (gettype($value))
489 489
 		{
490 490
 			case 'boolean': return PDO::PARAM_BOOL;
491 491
 			case 'integer': return PDO::PARAM_INT;
@@ -500,9 +500,9 @@  discard block
 block discarded – undo
500 500
 	 */
501 501
 	protected function hasIntegerKey($array)
502 502
 	{
503
-		foreach($array as $k => $v)
503
+		foreach ($array as $k => $v)
504 504
 		{
505
-			if(gettype($k) === 'integer')
505
+			if (gettype($k) === 'integer')
506 506
 				return true;
507 507
 		}
508 508
 		return false;
Please login to merge, or discard this patch.
Braces   +60 added lines, -43 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@  discard block
 block discarded – undo
78 78
 	{
79 79
 		foreach($this->getTableInfo()->getColumns() as $column)
80 80
 		{
81
-			if($column->hasSequence())
82
-				return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
81
+			if($column->hasSequence()) {
82
+							return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
83
+			}
83 84
 		}
84 85
 	}
85 86
 
@@ -120,8 +121,9 @@  discard block
 block discarded – undo
120 121
 			}
121 122
 			$orders[] = $key . ' ' . $direction;
122 123
 		}
123
-		if(count($orders) > 0)
124
-			$sql .= ' ORDER BY ' . implode(', ', $orders);
124
+		if(count($orders) > 0) {
125
+					$sql .= ' ORDER BY ' . implode(', ', $orders);
126
+		}
125 127
 		return $sql;
126 128
 	}
127 129
 
@@ -135,7 +137,9 @@  discard block
 block discarded – undo
135 137
 	 */
136 138
 	public function getSearchExpression($fields, $keywords)
137 139
 	{
138
-		if(strlen(trim($keywords)) == 0) return '';
140
+		if(strlen(trim($keywords)) == 0) {
141
+			return '';
142
+		}
139 143
 		$words = preg_split('/\s/u', $keywords);
140 144
 		$conditions = [];
141 145
 		foreach($fields as $field)
@@ -154,8 +158,9 @@  discard block
 block discarded – undo
154 158
 	protected function getSearchCondition($column, $words)
155 159
 	{
156 160
 		$conditions = [];
157
-		foreach($words as $word)
158
-			$conditions[] = $column . ' LIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%');
161
+		foreach($words as $word) {
162
+					$conditions[] = $column . ' LIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%');
163
+		}
159 164
 		return '(' . implode(' AND ', $conditions) . ')';
160 165
 	}
161 166
 
@@ -202,8 +207,9 @@  discard block
 block discarded – undo
202 207
 		if(is_scalar($data)) {
203 208
 			$tmp = explode(',', $data);
204 209
 			$result = [];
205
-			foreach($tmp as $v)
206
-				$result[] = trim($v);
210
+			foreach($tmp as $v) {
211
+							$result[] = trim($v);
212
+			}
207 213
 			return $result;
208 214
 		}
209 215
 
@@ -245,18 +251,20 @@  discard block
 block discarded – undo
245 251
 				}
246 252
 
247 253
 				if(strToUpper($value) === 'NULL') {
248
-					if($k)
249
-						$result[] = 'NULL AS ' . $columns[$key]->getColumnName();
250
-					else
251
-						$result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : '');
254
+					if($k) {
255
+											$result[] = 'NULL AS ' . $columns[$key]->getColumnName();
256
+					} else {
257
+											$result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : '');
258
+					}
252 259
 					continue;
253 260
 				}
254 261
 
255 262
 				if(strpos($value, '(') !== false && strpos($value, ')') !== false) {
256
-					if($k)
257
-						$result[] = $value . ' AS ' . $columns[$key]->getColumnName();
258
-					else
259
-						$result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : '');
263
+					if($k) {
264
+											$result[] = $value . ' AS ' . $columns[$key]->getColumnName();
265
+					} else {
266
+											$result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : '');
267
+					}
260 268
 					continue;
261 269
 				}
262 270
 
@@ -294,8 +302,9 @@  discard block
 block discarded – undo
294 302
 			}
295 303
 		}
296 304
 
297
-		if($data === null || count($result) == 0 || $bHasWildcard)
298
-			$result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result);
305
+		if($data === null || count($result) == 0 || $bHasWildcard) {
306
+					$result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result);
307
+		}
299 308
 
300 309
 		return $result;
301 310
 	}
@@ -312,17 +321,20 @@  discard block
 block discarded – undo
312 321
 		$table = $this->getTableInfo()->getTableFullName();
313 322
 		$fields = implode(', ', $this -> getSelectFieldList($select));
314 323
 		$sql = "SELECT {$fields} FROM {$table}";
315
-		if(!empty($where))
316
-			$sql .= " WHERE {$where}";
324
+		if(!empty($where)) {
325
+					$sql .= " WHERE {$where}";
326
+		}
317 327
 		return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset);
318 328
 	}
319 329
 
320 330
 	public function applyCriterias($sql, $parameters = [], $ordering = [], $limit = -1, $offset = -1)
321 331
 	{
322
-		if(count($ordering) > 0)
323
-			$sql = $this->applyOrdering($sql, $ordering);
324
-		if($limit >= 0 || $offset >= 0)
325
-			$sql = $this->applyLimitOffset($sql, $limit, $offset);
332
+		if(count($ordering) > 0) {
333
+					$sql = $this->applyOrdering($sql, $ordering);
334
+		}
335
+		if($limit >= 0 || $offset >= 0) {
336
+					$sql = $this->applyLimitOffset($sql, $limit, $offset);
337
+		}
326 338
 		$command = $this->createCommand($sql);
327 339
 		$this->bindArrayValues($command, $parameters);
328 340
 		return $command;
@@ -350,8 +362,9 @@  discard block
 block discarded – undo
350 362
 	public function createDeleteCommand($where, $parameters = [])
351 363
 	{
352 364
 		$table = $this->getTableInfo()->getTableFullName();
353
-		if (!empty($where))
354
-			$where = ' WHERE ' . $where;
365
+		if (!empty($where)) {
366
+					$where = ' WHERE ' . $where;
367
+		}
355 368
 		$command = $this->createCommand("DELETE FROM {$table}" . $where);
356 369
 		$this->bindArrayValues($command, $parameters);
357 370
 		return $command;
@@ -385,13 +398,15 @@  discard block
 block discarded – undo
385 398
 	public function createUpdateCommand($data, $where, $parameters = [])
386 399
 	{
387 400
 		$table = $this->getTableInfo()->getTableFullName();
388
-		if($this->hasIntegerKey($parameters))
389
-			$fields = implode(', ', $this->getColumnBindings($data, true));
390
-		else
391
-			$fields = implode(', ', $this->getColumnBindings($data));
401
+		if($this->hasIntegerKey($parameters)) {
402
+					$fields = implode(', ', $this->getColumnBindings($data, true));
403
+		} else {
404
+					$fields = implode(', ', $this->getColumnBindings($data));
405
+		}
392 406
 
393
-		if (!empty($where))
394
-			$where = ' WHERE ' . $where;
407
+		if (!empty($where)) {
408
+					$where = ' WHERE ' . $where;
409
+		}
395 410
 		$command = $this->createCommand("UPDATE {$table} SET {$fields}" . $where);
396 411
 		$this->bindArrayValues($command, array_merge($data, $parameters));
397 412
 		return $command;
@@ -450,10 +465,11 @@  discard block
 block discarded – undo
450 465
 		foreach($values as $name => $value)
451 466
 		{
452 467
 			$column = $this->getTableInfo()->getColumn($name);
453
-			if($value === null && $column->getAllowNull())
454
-				$command->bindValue(':' . $name, null, PDO::PARAM_NULL);
455
-			else
456
-				$command->bindValue(':' . $name, $value, $column->getPdoType());
468
+			if($value === null && $column->getAllowNull()) {
469
+							$command->bindValue(':' . $name, null, PDO::PARAM_NULL);
470
+			} else {
471
+							$command->bindValue(':' . $name, $value, $column->getPdoType());
472
+			}
457 473
 		}
458 474
 	}
459 475
 
@@ -466,10 +482,10 @@  discard block
 block discarded – undo
466 482
 		if($this->hasIntegerKey($values))
467 483
 		{
468 484
 			$values = array_values($values);
469
-			for($i = 0, $max = count($values); $i < $max; $i++)
470
-				$command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i]));
471
-		}
472
-		else
485
+			for($i = 0, $max = count($values); $i < $max; $i++) {
486
+							$command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i]));
487
+			}
488
+		} else
473 489
 		{
474 490
 			foreach($values as $name => $value)
475 491
 			{
@@ -502,8 +518,9 @@  discard block
 block discarded – undo
502 518
 	{
503 519
 		foreach($array as $k => $v)
504 520
 		{
505
-			if(gettype($k) === 'integer')
506
-				return true;
521
+			if(gettype($k) === 'integer') {
522
+							return true;
523
+			}
507 524
 		}
508 525
 		return false;
509 526
 	}
Please login to merge, or discard this patch.
framework/Data/Common/Mysql/TMysqlMetaData.php 2 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -83,21 +83,21 @@  discard block
 block discarded – undo
83 83
 		list($schemaName, $tableName) = $this->getSchemaTableName($table);
84 84
 		$find = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
85 85
 		$colCase = $this->getDbConnection()->getColumnCase();
86
-		if($colCase != TDbColumnCaseMode::Preserved)
86
+		if ($colCase != TDbColumnCaseMode::Preserved)
87 87
 			$this->getDbConnection()->setColumnCase('Preserved');
88 88
 		$this->getDbConnection()->setActive(true);
89 89
 		$sql = "SHOW FULL FIELDS FROM {$find}";
90 90
 		$command = $this->getDbConnection()->createCommand($sql);
91 91
 		$tableInfo = $this->createNewTableInfo($table);
92 92
 		$index = 0;
93
-		foreach($command->query() as $col)
93
+		foreach ($command->query() as $col)
94 94
 		{
95 95
 			$col['index'] = $index++;
96 96
 			$this->processColumn($tableInfo, $col);
97 97
 		}
98
-		if($index === 0)
98
+		if ($index === 0)
99 99
 			throw new TDbException('dbmetadata_invalid_table_view', $table);
100
-		if($colCase != TDbColumnCaseMode::Preserved)
100
+		if ($colCase != TDbColumnCaseMode::Preserved)
101 101
 			$this->getDbConnection()->setColumnCase($colCase);
102 102
 		return $tableInfo;
103 103
 	}
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	protected function getServerVersion()
109 109
 	{
110
-		if(!$this->_serverVersion)
110
+		if (!$this->_serverVersion)
111 111
 		{
112 112
 			$version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION);
113 113
 			$digits = [];
114 114
 			preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits);
115
-			$this->_serverVersion = floatval($digits[1] . '.' . $digits[2] . $digits[3]);
115
+			$this->_serverVersion = floatval($digits[1].'.'.$digits[2].$digits[3]);
116 116
 		}
117 117
 		return $this->_serverVersion;
118 118
 	}
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 		$info['ColumnName'] = "`$columnId`"; //quote the column names!
129 129
 		$info['ColumnId'] = $columnId;
130 130
 		$info['ColumnIndex'] = $col['index'];
131
-		if($col['Null'] === 'YES')
131
+		if ($col['Null'] === 'YES')
132 132
 			$info['AllowNull'] = true;
133
-		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
133
+		if (is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
134 134
 			$info['AutoIncrement'] = true;
135
-		if($col['Default'] !== "")
135
+		if ($col['Default'] !== "")
136 136
 			$info['DefaultValue'] = $col['Default'];
137 137
 
138
-		if($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
138
+		if ($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
139 139
 			$info['IsPrimaryKey'] = true;
140
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
140
+		if ($this->isForeignKeyColumn($columnId, $tableInfo))
141 141
 			$info['IsForeignKey'] = true;
142 142
 
143 143
 		$info['DbType'] = $col['Type'];
144 144
 		$match = [];
145 145
 		//find SET/ENUM values, column size, precision, and scale
146
-		if(preg_match('/\((.*)\)/', $col['Type'], $match))
146
+		if (preg_match('/\((.*)\)/', $col['Type'], $match))
147 147
 		{
148 148
 			$info['DbType'] = preg_replace('/\(.*\)/', '', $col['Type']);
149 149
 
150 150
 			//find SET/ENUM values
151
-			if($this->isEnumSetType($info['DbType']))
151
+			if ($this->isEnumSetType($info['DbType']))
152 152
 				$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
153 153
 
154 154
 			//find column size, precision and scale
155 155
 			$pscale = [];
156
-			if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
156
+			if (preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale))
157 157
 			{
158
-				if($this->isPrecisionType($info['DbType']))
158
+				if ($this->isPrecisionType($info['DbType']))
159 159
 				{
160 160
 					$info['NumericPrecision'] = intval($pscale[1]);
161
-					if(count($pscale) > 2)
161
+					if (count($pscale) > 2)
162 162
 						$info['NumericScale'] = intval($pscale[2]);
163 163
 				}
164 164
 				else
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 	{
199 199
 		//remove the back ticks and separate out the "database.table"
200 200
 		$result = explode('.', str_replace('`', '', $table));
201
-		foreach($result as $name)
201
+		foreach ($result as $name)
202 202
 		{
203
-			if(!$this->isValidIdentifier($name))
203
+			if (!$this->isValidIdentifier($name))
204 204
 			{
205 205
 				$ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html';
206 206
 				throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		list($schemaName, $tableName) = $this->getSchemaTableName($table);
230 230
 		$info['SchemaName'] = $schemaName;
231 231
 		$info['TableName'] = $tableName;
232
-		if($this->getIsView($schemaName, $tableName))
232
+		if ($this->getIsView($schemaName, $tableName))
233 233
 			$info['IsView'] = true;
234 234
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
235 235
 		$class = $this->getTableInfoClass();
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 	 */
249 249
 	protected function getIsView($schemaName, $tableName)
250 250
 	{
251
-		if($this->getServerVersion() < 5.01)
251
+		if ($this->getServerVersion() < 5.01)
252 252
 			return false;
253
-		if($schemaName !== null)
253
+		if ($schemaName !== null)
254 254
 			$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
255 255
 		else
256 256
 			$sql = "SHOW FULL TABLES LIKE :table";
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 		{
262 262
 			return count($result = $command->queryRow()) > 0 && $result['Table_type'] === 'VIEW';
263 263
 		}
264
-		catch(TDbException $e)
264
+		catch (TDbException $e)
265 265
 		{
266
-			$table = $schemaName === null?$tableName:$schemaName . '.' . $tableName;
266
+			$table = $schemaName === null ? $tableName : $schemaName.'.'.$tableName;
267 267
 			throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage());
268 268
 		}
269 269
 	}
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 		$sql = "SHOW INDEX FROM {$table}";
281 281
 		$command = $this->getDbConnection()->createCommand($sql);
282 282
 		$primary = [];
283
-		foreach($command->query() as $row)
283
+		foreach ($command->query() as $row)
284 284
 		{
285
-			if($row['Key_name'] === 'PRIMARY')
285
+			if ($row['Key_name'] === 'PRIMARY')
286 286
 				$primary[] = $row['Column_name'];
287 287
 		}
288 288
 				// MySQL version was increased to >=5.1.21 instead of 5.x
289 289
 				// due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
290
-		if($this->getServerVersion() >= 5.121)
290
+		if ($this->getServerVersion() >= 5.121)
291 291
 			$foreign = $this->getForeignConstraints($schemaName, $tableName);
292 292
 		else
293 293
 			$foreign = $this->findForeignConstraints($schemaName, $tableName);
294
-		return [$primary,$foreign];
294
+		return [$primary, $foreign];
295 295
 	}
296 296
 
297 297
 	/**
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
 EOD;
320 320
 		$command = $this->getDbConnection()->createCommand($sql);
321 321
 		$command->bindValue(':table', $tableName);
322
-		if($schemaName !== null)
322
+		if ($schemaName !== null)
323 323
 			$command->bindValue(':schema', $schemaName);
324 324
 		$fkeys = [];
325
-		foreach($command->query() as $col)
325
+		foreach ($command->query() as $col)
326 326
 		{
327 327
 			$fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol'];
328 328
 			$fkeys[$col['con']]['table'] = $col['fktable'];
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
 	 */
339 339
 	protected function getShowCreateTable($schemaName, $tableName)
340 340
 	{
341
-		if(version_compare(PHP_VERSION, '5.1.3', '<'))
341
+		if (version_compare(PHP_VERSION, '5.1.3', '<'))
342 342
 			throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
343 343
 
344 344
 		//See http://netevil.org/node.php?nid=795&SC=1
345 345
 		$this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
346
-		if($schemaName !== null)
346
+		if ($schemaName !== null)
347 347
 			$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
348 348
 		else
349 349
 			$sql = "SHOW CREATE TABLE `{$tableName}`";
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
 		$regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi';
366 366
 		preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER);
367 367
 		$foreign = [];
368
-		foreach($matches as $match)
368
+		foreach ($matches as $match)
369 369
 		{
370 370
 			$fields = array_map('trim', explode(',', str_replace('`', '', $match[1])));
371 371
 			$fk_fields = array_map('trim', explode(',', str_replace('`', '', $match[3])));
372 372
 			$keys = [];
373
-			foreach($fields as $k => $v)
373
+			foreach ($fields as $k => $v)
374 374
 				$keys[$v] = $fk_fields[$k];
375 375
 			$foreign[] = ['keys' => $keys, 'table' => trim($match[2])];
376 376
 		}
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 	 */
385 385
 	protected function isForeignKeyColumn($columnId, $tableInfo)
386 386
 	{
387
-		foreach($tableInfo->getForeignKeys() as $fk)
387
+		foreach ($tableInfo->getForeignKeys() as $fk)
388 388
 		{
389
-			if(in_array($columnId, array_keys($fk['keys'])))
389
+			if (in_array($columnId, array_keys($fk['keys'])))
390 390
 				return true;
391 391
 		}
392 392
 		return false;
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 		 */
401 401
 	public function findTableNames($schema = '')
402 402
 	{
403
-		if($schema === '')
403
+		if ($schema === '')
404 404
 			return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
405
-		$names = $this->getDbConnection()->createCommand('SHOW TABLES FROM ' . $this->quoteTableName($schema))->queryColumn();
406
-		foreach($names as &$name)
407
-			$name = $schema . '.' . $name;
405
+		$names = $this->getDbConnection()->createCommand('SHOW TABLES FROM '.$this->quoteTableName($schema))->queryColumn();
406
+		foreach ($names as &$name)
407
+			$name = $schema.'.'.$name;
408 408
 		return $names;
409 409
 	}
410 410
 }
Please login to merge, or discard this patch.
Braces   +76 added lines, -55 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
83 83
 		list($schemaName, $tableName) = $this->getSchemaTableName($table);
84 84
 		$find = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`";
85 85
 		$colCase = $this->getDbConnection()->getColumnCase();
86
-		if($colCase != TDbColumnCaseMode::Preserved)
87
-			$this->getDbConnection()->setColumnCase('Preserved');
86
+		if($colCase != TDbColumnCaseMode::Preserved) {
87
+					$this->getDbConnection()->setColumnCase('Preserved');
88
+		}
88 89
 		$this->getDbConnection()->setActive(true);
89 90
 		$sql = "SHOW FULL FIELDS FROM {$find}";
90 91
 		$command = $this->getDbConnection()->createCommand($sql);
@@ -95,10 +96,12 @@  discard block
 block discarded – undo
95 96
 			$col['index'] = $index++;
96 97
 			$this->processColumn($tableInfo, $col);
97 98
 		}
98
-		if($index === 0)
99
-			throw new TDbException('dbmetadata_invalid_table_view', $table);
100
-		if($colCase != TDbColumnCaseMode::Preserved)
101
-			$this->getDbConnection()->setColumnCase($colCase);
99
+		if($index === 0) {
100
+					throw new TDbException('dbmetadata_invalid_table_view', $table);
101
+		}
102
+		if($colCase != TDbColumnCaseMode::Preserved) {
103
+					$this->getDbConnection()->setColumnCase($colCase);
104
+		}
102 105
 		return $tableInfo;
103 106
 	}
104 107
 
@@ -128,17 +131,22 @@  discard block
 block discarded – undo
128 131
 		$info['ColumnName'] = "`$columnId`"; //quote the column names!
129 132
 		$info['ColumnId'] = $columnId;
130 133
 		$info['ColumnIndex'] = $col['index'];
131
-		if($col['Null'] === 'YES')
132
-			$info['AllowNull'] = true;
133
-		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment')))
134
-			$info['AutoIncrement'] = true;
135
-		if($col['Default'] !== "")
136
-			$info['DefaultValue'] = $col['Default'];
137
-
138
-		if($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys()))
139
-			$info['IsPrimaryKey'] = true;
140
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
141
-			$info['IsForeignKey'] = true;
134
+		if($col['Null'] === 'YES') {
135
+					$info['AllowNull'] = true;
136
+		}
137
+		if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) {
138
+					$info['AutoIncrement'] = true;
139
+		}
140
+		if($col['Default'] !== "") {
141
+					$info['DefaultValue'] = $col['Default'];
142
+		}
143
+
144
+		if($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) {
145
+					$info['IsPrimaryKey'] = true;
146
+		}
147
+		if($this->isForeignKeyColumn($columnId, $tableInfo)) {
148
+					$info['IsForeignKey'] = true;
149
+		}
142 150
 
143 151
 		$info['DbType'] = $col['Type'];
144 152
 		$match = [];
@@ -148,8 +156,9 @@  discard block
 block discarded – undo
148 156
 			$info['DbType'] = preg_replace('/\(.*\)/', '', $col['Type']);
149 157
 
150 158
 			//find SET/ENUM values
151
-			if($this->isEnumSetType($info['DbType']))
152
-				$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
159
+			if($this->isEnumSetType($info['DbType'])) {
160
+							$info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY);
161
+			}
153 162
 
154 163
 			//find column size, precision and scale
155 164
 			$pscale = [];
@@ -158,11 +167,12 @@  discard block
 block discarded – undo
158 167
 				if($this->isPrecisionType($info['DbType']))
159 168
 				{
160 169
 					$info['NumericPrecision'] = intval($pscale[1]);
161
-					if(count($pscale) > 2)
162
-						$info['NumericScale'] = intval($pscale[2]);
170
+					if(count($pscale) > 2) {
171
+											$info['NumericScale'] = intval($pscale[2]);
172
+					}
173
+				} else {
174
+									$info['ColumnSize'] = intval($pscale[1]);
163 175
 				}
164
-				else
165
-					$info['ColumnSize'] = intval($pscale[1]);
166 176
 			}
167 177
 		}
168 178
 
@@ -229,8 +239,9 @@  discard block
 block discarded – undo
229 239
 		list($schemaName, $tableName) = $this->getSchemaTableName($table);
230 240
 		$info['SchemaName'] = $schemaName;
231 241
 		$info['TableName'] = $tableName;
232
-		if($this->getIsView($schemaName, $tableName))
233
-			$info['IsView'] = true;
242
+		if($this->getIsView($schemaName, $tableName)) {
243
+					$info['IsView'] = true;
244
+		}
234 245
 		list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
235 246
 		$class = $this->getTableInfoClass();
236 247
 		return new $class($info, $primary, $foreign);
@@ -248,20 +259,21 @@  discard block
 block discarded – undo
248 259
 	 */
249 260
 	protected function getIsView($schemaName, $tableName)
250 261
 	{
251
-		if($this->getServerVersion() < 5.01)
252
-			return false;
253
-		if($schemaName !== null)
254
-			$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
255
-		else
256
-			$sql = "SHOW FULL TABLES LIKE :table";
262
+		if($this->getServerVersion() < 5.01) {
263
+					return false;
264
+		}
265
+		if($schemaName !== null) {
266
+					$sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table";
267
+		} else {
268
+					$sql = "SHOW FULL TABLES LIKE :table";
269
+		}
257 270
 
258 271
 		$command = $this->getDbConnection()->createCommand($sql);
259 272
 		$command->bindValue(':table', $tableName);
260 273
 		try
261 274
 		{
262 275
 			return count($result = $command->queryRow()) > 0 && $result['Table_type'] === 'VIEW';
263
-		}
264
-		catch(TDbException $e)
276
+		} catch(TDbException $e)
265 277
 		{
266 278
 			$table = $schemaName === null?$tableName:$schemaName . '.' . $tableName;
267 279
 			throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage());
@@ -282,15 +294,17 @@  discard block
 block discarded – undo
282 294
 		$primary = [];
283 295
 		foreach($command->query() as $row)
284 296
 		{
285
-			if($row['Key_name'] === 'PRIMARY')
286
-				$primary[] = $row['Column_name'];
297
+			if($row['Key_name'] === 'PRIMARY') {
298
+							$primary[] = $row['Column_name'];
299
+			}
287 300
 		}
288 301
 				// MySQL version was increased to >=5.1.21 instead of 5.x
289 302
 				// due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588)
290
-		if($this->getServerVersion() >= 5.121)
291
-			$foreign = $this->getForeignConstraints($schemaName, $tableName);
292
-		else
293
-			$foreign = $this->findForeignConstraints($schemaName, $tableName);
303
+		if($this->getServerVersion() >= 5.121) {
304
+					$foreign = $this->getForeignConstraints($schemaName, $tableName);
305
+		} else {
306
+					$foreign = $this->findForeignConstraints($schemaName, $tableName);
307
+		}
294 308
 		return [$primary,$foreign];
295 309
 	}
296 310
 
@@ -319,8 +333,9 @@  discard block
 block discarded – undo
319 333
 EOD;
320 334
 		$command = $this->getDbConnection()->createCommand($sql);
321 335
 		$command->bindValue(':table', $tableName);
322
-		if($schemaName !== null)
323
-			$command->bindValue(':schema', $schemaName);
336
+		if($schemaName !== null) {
337
+					$command->bindValue(':schema', $schemaName);
338
+		}
324 339
 		$fkeys = [];
325 340
 		foreach($command->query() as $col)
326 341
 		{
@@ -338,15 +353,17 @@  discard block
 block discarded – undo
338 353
 	 */
339 354
 	protected function getShowCreateTable($schemaName, $tableName)
340 355
 	{
341
-		if(version_compare(PHP_VERSION, '5.1.3', '<'))
342
-			throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
356
+		if(version_compare(PHP_VERSION, '5.1.3', '<')) {
357
+					throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3');
358
+		}
343 359
 
344 360
 		//See http://netevil.org/node.php?nid=795&SC=1
345 361
 		$this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
346
-		if($schemaName !== null)
347
-			$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
348
-		else
349
-			$sql = "SHOW CREATE TABLE `{$tableName}`";
362
+		if($schemaName !== null) {
363
+					$sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`";
364
+		} else {
365
+					$sql = "SHOW CREATE TABLE `{$tableName}`";
366
+		}
350 367
 		$command = $this->getDbConnection()->createCommand($sql);
351 368
 		$result = $command->queryRow();
352 369
 		return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : '');
@@ -370,8 +387,9 @@  discard block
 block discarded – undo
370 387
 			$fields = array_map('trim', explode(',', str_replace('`', '', $match[1])));
371 388
 			$fk_fields = array_map('trim', explode(',', str_replace('`', '', $match[3])));
372 389
 			$keys = [];
373
-			foreach($fields as $k => $v)
374
-				$keys[$v] = $fk_fields[$k];
390
+			foreach($fields as $k => $v) {
391
+							$keys[$v] = $fk_fields[$k];
392
+			}
375 393
 			$foreign[] = ['keys' => $keys, 'table' => trim($match[2])];
376 394
 		}
377 395
 		return $foreign;
@@ -386,8 +404,9 @@  discard block
 block discarded – undo
386 404
 	{
387 405
 		foreach($tableInfo->getForeignKeys() as $fk)
388 406
 		{
389
-			if(in_array($columnId, array_keys($fk['keys'])))
390
-				return true;
407
+			if(in_array($columnId, array_keys($fk['keys']))) {
408
+							return true;
409
+			}
391 410
 		}
392 411
 		return false;
393 412
 	}
@@ -400,11 +419,13 @@  discard block
 block discarded – undo
400 419
 		 */
401 420
 	public function findTableNames($schema = '')
402 421
 	{
403
-		if($schema === '')
404
-			return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
422
+		if($schema === '') {
423
+					return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
424
+		}
405 425
 		$names = $this->getDbConnection()->createCommand('SHOW TABLES FROM ' . $this->quoteTableName($schema))->queryColumn();
406
-		foreach($names as &$name)
407
-			$name = $schema . '.' . $name;
426
+		foreach($names as &$name) {
427
+					$name = $schema . '.' . $name;
428
+		}
408 429
 		return $names;
409 430
 	}
410 431
 }
Please login to merge, or discard this patch.
framework/Data/Common/Mysql/TMysqlTableInfo.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@
 block discarded – undo
40 40
 	 */
41 41
 	public function getTableFullName()
42 42
 	{
43
-		if(($schema = $this->getSchemaName()) !== null)
44
-			return '`' . $schema . '`.`' . $this->getTableName() . '`';
43
+		if (($schema = $this->getSchemaName()) !== null)
44
+			return '`'.$schema.'`.`'.$this->getTableName().'`';
45 45
 		else
46
-			return '`' . $this->getTableName() . '`';
46
+			return '`'.$this->getTableName().'`';
47 47
 	}
48 48
 
49 49
 	/**
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,10 +40,11 @@
 block discarded – undo
40 40
 	 */
41 41
 	public function getTableFullName()
42 42
 	{
43
-		if(($schema = $this->getSchemaName()) !== null)
44
-			return '`' . $schema . '`.`' . $this->getTableName() . '`';
45
-		else
46
-			return '`' . $this->getTableName() . '`';
43
+		if(($schema = $this->getSchemaName()) !== null) {
44
+					return '`' . $schema . '`.`' . $this->getTableName() . '`';
45
+		} else {
46
+					return '`' . $this->getTableName() . '`';
47
+		}
47 48
 	}
48 49
 
49 50
 	/**
Please login to merge, or discard this patch.
framework/Data/Common/Mysql/TMysqlTableColumn.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@
 block discarded – undo
39 39
 	 */
40 40
 	public function getPHPType()
41 41
 	{
42
-		$dbtype = trim(str_replace(['unsigned', 'zerofill'], ['','',], strtolower($this->getDbType())));
43
-		if($dbtype === 'tinyint' && $this->getColumnSize() === 1)
42
+		$dbtype = trim(str_replace(['unsigned', 'zerofill'], ['', '', ], strtolower($this->getDbType())));
43
+		if ($dbtype === 'tinyint' && $this->getColumnSize() === 1)
44 44
 			return 'boolean';
45
-		foreach(self::$types as $type => $dbtypes)
45
+		foreach (self::$types as $type => $dbtypes)
46 46
 		{
47
-			if(in_array($dbtype, $dbtypes))
47
+			if (in_array($dbtype, $dbtypes))
48 48
 				return $type;
49 49
 		}
50 50
 		return 'string';
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,12 +40,14 @@
 block discarded – undo
40 40
 	public function getPHPType()
41 41
 	{
42 42
 		$dbtype = trim(str_replace(['unsigned', 'zerofill'], ['','',], strtolower($this->getDbType())));
43
-		if($dbtype === 'tinyint' && $this->getColumnSize() === 1)
44
-			return 'boolean';
43
+		if($dbtype === 'tinyint' && $this->getColumnSize() === 1) {
44
+					return 'boolean';
45
+		}
45 46
 		foreach(self::$types as $type => $dbtypes)
46 47
 		{
47
-			if(in_array($dbtype, $dbtypes))
48
-				return $type;
48
+			if(in_array($dbtype, $dbtypes)) {
49
+							return $type;
50
+			}
49 51
 		}
50 52
 		return 'string';
51 53
 	}
Please login to merge, or discard this patch.
framework/Data/Common/Mssql/TMssqlCommandBuilder.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function getLastInsertID()
33 33
 	{
34
-		foreach($this->getTableInfo()->getColumns() as $column)
34
+		foreach ($this->getTableInfo()->getColumns() as $column)
35 35
 		{
36
-			if($column->hasSequence())
36
+			if ($column->hasSequence())
37 37
 			{
38 38
 				$command = $this->getDbConnection()->createCommand('SELECT @@Identity');
39 39
 				return intval($command->queryScalar());
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		$offset = $offset !== null ? intval($offset) : -1;
88 88
 		if ($limit > 0 && $offset <= 0) //just limit
89 89
 			$sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql);
90
-		elseif($limit > 0 && $offset > 0)
90
+		elseif ($limit > 0 && $offset > 0)
91 91
 			$sql = $this->rewriteLimitOffsetSql($sql, $limit, $offset);
92 92
 		return $sql;
93 93
 	}
@@ -120,20 +120,20 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	protected function findOrdering($sql)
122 122
 	{
123
-		if(!preg_match('/ORDER BY/i', $sql))
123
+		if (!preg_match('/ORDER BY/i', $sql))
124 124
 			return [];
125 125
 		$matches = [];
126 126
 		$ordering = [];
127 127
 		preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches);
128
-		if(count($matches) > 1 && count($matches[2]) > 0)
128
+		if (count($matches) > 1 && count($matches[2]) > 0)
129 129
 		{
130 130
 			$parts = explode(',', $matches[2][0]);
131
-			foreach($parts as $part)
131
+			foreach ($parts as $part)
132 132
 			{
133 133
 				$subs = [];
134
-				if(preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs))
134
+				if (preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs))
135 135
 				{
136
-					if(count($subs) > 1 && count($subs[2]) > 0)
136
+					if (count($subs) > 1 && count($subs[2]) > 0)
137 137
 					{
138 138
 						$ordering[$subs[1][0]] = $subs[2][0];
139 139
 					}
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	protected function joinOrdering($orders)
154 154
 	{
155
-		if(count($orders) > 0)
155
+		if (count($orders) > 0)
156 156
 		{
157 157
 			$str = [];
158
-			foreach($orders as $column => $direction)
159
-				$str[] = $column . ' ' . $direction;
160
-			return 'ORDER BY ' . implode(', ', $str);
158
+			foreach ($orders as $column => $direction)
159
+				$str[] = $column.' '.$direction;
160
+			return 'ORDER BY '.implode(', ', $str);
161 161
 		}
162 162
 	}
163 163
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 */
168 168
 	protected function reverseDirection($orders)
169 169
 	{
170
-		foreach($orders as $column => $direction)
170
+		foreach ($orders as $column => $direction)
171 171
 			$orders[$column] = strtolower(trim($direction)) === 'desc' ? 'ASC' : 'DESC';
172 172
 		return $orders;
173 173
 	}
Please login to merge, or discard this patch.
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -85,10 +85,12 @@  discard block
 block discarded – undo
85 85
 	{
86 86
 		$limit = $limit !== null ? intval($limit) : -1;
87 87
 		$offset = $offset !== null ? intval($offset) : -1;
88
-		if ($limit > 0 && $offset <= 0) //just limit
88
+		if ($limit > 0 && $offset <= 0) {
89
+			//just limit
89 90
 			$sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql);
90
-		elseif($limit > 0 && $offset > 0)
91
-			$sql = $this->rewriteLimitOffsetSql($sql, $limit, $offset);
91
+		} elseif($limit > 0 && $offset > 0) {
92
+					$sql = $this->rewriteLimitOffsetSql($sql, $limit, $offset);
93
+		}
92 94
 		return $sql;
93 95
 	}
94 96
 
@@ -120,8 +122,9 @@  discard block
 block discarded – undo
120 122
 	 */
121 123
 	protected function findOrdering($sql)
122 124
 	{
123
-		if(!preg_match('/ORDER BY/i', $sql))
124
-			return [];
125
+		if(!preg_match('/ORDER BY/i', $sql)) {
126
+					return [];
127
+		}
125 128
 		$matches = [];
126 129
 		$ordering = [];
127 130
 		preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches);
@@ -138,9 +141,9 @@  discard block
 block discarded – undo
138 141
 						$ordering[$subs[1][0]] = $subs[2][0];
139 142
 					}
140 143
 					//else what?
144
+				} else {
145
+									$ordering[trim($part)] = 'ASC';
141 146
 				}
142
-				else
143
-					$ordering[trim($part)] = 'ASC';
144 147
 			}
145 148
 		}
146 149
 		return $ordering;
@@ -155,8 +158,9 @@  discard block
 block discarded – undo
155 158
 		if(count($orders) > 0)
156 159
 		{
157 160
 			$str = [];
158
-			foreach($orders as $column => $direction)
159
-				$str[] = $column . ' ' . $direction;
161
+			foreach($orders as $column => $direction) {
162
+							$str[] = $column . ' ' . $direction;
163
+			}
160 164
 			return 'ORDER BY ' . implode(', ', $str);
161 165
 		}
162 166
 	}
@@ -167,8 +171,9 @@  discard block
 block discarded – undo
167 171
 	 */
168 172
 	protected function reverseDirection($orders)
169 173
 	{
170
-		foreach($orders as $column => $direction)
171
-			$orders[$column] = strtolower(trim($direction)) === 'desc' ? 'ASC' : 'DESC';
174
+		foreach($orders as $column => $direction) {
175
+					$orders[$column] = strtolower(trim($direction)) === 'desc' ? 'ASC' : 'DESC';
176
+		}
172 177
 		return $orders;
173 178
 	}
174 179
 }
Please login to merge, or discard this patch.
framework/Data/Common/Mssql/TMssqlMetaData.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -84,26 +84,26 @@  discard block
 block discarded – undo
84 84
 									WHERE t.table_name = c.table_name
85 85
 										AND t.table_name = :table
86 86
 EOD;
87
-		if($schemaName !== null)
87
+		if ($schemaName !== null)
88 88
 			$sql .= ' AND t.table_schema = :schema';
89
-		if($catalogName !== null)
89
+		if ($catalogName !== null)
90 90
 			$sql .= ' AND t.table_catalog = :catalog';
91 91
 
92 92
 		$command = $this->getDbConnection()->createCommand($sql);
93 93
 		$command->bindValue(':table', $tableName);
94
-		if($schemaName !== null)
94
+		if ($schemaName !== null)
95 95
 			$command->bindValue(':schema', $schemaName);
96
-		if($catalogName !== null)
96
+		if ($catalogName !== null)
97 97
 			$command->bindValue(':catalog', $catalogName);
98 98
 
99 99
 		$tableInfo = null;
100
-		foreach($command->query() as $col)
100
+		foreach ($command->query() as $col)
101 101
 		{
102
-			if($tableInfo === null)
102
+			if ($tableInfo === null)
103 103
 				$tableInfo = $this->createNewTableInfo($col);
104 104
 			$this->processColumn($tableInfo, $col);
105 105
 		}
106
-		if($tableInfo === null)
106
+		if ($tableInfo === null)
107 107
 			throw new TDbException('dbmetadata_invalid_table_view', $table);
108 108
 		return $tableInfo;
109 109
 	}
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 	{
117 117
 		//remove possible delimiters
118 118
 		$result = explode('.', preg_replace('/\[|\]|"/', '', $table));
119
-		if(count($result) === 1)
120
-			return [null,null,$result[0]];
121
-		if(count($result) === 2)
122
-			return [null,$result[0],$result[1]];
123
-		if(count($result) > 2)
124
-			return [$result[0],$result[1],$result[2]];
119
+		if (count($result) === 1)
120
+			return [null, null, $result[0]];
121
+		if (count($result) === 2)
122
+			return [null, $result[0], $result[1]];
123
+		if (count($result) > 2)
124
+			return [$result[0], $result[1], $result[2]];
125 125
 	}
126 126
 
127 127
 	/**
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
 		$info['ColumnName'] = "[$columnId]"; //quote the column names!
136 136
 		$info['ColumnId'] = $columnId;
137 137
 		$info['ColumnIndex'] = intval($col['ORDINAL_POSITION']) - 1; //zero-based index
138
-		if($col['IS_NULLABLE'] !== 'NO')
138
+		if ($col['IS_NULLABLE'] !== 'NO')
139 139
 			$info['AllowNull'] = true;
140
-		if($col['COLUMN_DEFAULT'] !== null)
140
+		if ($col['COLUMN_DEFAULT'] !== null)
141 141
 			$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
142 142
 
143
-		if(in_array($columnId, $tableInfo->getPrimaryKeys()))
143
+		if (in_array($columnId, $tableInfo->getPrimaryKeys()))
144 144
 			$info['IsPrimaryKey'] = true;
145
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
145
+		if ($this->isForeignKeyColumn($columnId, $tableInfo))
146 146
 			$info['IsForeignKey'] = true;
147 147
 
148
-		if($col['IsIdentity'] === '1')
148
+		if ($col['IsIdentity'] === '1')
149 149
 			$info['AutoIncrement'] = true;
150 150
 		$info['DbType'] = $col['DATA_TYPE'];
151
-		if($col['CHARACTER_MAXIMUM_LENGTH'] !== null)
151
+		if ($col['CHARACTER_MAXIMUM_LENGTH'] !== null)
152 152
 			$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
153
-		if($col['NUMERIC_PRECISION'] !== null)
153
+		if ($col['NUMERIC_PRECISION'] !== null)
154 154
 			$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
155
-		if($col['NUMERIC_SCALE'] !== null)
155
+		if ($col['NUMERIC_SCALE'] !== null)
156 156
 			$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
157 157
 		$tableInfo->Columns[$columnId] = new TMssqlTableColumn($info);
158 158
 	}
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		$info['CatalogName'] = $col['TABLE_CATALOG'];
168 168
 		$info['SchemaName'] = $col['TABLE_SCHEMA'];
169 169
 		$info['TableName'] = $col['TABLE_NAME'];
170
-		if($col['TABLE_TYPE'] === 'VIEW')
170
+		if ($col['TABLE_TYPE'] === 'VIEW')
171 171
 			$info['IsView'] = true;
172 172
 		list($primary, $foreign) = $this->getConstraintKeys($col);
173 173
 		$class = $this->getTableInfoClass();
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
 		$command = $this->getDbConnection()->createCommand($sql);
197 197
 		$command->bindValue(':table', $col['TABLE_NAME']);
198 198
 		$primary = [];
199
-		foreach($command->query()->readAll() as $field)
199
+		foreach ($command->query()->readAll() as $field)
200 200
 			$primary[] = $field['field_name'];
201 201
 		$foreign = $this->getForeignConstraints($col);
202
-		return [$primary,$foreign];
202
+		return [$primary, $foreign];
203 203
 	}
204 204
 
205 205
 	/**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		$command->bindValue(':table', $col['TABLE_NAME']);
241 241
 		$fkeys = [];
242 242
 		$catalogSchema = "[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]";
243
-		foreach($command->query() as $info)
243
+		foreach ($command->query() as $info)
244 244
 		{
245 245
 			$fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']] = $info['UQ_COLUMN_NAME'];
246 246
 			$fkeys[$info['FK_CONSTRAINT_NAME']]['table'] = $info['UQ_TABLE_NAME'];
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 */
256 256
 	protected function isForeignKeyColumn($columnId, $tableInfo)
257 257
 	{
258
-		foreach($tableInfo->getForeignKeys() as $fk)
258
+		foreach ($tableInfo->getForeignKeys() as $fk)
259 259
 		{
260
-			if(in_array($columnId, array_keys($fk['keys'])))
260
+			if (in_array($columnId, array_keys($fk['keys'])))
261 261
 				return true;
262 262
 		}
263 263
 		return false;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 			if ($schema == self::DEFAULT_SCHEMA)
286 286
 				$names[] = $row['TABLE_NAME'];
287 287
 			else
288
-				$names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'];
288
+				$names[] = $schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME'];
289 289
 		}
290 290
 
291 291
 		return $names;
Please login to merge, or discard this patch.
Braces   +65 added lines, -44 removed lines patch added patch discarded remove patch
@@ -84,27 +84,33 @@  discard block
 block discarded – undo
84 84
 									WHERE t.table_name = c.table_name
85 85
 										AND t.table_name = :table
86 86
 EOD;
87
-		if($schemaName !== null)
88
-			$sql .= ' AND t.table_schema = :schema';
89
-		if($catalogName !== null)
90
-			$sql .= ' AND t.table_catalog = :catalog';
87
+		if($schemaName !== null) {
88
+					$sql .= ' AND t.table_schema = :schema';
89
+		}
90
+		if($catalogName !== null) {
91
+					$sql .= ' AND t.table_catalog = :catalog';
92
+		}
91 93
 
92 94
 		$command = $this->getDbConnection()->createCommand($sql);
93 95
 		$command->bindValue(':table', $tableName);
94
-		if($schemaName !== null)
95
-			$command->bindValue(':schema', $schemaName);
96
-		if($catalogName !== null)
97
-			$command->bindValue(':catalog', $catalogName);
96
+		if($schemaName !== null) {
97
+					$command->bindValue(':schema', $schemaName);
98
+		}
99
+		if($catalogName !== null) {
100
+					$command->bindValue(':catalog', $catalogName);
101
+		}
98 102
 
99 103
 		$tableInfo = null;
100 104
 		foreach($command->query() as $col)
101 105
 		{
102
-			if($tableInfo === null)
103
-				$tableInfo = $this->createNewTableInfo($col);
106
+			if($tableInfo === null) {
107
+							$tableInfo = $this->createNewTableInfo($col);
108
+			}
104 109
 			$this->processColumn($tableInfo, $col);
105 110
 		}
106
-		if($tableInfo === null)
107
-			throw new TDbException('dbmetadata_invalid_table_view', $table);
111
+		if($tableInfo === null) {
112
+					throw new TDbException('dbmetadata_invalid_table_view', $table);
113
+		}
108 114
 		return $tableInfo;
109 115
 	}
110 116
 
@@ -116,12 +122,15 @@  discard block
 block discarded – undo
116 122
 	{
117 123
 		//remove possible delimiters
118 124
 		$result = explode('.', preg_replace('/\[|\]|"/', '', $table));
119
-		if(count($result) === 1)
120
-			return [null,null,$result[0]];
121
-		if(count($result) === 2)
122
-			return [null,$result[0],$result[1]];
123
-		if(count($result) > 2)
124
-			return [$result[0],$result[1],$result[2]];
125
+		if(count($result) === 1) {
126
+					return [null,null,$result[0]];
127
+		}
128
+		if(count($result) === 2) {
129
+					return [null,$result[0],$result[1]];
130
+		}
131
+		if(count($result) > 2) {
132
+					return [$result[0],$result[1],$result[2]];
133
+		}
125 134
 	}
126 135
 
127 136
 	/**
@@ -135,25 +144,33 @@  discard block
 block discarded – undo
135 144
 		$info['ColumnName'] = "[$columnId]"; //quote the column names!
136 145
 		$info['ColumnId'] = $columnId;
137 146
 		$info['ColumnIndex'] = intval($col['ORDINAL_POSITION']) - 1; //zero-based index
138
-		if($col['IS_NULLABLE'] !== 'NO')
139
-			$info['AllowNull'] = true;
140
-		if($col['COLUMN_DEFAULT'] !== null)
141
-			$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
147
+		if($col['IS_NULLABLE'] !== 'NO') {
148
+					$info['AllowNull'] = true;
149
+		}
150
+		if($col['COLUMN_DEFAULT'] !== null) {
151
+					$info['DefaultValue'] = $col['COLUMN_DEFAULT'];
152
+		}
142 153
 
143
-		if(in_array($columnId, $tableInfo->getPrimaryKeys()))
144
-			$info['IsPrimaryKey'] = true;
145
-		if($this->isForeignKeyColumn($columnId, $tableInfo))
146
-			$info['IsForeignKey'] = true;
154
+		if(in_array($columnId, $tableInfo->getPrimaryKeys())) {
155
+					$info['IsPrimaryKey'] = true;
156
+		}
157
+		if($this->isForeignKeyColumn($columnId, $tableInfo)) {
158
+					$info['IsForeignKey'] = true;
159
+		}
147 160
 
148
-		if($col['IsIdentity'] === '1')
149
-			$info['AutoIncrement'] = true;
161
+		if($col['IsIdentity'] === '1') {
162
+					$info['AutoIncrement'] = true;
163
+		}
150 164
 		$info['DbType'] = $col['DATA_TYPE'];
151
-		if($col['CHARACTER_MAXIMUM_LENGTH'] !== null)
152
-			$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
153
-		if($col['NUMERIC_PRECISION'] !== null)
154
-			$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
155
-		if($col['NUMERIC_SCALE'] !== null)
156
-			$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
165
+		if($col['CHARACTER_MAXIMUM_LENGTH'] !== null) {
166
+					$info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']);
167
+		}
168
+		if($col['NUMERIC_PRECISION'] !== null) {
169
+					$info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']);
170
+		}
171
+		if($col['NUMERIC_SCALE'] !== null) {
172
+					$info['NumericScale'] = intval($col['NUMERIC_SCALE']);
173
+		}
157 174
 		$tableInfo->Columns[$columnId] = new TMssqlTableColumn($info);
158 175
 	}
159 176
 
@@ -167,8 +184,9 @@  discard block
 block discarded – undo
167 184
 		$info['CatalogName'] = $col['TABLE_CATALOG'];
168 185
 		$info['SchemaName'] = $col['TABLE_SCHEMA'];
169 186
 		$info['TableName'] = $col['TABLE_NAME'];
170
-		if($col['TABLE_TYPE'] === 'VIEW')
171
-			$info['IsView'] = true;
187
+		if($col['TABLE_TYPE'] === 'VIEW') {
188
+					$info['IsView'] = true;
189
+		}
172 190
 		list($primary, $foreign) = $this->getConstraintKeys($col);
173 191
 		$class = $this->getTableInfoClass();
174 192
 		return new $class($info, $primary, $foreign);
@@ -196,8 +214,9 @@  discard block
 block discarded – undo
196 214
 		$command = $this->getDbConnection()->createCommand($sql);
197 215
 		$command->bindValue(':table', $col['TABLE_NAME']);
198 216
 		$primary = [];
199
-		foreach($command->query()->readAll() as $field)
200
-			$primary[] = $field['field_name'];
217
+		foreach($command->query()->readAll() as $field) {
218
+					$primary[] = $field['field_name'];
219
+		}
201 220
 		$foreign = $this->getForeignConstraints($col);
202 221
 		return [$primary,$foreign];
203 222
 	}
@@ -257,8 +276,9 @@  discard block
 block discarded – undo
257 276
 	{
258 277
 		foreach($tableInfo->getForeignKeys() as $fk)
259 278
 		{
260
-			if(in_array($columnId, array_keys($fk['keys'])))
261
-				return true;
279
+			if(in_array($columnId, array_keys($fk['keys']))) {
280
+							return true;
281
+			}
262 282
 		}
263 283
 		return false;
264 284
 	}
@@ -282,10 +302,11 @@  discard block
 block discarded – undo
282 302
 		$names = [];
283 303
 		foreach ($rows as $row)
284 304
 		{
285
-			if ($schema == self::DEFAULT_SCHEMA)
286
-				$names[] = $row['TABLE_NAME'];
287
-			else
288
-				$names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'];
305
+			if ($schema == self::DEFAULT_SCHEMA) {
306
+							$names[] = $row['TABLE_NAME'];
307
+			} else {
308
+							$names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'];
309
+			}
289 310
 		}
290 311
 
291 312
 		return $names;
Please login to merge, or discard this patch.
framework/Data/Common/TDbTableInfo.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function getColumn($name)
119 119
 	{
120
-		if(($column = $this->_columns->itemAt($name)) !== null)
120
+		if (($column = $this->_columns->itemAt($name)) !== null)
121 121
 			return $column;
122 122
 		throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
123 123
 	}
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	public function getColumnNames()
130 130
 	{
131
-		if($this->_names === null)
131
+		if ($this->_names === null)
132 132
 		{
133 133
 			$this->_names = [];
134
-			foreach($this->getColumns() as $column)
134
+			foreach ($this->getColumns() as $column)
135 135
 				$this->_names[] = $column->getColumnName();
136 136
 		}
137 137
 		return $this->_names;
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	public function getLowerCaseColumnNames()
160 160
 	{
161
-		if($this->_lowercase === null)
161
+		if ($this->_lowercase === null)
162 162
 		{
163 163
 			$this->_lowercase = [];
164
-			foreach($this->getColumns()->getKeys() as $key)
164
+			foreach ($this->getColumns()->getKeys() as $key)
165 165
 				$this->_lowercase[strtolower($key)] = $key;
166 166
 		}
167 167
 		return $this->_lowercase;
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -117,8 +117,9 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function getColumn($name)
119 119
 	{
120
-		if(($column = $this->_columns->itemAt($name)) !== null)
121
-			return $column;
120
+		if(($column = $this->_columns->itemAt($name)) !== null) {
121
+					return $column;
122
+		}
122 123
 		throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
123 124
 	}
124 125
 
@@ -131,8 +132,9 @@  discard block
 block discarded – undo
131 132
 		if($this->_names === null)
132 133
 		{
133 134
 			$this->_names = [];
134
-			foreach($this->getColumns() as $column)
135
-				$this->_names[] = $column->getColumnName();
135
+			foreach($this->getColumns() as $column) {
136
+							$this->_names[] = $column->getColumnName();
137
+			}
136 138
 		}
137 139
 		return $this->_names;
138 140
 	}
@@ -161,8 +163,9 @@  discard block
 block discarded – undo
161 163
 		if($this->_lowercase === null)
162 164
 		{
163 165
 			$this->_lowercase = [];
164
-			foreach($this->getColumns()->getKeys() as $key)
165
-				$this->_lowercase[strtolower($key)] = $key;
166
+			foreach($this->getColumns()->getKeys() as $key) {
167
+							$this->_lowercase[strtolower($key)] = $key;
168
+			}
166 169
 		}
167 170
 		return $this->_lowercase;
168 171
 	}
Please login to merge, or discard this patch.