Completed
Push — 3.4 ( 68f63c...14426e )
by David
01:02
created
src/Mouf/Database/TDBM/TDBMService.php 5 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -711,10 +711,10 @@  discard block
 block discarded – undo
711 711
 	
712 712
 	/**
713 713
 	 * Returns a generator for the database.
714
-	 * @param unknown $result
714
+	 * @param \PDOStatement $result
715 715
 	 * @param unknown $table_name
716
-	 * @param unknown $className
717
-	 * @param unknown $sql
716
+	 * @param string $className
717
+	 * @param string $sql
718 718
 	 */
719 719
 	private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) {
720 720
 		$keysStandardCased = array();
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
 	 * @param unknown_type $target_tables
1101 1101
 	 * @param unknown_type $path
1102 1102
 	 * @param unknown_type $queue
1103
-	 * @return unknown
1103
+	 * @return boolean
1104 1104
 	 */
1105 1105
 	private function find_paths_iter(&$target_tables, &$path, &$queue) {
1106 1106
 		// Get table to look at:
@@ -1569,7 +1569,7 @@  discard block
 block discarded – undo
1569 1569
 	 * Takes in input a filter_bag (which can be about anything from a string to an array of TDBMObjects... see above from documentation),
1570 1570
 	 * and gives back a proper Filter object.
1571 1571
 	 *
1572
-	 * @param unknown_type $filter_bag
1572
+	 * @param unknown_type|null $filter_bag
1573 1573
 	 * @return FilterInterface
1574 1574
 	 */
1575 1575
 	public function buildFilterFromFilterBag($filter_bag) {
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 	 * Takes in input an order_bag (which can be about anything from a string to an array of OrderByColumn objects... see above from documentation),
1635 1635
 	 * and gives back an array of OrderByColumn / OrderBySQLString objects.
1636 1636
 	 *
1637
-	 * @param unknown_type $orderby_bag
1637
+	 * @param unknown_type|null $orderby_bag
1638 1638
 	 * @return array
1639 1639
 	 */
1640 1640
 	public function buildOrderArrayFromOrderBag($orderby_bag) {
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
 	 * @param bool $support If the generated daos should keep support for old functions (eg : getUserList and getList)
1852 1852
 	 * @param bool $storeInUtc If the generated daos should store the date in UTC timezone instead of user's timezone.
1853 1853
 	 * @param bool $castDatesToDateTime
1854
-	 * @return \string[] the list of tables
1854
+	 * @return string[] the list of tables
1855 1855
 	 */
1856 1856
 	public function generateAllDaosAndBeans($daoFactoryClassName, $daonamespace, $beannamespace, $support, $storeInUtc, $castDatesToDateTime) {
1857 1857
 		$tdbmDaoGenerator = new TDBMDaoGenerator($this->dbConnection);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,6 @@
 block discarded – undo
28 28
 use Mouf\Utils\Cache\CacheInterface;
29 29
 use Mouf\Database\TDBM\Filters\FilterInterface;
30 30
 use Mouf\Database\DBConnection\ConnectionInterface;
31
-use Mouf\Database\DBConnection\DBConnectionException;
32 31
 use Mouf\Database\TDBM\Filters\OrFilter;
33 32
 use Mouf\Database\TDBM\Utils\TDBMDaoGenerator;
34 33
 
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -545,45 +545,45 @@  discard block
 block discarded – undo
545 545
 		}
546 546
 	}
547 547
 
548
-    /**
549
-     * This function removes the given object from the database. It will also remove all objects relied to the one given
550
-     * by parameter before all.
551
-     *
552
-     * Notice: if the object has a multiple primary key, the function will not work.
553
-     *
554
-     * @param TDBMObject $objToDelete
555
-     */
556
-    public function deleteCascade(TDBMObject $objToDelete) {
557
-        $this->deleteAllConstraintWithThisObject($objToDelete);
558
-        $this->deleteObject($objToDelete);
559
-    }
560
-
561
-    /**
562
-     * This function is used only in TDBMService (private function)
563
-     * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter
564
-     *
565
-     * @param TDBMObject $obj
566
-     * @return TDBMObjectArray
567
-     */
568
-    private function deleteAllConstraintWithThisObject(TDBMObject $obj) {
569
-        $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName());
570
-        $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom);
571
-        foreach ($constraints as $constraint) {
572
-            $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]);
573
-            $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]);
574
-            $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]);
575
-            $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]);
576
-            $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id);
577
-            $sql = "SELECT DISTINCT ".$tableTo.".*"
578
-                    ." FROM ".$tableFrom
579
-                    ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo
580
-                    ." WHERE ".$tableFrom.".".$idVarName."=".$idValue;
581
-            $result = $this->getObjectsFromSQL($constraint["table1"], $sql);
582
-            foreach ($result as $tdbmObj) {
583
-                $this->deleteCascade($tdbmObj);
584
-            }
585
-        }
586
-    }
548
+	/**
549
+	 * This function removes the given object from the database. It will also remove all objects relied to the one given
550
+	 * by parameter before all.
551
+	 *
552
+	 * Notice: if the object has a multiple primary key, the function will not work.
553
+	 *
554
+	 * @param TDBMObject $objToDelete
555
+	 */
556
+	public function deleteCascade(TDBMObject $objToDelete) {
557
+		$this->deleteAllConstraintWithThisObject($objToDelete);
558
+		$this->deleteObject($objToDelete);
559
+	}
560
+
561
+	/**
562
+	 * This function is used only in TDBMService (private function)
563
+	 * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter
564
+	 *
565
+	 * @param TDBMObject $obj
566
+	 * @return TDBMObjectArray
567
+	 */
568
+	private function deleteAllConstraintWithThisObject(TDBMObject $obj) {
569
+		$tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName());
570
+		$constraints = $this->dbConnection->getConstraintsFromTable($tableFrom);
571
+		foreach ($constraints as $constraint) {
572
+			$tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]);
573
+			$colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]);
574
+			$colTo = $this->dbConnection->escapeDBItem($constraint["col1"]);
575
+			$idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]);
576
+			$idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id);
577
+			$sql = "SELECT DISTINCT ".$tableTo.".*"
578
+					." FROM ".$tableFrom
579
+					." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo
580
+					." WHERE ".$tableFrom.".".$idVarName."=".$idValue;
581
+			$result = $this->getObjectsFromSQL($constraint["table1"], $sql);
582
+			foreach ($result as $tdbmObj) {
583
+				$this->deleteCascade($tdbmObj);
584
+			}
585
+		}
586
+	}
587 587
 
588 588
 	/**
589 589
 	 * The getObjectsFromSQL is used to retrieve objects from the database using a full SQL query.
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 			}
645 645
 			$keysStandardCased = array();
646 646
 			$firstLine = true;
647
-            $colsArray = null;
647
+			$colsArray = null;
648 648
 			while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC))
649 649
 			{
650 650
 				$row = array();
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
 					$id = serialize($ids);
677 677
 				}
678 678
 
679
-                $obj = $this->objectStorage->get($table_name,$id);
679
+				$obj = $this->objectStorage->get($table_name,$id);
680 680
 				if ($obj === null)
681 681
 				{
682 682
 					if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) {
683 683
 						throw new TDBMException("Error while calling TDBM: The class ".$className." should extend TDBMObject.");
684 684
 					}
685 685
 					$obj = new $className($this, $table_name, $id);
686
-                    $obj->loadFromRow($row, $colsArray);
687
-                    $this->objectStorage->set($table_name, $id, $obj);
686
+					$obj->loadFromRow($row, $colsArray);
687
+					$this->objectStorage->set($table_name, $id, $obj);
688 688
 				} elseif ($obj->_getStatus() == "not loaded") {
689
-                    $obj->loadFromRow($row, $colsArray);
689
+					$obj->loadFromRow($row, $colsArray);
690 690
 					// Check that the object fetched from cache is from the requested class.
691 691
 					if (!is_a($obj, $className)) {
692 692
 						throw new TDBMException("Error while calling TDBM: An object fetched from database is already present in TDBM cache and they do not share the same class. You requested the object to be of the class ".$className." but the object available locally is of the class ".get_class($obj).".");
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) {
720 720
 		$keysStandardCased = array();
721 721
 		$firstLine = true;
722
-        $colsArray = null;
722
+		$colsArray = null;
723 723
 		while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC))
724 724
 		{
725 725
 			$row = array();
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 				}
751 751
 				$id = serialize($ids);
752 752
 			}
753
-            $obj = $this->objectStorage->get($table_name, $id);
753
+			$obj = $this->objectStorage->get($table_name, $id);
754 754
 			if ($obj === null)
755 755
 			{
756 756
 				if ($className == null) {
@@ -763,10 +763,10 @@  discard block
 block discarded – undo
763 763
 				} else {
764 764
 					throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className);
765 765
 				}
766
-                $obj->loadFromRow($row, $colsArray);
767
-                $this->objectStorage->set($table_name, $id, $obj);
766
+				$obj->loadFromRow($row, $colsArray);
767
+				$this->objectStorage->set($table_name, $id, $obj);
768 768
 			} elseif ($obj->_getStatus() == "not loaded") {
769
-                $obj->loadFromRow($row, $colsArray);
769
+				$obj->loadFromRow($row, $colsArray);
770 770
 				// Check that the object fetched from cache is from the requested class.
771 771
 				if ($className != null) {
772 772
 					if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) {
@@ -1665,9 +1665,9 @@  discard block
 block discarded – undo
1665 1665
 	 * Throws a TDBMException if one of those table does not exist.
1666 1666
 	 *
1667 1667
 	 * @param array $tables
1668
-     * @throws TDBMException
1668
+	 * @throws TDBMException
1669 1669
 	 */
1670
-    private function checkTablesExist($tables) {
1670
+	private function checkTablesExist($tables) {
1671 1671
 		foreach ($tables as $table) {
1672 1672
 			$possible_tables = $this->dbConnection->checkTableExist($table);
1673 1673
 			if ($possible_tables !== true)
@@ -1740,12 +1740,12 @@  discard block
 block discarded – undo
1740 1740
 	 * This function returns the HTML to draw a tree of DisplayNode.
1741 1741
 	 *
1742 1742
 	 * @param DisplayNode $tree
1743
-     * @param int $x
1744
-     * @param int $y
1745
-     * @param int $ret_width
1746
-     * @param int $ret_height
1747
-     *
1748
-     * @return string
1743
+	 * @param int $x
1744
+	 * @param int $y
1745
+	 * @param int $ret_width
1746
+	 * @param int $ret_height
1747
+	 *
1748
+	 * @return string
1749 1749
 	 */
1750 1750
 	public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) {
1751 1751
 
@@ -1859,8 +1859,8 @@  discard block
 block discarded – undo
1859 1859
 	}
1860 1860
 
1861 1861
 	/**
1862
- 	* @param array<string, string> $tableToBeanMap
1863
- 	*/
1862
+	 * @param array<string, string> $tableToBeanMap
1863
+	 */
1864 1864
 	public function setTableToBeanMap(array $tableToBeanMap) {
1865 1865
 		$this->tableToBeanMap = $tableToBeanMap;
1866 1866
 	}
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	private $tableToBeanMap = [];
149 149
 	
150 150
 	public function __construct() {
151
-		register_shutdown_function(array($this,"completeSaveOnExit"));
151
+		register_shutdown_function(array($this, "completeSaveOnExit"));
152 152
 		if (extension_loaded('weakref')) {
153 153
 			$this->objectStorage = new WeakrefObjectStorage();
154 154
 		} else {
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 				$objects = $this->getObjects($table_name, $filters, null, null, null, $className);
369 369
 				if (count($objects) == 0) {
370 370
 					return null;
371
-				} elseif (count($objects) > 1) {
371
+				} elseif (count($objects)>1) {
372 372
 					throw new DuplicateRowException("Error while querying an object for table '$table_name': ".count($objects)." rows have been returned, but we should have received at most one.");
373 373
 				}
374 374
 				// Return the first and only object.
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	 * @param string $className Optional: The name of the class to instanciate. This class must extend the TDBMObject class. If none is specified, a TDBMObject instance will be returned.
446 446
 	 * @return TDBMObject
447 447
 	 */
448
-	public function getNewObject($table_name, $auto_assign_id=true, $className = null) {
448
+	public function getNewObject($table_name, $auto_assign_id = true, $className = null) {
449 449
 		if ($this->dbConnection == null) {
450 450
 			throw new TDBMException("Error while calling TDBMObject::getNewObject(): No connection has been established on the database!");
451 451
 		}
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 		$object = new $className($this, $table_name);
480 480
 
481 481
 		if ($auto_assign_id && !$this->isPrimaryKeyAutoIncrement($table_name)) {
482
-			$pk_table =  $this->getPrimaryKeyStatic($table_name);
483
-			if (count($pk_table)==1)
482
+			$pk_table = $this->getPrimaryKeyStatic($table_name);
483
+			if (count($pk_table) == 1)
484 484
 			{
485 485
 				$root_table = $this->dbConnection->findRootSequenceTable($table_name);
486 486
 				$id = $this->dbConnection->nextId($root_table);
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 					$sql = "SELECT MAX(".$this->dbConnection->escapeDBItem($pk_table[0]).") AS maxkey FROM ".$root_table;
491 491
 					$res = $this->dbConnection->getAll($sql);
492 492
 					// NOTE: this will work only if the ID is an integer!
493
-					$newid = $res[0]['maxkey'] + 1;
493
+					$newid = $res[0]['maxkey']+1;
494 494
 					if ($newid>$id) {
495 495
 						$id = $newid;
496 496
 					}
@@ -520,17 +520,17 @@  discard block
 block discarded – undo
520 520
 			// Now for the object_id
521 521
 			$object_id = $object->TDBMObject_id;
522 522
 			// If there is only one primary key:
523
-			if (count($pk_table)==1) {
523
+			if (count($pk_table) == 1) {
524 524
 				$sql_where = $this->dbConnection->escapeDBItem($pk_table[0])."=".$this->dbConnection->quoteSmart($object->TDBMObject_id);
525 525
 			} else {
526 526
 				$ids = unserialize($object_id);
527
-				$i=0;
527
+				$i = 0;
528 528
 				$sql_where_array = array();
529 529
 				foreach ($pk_table as $pk) {
530 530
 					$sql_where_array[] = $this->dbConnection->escapeDBItem($pk)."=".$this->dbConnection->quoteSmart($ids[$i]);
531 531
 					$i++;
532 532
 				}
533
-				$sql_where = implode(" AND ",$sql_where_array);
533
+				$sql_where = implode(" AND ", $sql_where_array);
534 534
 			}
535 535
 
536 536
 
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 	 * @param string $className Optional: The name of the class to instanciate. This class must extend the TDBMObject class. If none is specified, a TDBMObject instance will be returned.
614 614
 	 * @return array|Generator|TDBMObjectArray The result set of the query as a TDBMObjectArray (an array of TDBMObjects with special properties)
615 615
 	 */
616
-	public function getObjectsFromSQL($table_name, $sql, $from=null, $limit=null, $className=null) {
616
+	public function getObjectsFromSQL($table_name, $sql, $from = null, $limit = null, $className = null) {
617 617
 		if ($this->dbConnection == null) {
618 618
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
619 619
 		}
@@ -656,10 +656,10 @@  discard block
 block discarded – undo
656 656
 					$firstLine = false;
657 657
 				}
658 658
 				foreach ($fullCaseRow as $key=>$value) {
659
-					$row[$keysStandardCased[$key]]=$value;
659
+					$row[$keysStandardCased[$key]] = $value;
660 660
 				}
661 661
 				$pk_table = $this->primary_keys[$table_name];
662
-				if (count($pk_table)==1)
662
+				if (count($pk_table) == 1)
663 663
 				{
664 664
 					if (!isset($keysStandardCased[$pk_table[0]])) {
665 665
 						throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '$table_name' table. Could not find primary key in this set of rows. SQL request passed: ".$sql);
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 					$id = serialize($ids);
677 677
 				}
678 678
 
679
-                $obj = $this->objectStorage->get($table_name,$id);
679
+                $obj = $this->objectStorage->get($table_name, $id);
680 680
 				if ($obj === null)
681 681
 				{
682 682
 					if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) {
@@ -731,10 +731,10 @@  discard block
 block discarded – undo
731 731
 				$firstLine = false;
732 732
 			}
733 733
 			foreach ($fullCaseRow as $key=>$value) {
734
-				$row[$keysStandardCased[$key]]=$value;
734
+				$row[$keysStandardCased[$key]] = $value;
735 735
 			}
736 736
 			$pk_table = $this->primary_keys[$table_name];
737
-			if (count($pk_table)==1)
737
+			if (count($pk_table) == 1)
738 738
 			{
739 739
 				if (!isset($keysStandardCased[$pk_table[0]])) {
740 740
 					throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '$table_name' table. Could not find primary key in this set of rows. SQL request passed: ".$sql);
@@ -829,14 +829,14 @@  discard block
 block discarded – undo
829 829
 		// Now, let's commit or rollback if needed.
830 830
 		if ($this->dbConnection != null && $this->dbConnection->hasActiveTransaction()) {
831 831
 			if ($this->commitOnQuit) {
832
-				try  {
832
+				try {
833 833
 					$this->dbConnection->commit();
834 834
 				} catch (Exception $e) {
835 835
 					echo $e->getMessage()."<br/>";
836 836
 					echo $e->getTraceAsString();
837 837
 				}
838 838
 			} else {
839
-				try  {
839
+				try {
840 840
 					$this->dbConnection->rollback();
841 841
 				} catch (Exception $e) {
842 842
 					echo $e->getMessage()."<br/>";
@@ -897,21 +897,21 @@  discard block
 block discarded – undo
897 897
 	 * @param string $sql
898 898
 	 * @return array the result of your query
899 899
 	 */
900
-	public function getTransientObjectsFromSQL($sql,$classname=null) {
900
+	public function getTransientObjectsFromSQL($sql, $classname = null) {
901 901
 		if ($this->dbConnection == null) {
902 902
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
903 903
 		}
904
-		return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS,$classname);
904
+		return $this->dbConnection->getAll($sql, \PDO::FETCH_CLASS, $classname);
905 905
 	}
906 906
 
907 907
 
908 908
 	private function to_explain_string($path) {
909 909
 		$msg = '';
910 910
 		foreach ($path as $constraint) {
911
-			if ($constraint['type']=='1*') {
911
+			if ($constraint['type'] == '1*') {
912 912
 				$msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n';
913 913
 			}
914
-			elseif ($constraint['type']=='*1') {
914
+			elseif ($constraint['type'] == '*1') {
915 915
 				$msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n';
916 916
 			}
917 917
 		}
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 		$this->loadCache();
931 931
 
932 932
 		$path = array();
933
-		$queue = array(array($table,array()));
933
+		$queue = array(array($table, array()));
934 934
 
935 935
 		$found = false;
936 936
 		$found_depth = 0;
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 				{
966 966
 					break;
967 967
 				}
968
-				if ($ret==true)
968
+				if ($ret == true)
969 969
 				{
970 970
 					// Ok, we got one, we will continue a bit more until we reach the next level in the tree,
971 971
 					// just to see if there is no ambiguity
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
 				}
976 976
 
977 977
 				// At each iteration, let's check the time.
978
-				if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time > $max_execution_time && $max_execution_time!=0) {
978
+				if ($this->trackExecutionTime && microtime(true)-self::$script_start_up_time>$max_execution_time && $max_execution_time != 0) {
979 979
 					// Call check table names
980 980
 					$this->checkTablesExist($tables);
981 981
 
@@ -986,11 +986,11 @@  discard block
 block discarded – undo
986 986
 			}
987 987
 		}
988 988
 
989
-		$ambiguity =false;
989
+		$ambiguity = false;
990 990
 		$msg = '';
991 991
 		foreach ($tables_paths as $table_path) {
992 992
 			// If any table has not been found, throw an exception
993
-			if (!isset($table_path['founddepth']) || $table_path['founddepth']==null) {
993
+			if (!isset($table_path['founddepth']) || $table_path['founddepth'] == null) {
994 994
 				// First, check if the tables do exist.
995 995
 				$this->checkTablesExist(array($table, $table_path['name']));
996 996
 				// Else, throw an error.
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 						'table2' => $depArr['table1'],
1053 1053
 						'col1' => $depArr['col2'],
1054 1054
 						'col2' => $depArr['col1'],
1055
-						'type' => (($depArr['type'] == '1*')?'*1':'1*')
1055
+						'type' => (($depArr['type'] == '1*') ? '*1' : '1*')
1056 1056
 				);
1057 1057
 			}, $toRevertPath);
1058 1058
 			return array_reverse($invertedDependencies);
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 	 * @param unknown_type $paths
1071 1071
 	 */
1072 1072
 	private function flatten_paths($paths) {
1073
-		$flat_path=array();
1073
+		$flat_path = array();
1074 1074
 		foreach ($paths as $path_bigarray) {
1075 1075
 			$path = $path_bigarray['paths'][0];
1076 1076
 
@@ -1109,9 +1109,9 @@  discard block
 block discarded – undo
1109 1109
 		$path = $current_vars[1];
1110 1110
 
1111 1111
 		foreach ($target_tables as $id=>$target_table) {
1112
-			if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth']==null || $target_table['founddepth']==count($path))) {
1112
+			if ($target_table['name'] == $current_table && (!isset($target_table['founddepth']) || $target_table['founddepth'] == null || $target_table['founddepth'] == count($path))) {
1113 1113
 				// When a path is found to a table, we mark the table as found with its depth.
1114
-				$target_tables[$id]['founddepth']=count($path);
1114
+				$target_tables[$id]['founddepth'] = count($path);
1115 1115
 
1116 1116
 				// Then we add the path to table to the target_tables array
1117 1117
 				$target_tables[$id]['paths'][] = $path;
@@ -1142,12 +1142,12 @@  discard block
 block discarded – undo
1142 1142
 			$already_done = false;
1143 1143
 			foreach ($path as $previous_constraint)
1144 1144
 			{
1145
-				if ($previous_constraint['type']=='1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"])
1145
+				if ($previous_constraint['type'] == '1*' && $current_table == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"] && $table1 == $previous_constraint["table1"] && $col1 == $previous_constraint["col1"])
1146 1146
 				{
1147 1147
 					$already_done = true;
1148 1148
 					break;
1149 1149
 				}
1150
-				elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"])
1150
+				elseif ($previous_constraint['type'] == '*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"])
1151 1151
 				{
1152 1152
 					$already_done = true;
1153 1153
 					break;
@@ -1175,12 +1175,12 @@  discard block
 block discarded – undo
1175 1175
 			$already_done = false;
1176 1176
 			foreach ($path as $previous_constraint)
1177 1177
 			{
1178
-				if ($previous_constraint['type']=='1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"])
1178
+				if ($previous_constraint['type'] == '1*' && $table2 == $previous_constraint["table2"] && $col2 == $previous_constraint["col2"])
1179 1179
 				{
1180 1180
 					$already_done = true;
1181 1181
 					break;
1182 1182
 				}
1183
-				elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"])
1183
+				elseif ($previous_constraint['type'] == '*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"])
1184 1184
 				{
1185 1185
 					$already_done = true;
1186 1186
 					break;
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
 	 * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null).
1290 1290
 	 * @return TDBMObjectArray A TDBMObjectArray containing the resulting objects of the query.
1291 1291
 	 */
1292
-	public function getObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) {
1292
+	public function getObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) {
1293 1293
 		if ($this->dbConnection == null) {
1294 1294
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
1295 1295
 		}
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 	 * @param unknown_type $hint_path
1306 1306
 	 * @return integer
1307 1307
 	 */
1308
-	public function getCount($table_name, $filter_bag=null, $hint_path=null) {
1308
+	public function getCount($table_name, $filter_bag = null, $hint_path = null) {
1309 1309
 		if ($this->dbConnection == null) {
1310 1310
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
1311 1311
 		}
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
 	 * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null).
1324 1324
 	 * @return string The SQL that would be executed.
1325 1325
 	 */
1326
-	public function explainSQLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) 	{
1326
+	public function explainSQLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) {
1327 1327
 		if ($this->dbConnection == null) {
1328 1328
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
1329 1329
 		}
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	 * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null).
1342 1342
 	 * @return string The SQL that would be executed.
1343 1343
 	 */
1344
-	public function explainRequestAsTextGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null) 	{
1344
+	public function explainRequestAsTextGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null) {
1345 1345
 		if ($this->dbConnection == null) {
1346 1346
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
1347 1347
 		}
@@ -1362,12 +1362,12 @@  discard block
 block discarded – undo
1362 1362
 	 * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null).
1363 1363
 	 * @return string The SQL that would be executed.
1364 1364
 	 */
1365
-	public function explainRequestAsHTMLGetObjects($table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $hint_path=null, $x=10, $y=10) 	{
1365
+	public function explainRequestAsHTMLGetObjects($table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $hint_path = null, $x = 10, $y = 10) {
1366 1366
 		if ($this->dbConnection == null) {
1367 1367
 			throw new TDBMException("Error while calling TDBMObject::getObject(): No connection has been established on the database!");
1368 1368
 		}
1369 1369
 		$tree = $this->getObjectsByMode('explainTree', $table_name, $filter_bag, $orderby_bag, $from, $limit, $hint_path);
1370
-		return $this->drawTree($tree,$x,$y);
1370
+		return $this->drawTree($tree, $x, $y);
1371 1371
 	}
1372 1372
 
1373 1373
 	/**
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
 	 * @param unknown_type $hint_path Hints to get the path for the query (expert parameter, you should leave it to null).
1385 1385
 	 * @return array|Generator|TDBMObjectArray|int An array or object containing the resulting objects of the query.
1386 1386
 	 */
1387
-	public function getObjectsByMode($mode, $table_name, $filter_bag=null, $orderby_bag=null, $from=null, $limit=null, $className=null, $hint_path=null) {
1387
+	public function getObjectsByMode($mode, $table_name, $filter_bag = null, $orderby_bag = null, $from = null, $limit = null, $className = null, $hint_path = null) {
1388 1388
 		$this->completeSave();
1389 1389
 		$this->loadCache();
1390 1390
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 			}
1424 1424
 		}
1425 1425
 
1426
-		if (count($needed_table_array)==0)
1426
+		if (count($needed_table_array) == 0)
1427 1427
 		{
1428 1428
 			$sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem)
1429 1429
 
@@ -1431,14 +1431,14 @@  discard block
 block discarded – undo
1431 1431
 			throw new TDBMException("TODO: explainTree not implemented for only one table.");
1432 1432
 		}
1433 1433
 		else {
1434
-			if ($hint_path!=null && $mode != 'explainTree')
1434
+			if ($hint_path != null && $mode != 'explainTree')
1435 1435
 			{
1436 1436
 				$path = $hint_path;
1437 1437
 				$flat_path = $this->flatten_paths($path);
1438 1438
 			}
1439 1439
 			else
1440 1440
 			{
1441
-				$full_paths = $this->static_find_paths($table_name,$needed_table_array);
1441
+				$full_paths = $this->static_find_paths($table_name, $needed_table_array);
1442 1442
 
1443 1443
 				if ($mode == 'explainTree') {
1444 1444
 					return $this->getTablePathsTree($full_paths);
@@ -1481,7 +1481,7 @@  discard block
 block discarded – undo
1481 1481
 			*/
1482 1482
 			$is_ok = true;
1483 1483
 			foreach ($path as $step) {
1484
-				if ($step["type"]=="1*") {
1484
+				if ($step["type"] == "1*") {
1485 1485
 					$is_ok = false;
1486 1486
 					break;
1487 1487
 				}
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
 				$orderby_columns_array = array_merge($orderby_columns_array, $orderby_object->toSqlStatementsArray());
1507 1507
 			}
1508 1508
 
1509
-			$orderby_statement = ' ORDER BY '.implode(',',$orderby_columns_array);
1509
+			$orderby_statement = ' ORDER BY '.implode(',', $orderby_columns_array);
1510 1510
 			$count = 0;
1511 1511
 			foreach ($orderby_columns_array as $id=>$orderby_statement_phrase) {
1512 1512
 				// Let's remove the trailing ASC or DESC and add AS tdbm_reserved_col_Xxx
@@ -1524,10 +1524,10 @@  discard block
 block discarded – undo
1524 1524
 				$orderby_columns_array[$id] = $orderby_statement_phrase.' AS tdbm_reserved_col_'.$count;
1525 1525
 				$count++;
1526 1526
 			}
1527
-			$orderby_column_statement = ', '.implode(',',$orderby_columns_array);
1527
+			$orderby_column_statement = ', '.implode(',', $orderby_columns_array);
1528 1528
 		}
1529 1529
 
1530
-		if ($mode=="getCount") {
1530
+		if ($mode == "getCount") {
1531 1531
 			// Let's get the list of primary keys to perform a DISTINCT request.
1532 1532
 			$pk_table = $this->getPrimaryKeyStatic($table_name);
1533 1533
 				
@@ -1561,7 +1561,7 @@  discard block
 block discarded – undo
1561 1561
 		if ($mode == 'explainSQL') {
1562 1562
 			return $sql;
1563 1563
 		}
1564
-		return $this->getObjectsFromSQL($table_name, $sql,  $from, $limit, $className);
1564
+		return $this->getObjectsFromSQL($table_name, $sql, $from, $limit, $className);
1565 1565
 
1566 1566
 	}
1567 1567
 
@@ -1586,17 +1586,17 @@  discard block
 block discarded – undo
1586 1586
 		// Second, let's take all the objects out of the filter bag, and let's make filters from them
1587 1587
 		$filter_bag2 = array();
1588 1588
 		foreach ($filter_bag as $thing) {
1589
-			if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) {
1589
+			if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\FilterInterface')) {
1590 1590
 				$filter_bag2[] = $thing;
1591 1591
 			} elseif (is_string($thing)) {
1592 1592
 				$filter_bag2[] = new SqlStringFilter($thing);
1593
-			} elseif (is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) {
1593
+			} elseif (is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && count($thing)>0) {
1594 1594
 				// Get table_name and column_name
1595 1595
 				$filter_table_name = $thing[0]->_getDbTableName();
1596 1596
 				$filter_column_names = $thing[0]->getPrimaryKey();
1597 1597
 
1598 1598
 				// If there is only one primary key, we can use the InFilter
1599
-				if (count($filter_column_names)==1) {
1599
+				if (count($filter_column_names) == 1) {
1600 1600
 					$primary_keys_array = array();
1601 1601
 					$filter_column_name = $filter_column_names[0];
1602 1602
 					foreach ($thing as $TDBMObject) {
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
 				{
1610 1610
 					$filter_bag_and = array();
1611 1611
 					foreach ($thing as $TDBMObject) {
1612
-						$filter_bag_temp_and=array();
1612
+						$filter_bag_temp_and = array();
1613 1613
 						foreach ($filter_column_names as $pk) {
1614 1614
 							$filter_bag_temp_and[] = new EqualFilter($TDBMObject->_getDbTableName(), $pk, $TDBMObject->$pk);
1615 1615
 						}
@@ -1619,7 +1619,7 @@  discard block
 block discarded – undo
1619 1619
 				}
1620 1620
 
1621 1621
 
1622
-			} elseif (!is_a($thing,'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing!==null) {
1622
+			} elseif (!is_a($thing, 'Mouf\\Database\\TDBM\\TDBMObjectArray') && $thing !== null) {
1623 1623
 				throw new TDBMException("Error in filter bag in getObjectsByFilter. An object has been passed that is neither a filter, nor a TDBMObject, nor a TDBMObjectArray, nor a string, nor null.");
1624 1624
 			}
1625 1625
 		}
@@ -1647,9 +1647,9 @@  discard block
 block discarded – undo
1647 1647
 		// 4-2, let's take all the objects out of the orderby bag, and let's make objects from them
1648 1648
 		$orderby_bag2 = array();
1649 1649
 		foreach ($orderby_bag as $thing) {
1650
-			if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) {
1650
+			if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) {
1651 1651
 				$orderby_bag2[] = $thing;
1652
-			} elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) {
1652
+			} elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) {
1653 1653
 				$orderby_bag2[] = $thing;
1654 1654
 			} elseif (is_string($thing)) {
1655 1655
 				$orderby_bag2[] = new OrderBySQLString($thing);
@@ -1672,10 +1672,10 @@  discard block
 block discarded – undo
1672 1672
 			$possible_tables = $this->dbConnection->checkTableExist($table);
1673 1673
 			if ($possible_tables !== true)
1674 1674
 			{
1675
-				if (count($possible_tables)==1)
1675
+				if (count($possible_tables) == 1)
1676 1676
 				$str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'";
1677 1677
 				else
1678
-				$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'";
1678
+				$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $possible_tables)."'";
1679 1679
 				throw new TDBMException($str);
1680 1680
 			}
1681 1681
 		}
@@ -1698,16 +1698,16 @@  discard block
 block discarded – undo
1698 1698
 			$current_node = $tree;
1699 1699
 			$found = true;
1700 1700
 			foreach ($path as $link) {
1701
-				if ($found==true)
1701
+				if ($found == true)
1702 1702
 				{
1703 1703
 					if (is_array($current_node->getChildren()))
1704 1704
 					{
1705 1705
 						foreach ($current_node->getChildren() as $child)
1706 1706
 						{
1707
-							if ($link['table1']==$child->table_name &&
1708
-							$link['col1']==$child->keyNode &&
1709
-							$link['col2']==$child->keyParent &&
1710
-							$link['type']==$child->link_type) {
1707
+							if ($link['table1'] == $child->table_name &&
1708
+							$link['col1'] == $child->keyNode &&
1709
+							$link['col2'] == $child->keyParent &&
1710
+							$link['type'] == $child->link_type) {
1711 1711
 								$current_node = $child;
1712 1712
 							}
1713 1713
 							else
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
 
1723 1723
 				}
1724 1724
 
1725
-				if ($found==false)
1725
+				if ($found == false)
1726 1726
 				{
1727 1727
 					$current_node = new DisplayNode($link['table1'], $current_node, $link['type'], $link['col2'], $link['col1']);
1728 1728
 				}
@@ -1747,7 +1747,7 @@  discard block
 block discarded – undo
1747 1747
      *
1748 1748
      * @return string
1749 1749
 	 */
1750
-	public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) {
1750
+	public function drawTree($tree, $x, $y, &$ret_width = 0, &$ret_height = 0) {
1751 1751
 
1752 1752
 		// Let's get the background div:
1753 1753
 		$treeDepth = $tree->computeDepth(1)-1;
@@ -1758,7 +1758,7 @@  discard block
 block discarded – undo
1758 1758
 
1759 1759
 		$str = "<div style='position:absolute; left:".($x+DisplayNode::$left_start-DisplayNode::$border)."px; top:".($y+DisplayNode::$top_start-DisplayNode::$border)."px; width:".$ret_width."px; height:".$ret_height."; background-color:#EEEEEE; color: white; text-align:center;'></div>";
1760 1760
 
1761
-		$str .= $tree->draw(0,0, $x, $y);
1761
+		$str .= $tree->draw(0, 0, $x, $y);
1762 1762
 
1763 1763
 		return $str;
1764 1764
 	}
@@ -1793,10 +1793,10 @@  discard block
 block discarded – undo
1793 1793
 				if ($tables === true)
1794 1794
 				throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table.");
1795 1795
 				elseif ($tables !== null) {
1796
-					if (count($tables)==1)
1796
+					if (count($tables) == 1)
1797 1797
 					$str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'";
1798 1798
 					else
1799
-					$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'";
1799
+					$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '", $tables)."'";
1800 1800
 					throw new TDBMException($str);
1801 1801
 				}
1802 1802
 			}
Please login to merge, or discard this patch.
Braces   +60 added lines, -57 removed lines patch added patch discarded remove patch
@@ -456,10 +456,11 @@  discard block
 block discarded – undo
456 456
 			/*$data =*/ $this->dbConnection->getTableInfo($table_name);
457 457
 		} catch (TDBMException $exception) {
458 458
 			$probable_table_name = $this->dbConnection->checkTableExist($table_name);
459
-			if ($probable_table_name == null)
460
-			throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist.");
461
-			else
462
-			throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'.");
459
+			if ($probable_table_name == null) {
460
+						throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist.");
461
+			} else {
462
+						throw new TDBMException("Error while calling TDBMObject::getNewObject(): The table named '$table_name' does not exist. Maybe you meant the table '$probable_table_name'.");
463
+			}
463 464
 		}
464 465
 
465 466
 		if ($className === null) {
@@ -537,8 +538,9 @@  discard block
 block discarded – undo
537 538
 			$sql = 'DELETE FROM '.$this->dbConnection->escapeDBItem($object->_getDbTableName()).' WHERE '.$sql_where;
538 539
 			$result = $this->dbConnection->exec($sql);
539 540
 
540
-			if ($result != 1)
541
-			throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected.");
541
+			if ($result != 1) {
542
+						throw new TDBMException("Error while deleting object from table ".$object->_getDbTableName().": ".$result." have been affected.");
543
+			}
542 544
 
543 545
 			$this->objectStorage->remove($object->_getDbTableName(), $object_id);
544 546
 			$object->setTDBMObjectState("deleted");
@@ -665,8 +667,7 @@  discard block
 block discarded – undo
665 667
 						throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '$table_name' table. Could not find primary key in this set of rows. SQL request passed: ".$sql);
666 668
 					}
667 669
 					$id = $row[$keysStandardCased[$pk_table[0]]];
668
-				}
669
-				else
670
+				} else
670 671
 				{
671 672
 					// Let's generate the serialized primary key from the columns!
672 673
 					$ids = array();
@@ -740,8 +741,7 @@  discard block
 block discarded – undo
740 741
 					throw new TDBMException("Bad SQL request passed to getObjectsFromSQL. The SQL request should return all the rows from the '$table_name' table. Could not find primary key in this set of rows. SQL request passed: ".$sql);
741 742
 				}
742 743
 				$id = $row[$keysStandardCased[$pk_table[0]]];
743
-			}
744
-			else
744
+			} else
745 745
 			{
746 746
 				// Let's generate the serialized primary key from the columns!
747 747
 				$ids = array();
@@ -910,8 +910,7 @@  discard block
 block discarded – undo
910 910
 		foreach ($path as $constraint) {
911 911
 			if ($constraint['type']=='1*') {
912 912
 				$msg .= 'Table "'.$constraint['table1'].'" points to "'.$constraint['table2'].'" through its foreign key "'.$constraint['col1'].'"\n';
913
-			}
914
-			elseif ($constraint['type']=='*1') {
913
+			} elseif ($constraint['type']=='*1') {
915 914
 				$msg .= 'Table "'.$constraint['table1'].'" is pointed by "'.$constraint['table2'].'" through its foreign key "'.$constraint['col2'].'"\n';
916 915
 			}
917 916
 		}
@@ -999,8 +998,9 @@  discard block
 block discarded – undo
999 998
 			// If any table has more than 1 way to be reached, throw an exception.
1000 999
 			if (count($table_path['paths'])>1) {
1001 1000
 				// If this is the first ambiguity
1002
-				if (!$ambiguity)
1003
-				$msg .= 'An ambiguity has been found during the search. Please catch this exception and execute the $exception->explainAmbiguity() to get a nice graphical view of what you should do to solve this ambiguity.';
1001
+				if (!$ambiguity) {
1002
+								$msg .= 'An ambiguity has been found during the search. Please catch this exception and execute the $exception->explainAmbiguity() to get a nice graphical view of what you should do to solve this ambiguity.';
1003
+				}
1004 1004
 
1005 1005
 				$msg .= "The table \"".$table_path['name']."\" can be reached using several different ways from the table \"$table\".\n\n";
1006 1006
 				$count = 0;
@@ -1041,8 +1041,7 @@  discard block
 block discarded – undo
1041 1041
 		if (isset($this->cache['paths'][$table1][$table2]))
1042 1042
 		{
1043 1043
 			return $this->cache['paths'][$table1][$table2];
1044
-		}
1045
-		elseif (isset($this->cache['paths'][$table2][$table1]))
1044
+		} elseif (isset($this->cache['paths'][$table2][$table1]))
1046 1045
 		{
1047 1046
 			// Let's revert the path!
1048 1047
 			$toRevertPath = $this->cache['paths'][$table2][$table1];
@@ -1087,8 +1086,9 @@  discard block
 block discarded – undo
1087 1086
 						break;
1088 1087
 					}
1089 1088
 				}
1090
-				if (!$found)
1091
-				$flat_path[] = $path_step;
1089
+				if (!$found) {
1090
+								$flat_path[] = $path_step;
1091
+				}
1092 1092
 			}
1093 1093
 		}
1094 1094
 		return $flat_path;
@@ -1123,8 +1123,9 @@  discard block
 block discarded – undo
1123 1123
 					}
1124 1124
 				}
1125 1125
 
1126
-				if ($found)
1127
-				return true;
1126
+				if ($found) {
1127
+								return true;
1128
+				}
1128 1129
 			}
1129 1130
 
1130 1131
 		}
@@ -1146,15 +1147,15 @@  discard block
 block discarded – undo
1146 1147
 				{
1147 1148
 					$already_done = true;
1148 1149
 					break;
1149
-				}
1150
-				elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"])
1150
+				} elseif ($previous_constraint['type']=='*1' && $current_table == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"] && $table1 == $previous_constraint["table2"] && $col1 == $previous_constraint["col2"])
1151 1151
 				{
1152 1152
 					$already_done = true;
1153 1153
 					break;
1154 1154
 				}
1155 1155
 			}
1156
-			if ($already_done)
1157
-			continue;
1156
+			if ($already_done) {
1157
+						continue;
1158
+			}
1158 1159
 
1159 1160
 			$new_path = array_merge($path, array(array("table1"=>$table1,
1160 1161
 									"col1"=>$col1,
@@ -1179,15 +1180,15 @@  discard block
 block discarded – undo
1179 1180
 				{
1180 1181
 					$already_done = true;
1181 1182
 					break;
1182
-				}
1183
-				elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"])
1183
+				} elseif ($previous_constraint['type']=='*1' && $table2 == $previous_constraint["table1"] && $col2 == $previous_constraint["col1"])
1184 1184
 				{
1185 1185
 					$already_done = true;
1186 1186
 					break;
1187 1187
 				}
1188 1188
 			}
1189
-			if ($already_done)
1190
-			continue;
1189
+			if ($already_done) {
1190
+						continue;
1191
+			}
1191 1192
 
1192 1193
 			$new_path = array_merge($path, array(array("table1"=>$table2,
1193 1194
 									"col1"=>$col2,
@@ -1427,16 +1428,15 @@  discard block
 block discarded – undo
1427 1428
 		{
1428 1429
 			$sql = $this->dbConnection->escapeDBItem($table_name); //Make by Pierre PIV (add escapeDBItem)
1429 1430
 
1430
-			if ($mode == 'explainTree')
1431
-			throw new TDBMException("TODO: explainTree not implemented for only one table.");
1432
-		}
1433
-		else {
1431
+			if ($mode == 'explainTree') {
1432
+						throw new TDBMException("TODO: explainTree not implemented for only one table.");
1433
+			}
1434
+		} else {
1434 1435
 			if ($hint_path!=null && $mode != 'explainTree')
1435 1436
 			{
1436 1437
 				$path = $hint_path;
1437 1438
 				$flat_path = $this->flatten_paths($path);
1438
-			}
1439
-			else
1439
+			} else
1440 1440
 			{
1441 1441
 				$full_paths = $this->static_find_paths($table_name,$needed_table_array);
1442 1442
 
@@ -1540,8 +1540,9 @@  discard block
 block discarded – undo
1540 1540
 			$sql = "SELECT COUNT(DISTINCT $pk_str) FROM $sql";
1541 1541
 
1542 1542
 			$where_clause = $filter->toSql($this->dbConnection);
1543
-			if ($where_clause != '')
1544
-			$sql .= ' WHERE '.$where_clause;
1543
+			if ($where_clause != '') {
1544
+						$sql .= ' WHERE '.$where_clause;
1545
+			}
1545 1546
 
1546 1547
 			// Now, let's perform the request:
1547 1548
 			$result = $this->dbConnection->getOne($sql, array());
@@ -1552,8 +1553,9 @@  discard block
 block discarded – undo
1552 1553
 		$sql = "SELECT DISTINCT ".$this->dbConnection->escapeDBItem($table_name).".* $orderby_column_statement FROM $sql";
1553 1554
 
1554 1555
 		$where_clause = $filter->toSql($this->dbConnection);
1555
-		if ($where_clause != '')
1556
-		$sql .= ' WHERE '.$where_clause;
1556
+		if ($where_clause != '') {
1557
+				$sql .= ' WHERE '.$where_clause;
1558
+		}
1557 1559
 
1558 1560
 		$sql .= $orderby_statement;
1559 1561
 
@@ -1578,8 +1580,7 @@  discard block
 block discarded – undo
1578 1580
 			$filter_bag = array();
1579 1581
 		} elseif (!is_array($filter_bag)) {
1580 1582
 			$filter_bag = array($filter_bag);
1581
-		}
1582
-		elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) {
1583
+		} elseif (is_a($filter_bag, 'Mouf\\Database\\TDBM\\TDBMObjectArray')) {
1583 1584
 			$filter_bag = array($filter_bag);
1584 1585
 		}
1585 1586
 
@@ -1641,8 +1642,9 @@  discard block
 block discarded – undo
1641 1642
 		// Fourth, let's apply the same steps to the orderby_bag
1642 1643
 		// 4-1 orderby_bag should be an array, if it is a singleton, let's put it in an array.
1643 1644
 
1644
-		if (!is_array($orderby_bag))
1645
-		$orderby_bag = array($orderby_bag);
1645
+		if (!is_array($orderby_bag)) {
1646
+				$orderby_bag = array($orderby_bag);
1647
+		}
1646 1648
 
1647 1649
 		// 4-2, let's take all the objects out of the orderby bag, and let's make objects from them
1648 1650
 		$orderby_bag2 = array();
@@ -1672,10 +1674,11 @@  discard block
 block discarded – undo
1672 1674
 			$possible_tables = $this->dbConnection->checkTableExist($table);
1673 1675
 			if ($possible_tables !== true)
1674 1676
 			{
1675
-				if (count($possible_tables)==1)
1676
-				$str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'";
1677
-				else
1678
-				$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'";
1677
+				if (count($possible_tables)==1) {
1678
+								$str = "Could not find table '$table'. Maybe you meant this table: '".$possible_tables[0]."'";
1679
+				} else {
1680
+								$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$possible_tables)."'";
1681
+				}
1679 1682
 				throw new TDBMException($str);
1680 1683
 			}
1681 1684
 		}
@@ -1709,16 +1712,15 @@  discard block
 block discarded – undo
1709 1712
 							$link['col2']==$child->keyParent &&
1710 1713
 							$link['type']==$child->link_type) {
1711 1714
 								$current_node = $child;
1712
-							}
1713
-							else
1715
+							} else
1714 1716
 							{
1715 1717
 								// Now, we must add the rest of the links to the tree.
1716 1718
 								$found = false;
1717 1719
 							}
1718 1720
 						}
1721
+					} else {
1722
+										$found = false;
1719 1723
 					}
1720
-					else
1721
-					$found = false;
1722 1724
 
1723 1725
 				}
1724 1726
 
@@ -1790,13 +1792,14 @@  discard block
 block discarded – undo
1790 1792
 				// Unable to find primary key.... this is an error
1791 1793
 				// Let's try to be precise in error reporting. Let's try to find the table.
1792 1794
 				$tables = $this->dbConnection->checkTableExist($table);
1793
-				if ($tables === true)
1794
-				throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table.");
1795
-				elseif ($tables !== null) {
1796
-					if (count($tables)==1)
1797
-					$str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'";
1798
-					else
1799
-					$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'";
1795
+				if ($tables === true) {
1796
+								throw new TDBMException("Could not find table primary key for table '$table'. Please define a primary key for this table.");
1797
+				} elseif ($tables !== null) {
1798
+					if (count($tables)==1) {
1799
+										$str = "Could not find table '$table'. Maybe you meant this table: '".$tables[0]."'";
1800
+					} else {
1801
+										$str = "Could not find table '$table'. Maybe you meant one of those tables: '".implode("', '",$tables)."'";
1802
+					}
1800 1803
 					throw new TDBMException($str);
1801 1804
 				}
1802 1805
 			}
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Utils/TDBMDaoGenerator.php 4 patches
Doc Comments   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @param bool $support If the generated daos should keep support for old functions (eg : getUserList and getList)
57 57
 	 * @param bool $storeInUtc If the generated daos should store the date in UTC timezone instead of user's timezone.
58 58
 	 * @param bool $castDatesToDateTime Whether dates are converted to DateTimeImmutable or to timestamp
59
-	 * @return \string[] the list of tables
59
+	 * @return string[] the list of tables
60 60
 	 * @throws TDBMException
61 61
 	 */
62 62
 	public function generateAllDaosAndBeans($daoFactoryClassName, $daonamespace, $beannamespace, $support, $storeInUtc, $castDatesToDateTime) {
@@ -84,7 +84,12 @@  discard block
 block discarded – undo
84 84
 	/**
85 85
 	 * Generates in one method call the daos and the beans for one table.
86 86
 	 * 
87
-	 * @param $tableName
87
+	 * @param string $tableName
88
+	 * @param string $daonamespace
89
+	 * @param string $beannamespace
90
+	 * @param boolean $support
91
+	 * @param boolean $storeInUtc
92
+	 * @param boolean $castDatesToDateTime
88 93
 	 */
89 94
 	public function generateDaoAndBean($tableName, $daonamespace, $beannamespace, ClassNameMapper $classNameMapper, $support, $storeInUtc, $castDatesToDateTime) {
90 95
 		$daoName = $this->getDaoNameFromTableName($tableName);
@@ -412,9 +417,10 @@  discard block
 block discarded – undo
412 417
 	/**
413 418
 	 * Writes the PHP bean DAO with simple functions to create/get/save objects.
414 419
 	 *
415
-	 * @param string $fileName The file that will be written (without the directory)
416 420
 	 * @param string $className The name of the class
417 421
 	 * @param string $tableName The name of the table
422
+	 * @param string $baseClassName
423
+	 * @param string $beanClassName
418 424
 	 */
419 425
 	public function generateDao($className, $baseClassName, $beanClassName, $tableName, ClassNameMapper $classNameMapper, $support) {
420 426
 		$info = $this->dbConnection->getTableInfo($tableName);
@@ -702,7 +708,9 @@  discard block
 block discarded – undo
702 708
 	/**
703 709
 	 * Generates the factory bean.
704 710
 	 * 
705
-	 * @param $tableList
711
+	 * @param string[] $tableList
712
+	 * @param string $daoFactoryClassName
713
+	 * @param string $daoNamespace
706 714
 	 */
707 715
 	private function generateFactory($tableList, $daoFactoryClassName, $daoNamespace, ClassNameMapper $classNameMapper) {
708 716
 		// For each table, let's write a property.
@@ -774,7 +782,6 @@  discard block
 block discarded – undo
774 782
 	 * Transforms the property name in a setter name.
775 783
 	 * For instance, phone => getPhone or name => getName
776 784
 	 *
777
-	 * @param string $methodName
778 785
 	 * @return string
779 786
 	 */
780 787
 	public static function getSetterNameForPropertyName($propertyName) {
@@ -854,7 +861,7 @@  discard block
 block discarded – undo
854 861
 	 * Tries to put string to the singular form (if it is plural).
855 862
 	 * Obviously, this can't be perfect, be we do the best we can.
856 863
 	 * 
857
-	 * @param $str string
864
+	 * @param string $str string
858 865
 	 * @return string
859 866
 	 */
860 867
 	public static function toSingular($str) {
@@ -875,7 +882,7 @@  discard block
 block discarded – undo
875 882
 	 * Put the first letter of the string in lower case.
876 883
 	 * Very useful to transform a class name into a variable name.
877 884
 	 * 
878
-	 * @param $str string
885
+	 * @param string $str string
879 886
 	 * @return string
880 887
 	 */
881 888
 	public static function toVariableName($str) {
Please login to merge, or discard this patch.
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function generateAllDaosAndBeans($daoFactoryClassName, $daonamespace, $beannamespace, $support, $storeInUtc, $castDatesToDateTime) {
63 63
 		// TODO: migrate $this->daoNamespace to $daonamespace that is passed in parameter!
64
-        $classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.'composer.json');
64
+		$classNameMapper = ClassNameMapper::createFromComposerFile($this->rootPath.'composer.json');
65 65
 
66 66
 		$this->daoNamespace = $daonamespace;
67 67
 		$this->beanNamespace = $beannamespace;
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 		$beanName = $this->getBeanNameFromTableName($tableName);
92 92
 		$baseBeanName = $this->getBaseBeanNameFromTableName($tableName);
93 93
 
94
-        $connection = $this->dbConnection;
95
-        if ($connection instanceof CachedConnection){
96
-            $connection->cacheService->purgeAll();
97
-        }
94
+		$connection = $this->dbConnection;
95
+		if ($connection instanceof CachedConnection){
96
+			$connection->cacheService->purgeAll();
97
+		}
98 98
 		
99 99
 		$this->generateBean($beanName, $baseBeanName, $tableName, $beannamespace, $classNameMapper, $storeInUtc, $castDatesToDateTime);
100 100
 		$this->generateDao($daoName, $daoName."Base", $beanName, $tableName, $classNameMapper, $support);
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
 		return TDBMDaoGenerator::toSingular(TDBMDaoGenerator::toCamelCase($tableName))."BaseBean";
131 131
 	}
132 132
 
133
-    /**
134
-     * Writes the PHP bean file with all getters and setters from the table passed in parameter.
135
-     *
136
-     * @param string $className The name of the class
137
-     * @param string $baseClassName The name of the base class which will be extended (name only, no directory)
138
-     * @param string $tableName The name of the table
139
-     * @param string $beannamespace The namespace of the bean
140
-     * @param ClassNameMapper $classNameMapper
141
-     * @throws TDBMException
142
-     */
133
+	/**
134
+	 * Writes the PHP bean file with all getters and setters from the table passed in parameter.
135
+	 *
136
+	 * @param string $className The name of the class
137
+	 * @param string $baseClassName The name of the base class which will be extended (name only, no directory)
138
+	 * @param string $tableName The name of the table
139
+	 * @param string $beannamespace The namespace of the bean
140
+	 * @param ClassNameMapper $classNameMapper
141
+	 * @throws TDBMException
142
+	 */
143 143
 	public function generateBean($className, $baseClassName, $tableName, $beannamespace, ClassNameMapper $classNameMapper, $storeInUtc, $castDatesToDateTime) {
144 144
 		$table = $this->dbConnection->getTableFromDbModel($tableName);
145 145
 
@@ -367,25 +367,25 @@  discard block
 block discarded – undo
367 367
 		$str .= "}
368 368
 ?>";
369 369
 
370
-        $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$baseClassName);
371
-        if (!$possibleBaseFileNames) {
372
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$baseClassName.'" is not autoloadable.');
373
-        }
374
-        $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
370
+		$possibleBaseFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$baseClassName);
371
+		if (!$possibleBaseFileNames) {
372
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$baseClassName.'" is not autoloadable.');
373
+		}
374
+		$possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
375 375
 
376
-        $this->ensureDirectoryExist($possibleBaseFileName);
376
+		$this->ensureDirectoryExist($possibleBaseFileName);
377 377
 		file_put_contents($possibleBaseFileName, $str);
378 378
 		@chmod($possibleBaseFileName, 0664);
379 379
 
380 380
 
381 381
 
382
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$className);
383
-        if (!$possibleFileNames) {
384
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$className.'" is not autoloadable.');
385
-        }
386
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
382
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($beannamespace."\\".$className);
383
+		if (!$possibleFileNames) {
384
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$beannamespace."\\".$className.'" is not autoloadable.');
385
+		}
386
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
387 387
 
388
-        if (!file_exists($possibleFileName)) {
388
+		if (!file_exists($possibleFileName)) {
389 389
 			$str = "<?php
390 390
 /*
391 391
  * This file has been automatically generated by TDBM.
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 {
404 404
 
405 405
 }";
406
-            $this->ensureDirectoryExist($possibleFileName);
406
+			$this->ensureDirectoryExist($possibleFileName);
407 407
 			file_put_contents($possibleFileName ,$str);
408 408
 			@chmod($possibleFileName, 0664);
409 409
 		}
@@ -659,21 +659,21 @@  discard block
 block discarded – undo
659 659
 }
660 660
 ?>";
661 661
 
662
-        $possibleBaseFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$baseClassName);
663
-        if (!$possibleBaseFileNames) {
664
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$baseClassName.'" is not autoloadable.');
665
-        }
666
-        $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
662
+		$possibleBaseFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$baseClassName);
663
+		if (!$possibleBaseFileNames) {
664
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$baseClassName.'" is not autoloadable.');
665
+		}
666
+		$possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
667 667
 
668
-        $this->ensureDirectoryExist($possibleBaseFileName);
668
+		$this->ensureDirectoryExist($possibleBaseFileName);
669 669
 		file_put_contents($possibleBaseFileName ,$str);
670 670
 		@chmod($possibleBaseFileName, 0664);
671 671
 
672
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className);
673
-        if (!$possibleFileNames) {
674
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$className.'" is not autoloadable.');
675
-        }
676
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
672
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className);
673
+		if (!$possibleFileNames) {
674
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$className.'" is not autoloadable.');
675
+		}
676
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
677 677
 		
678 678
 		// Now, let's generate the "editable" class
679 679
 		if (!file_exists($possibleFileName)) {
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 {
694 694
 
695 695
 }";
696
-            $this->ensureDirectoryExist($possibleFileName);
696
+			$this->ensureDirectoryExist($possibleFileName);
697 697
 			file_put_contents($possibleFileName ,$str);
698 698
 			@chmod($possibleFileName, 0664);
699 699
 		}
@@ -760,13 +760,13 @@  discard block
 block discarded – undo
760 760
 }
761 761
 ?>';
762 762
 
763
-        $possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace."\\".$daoFactoryClassName);
764
-        if (!$possibleFileNames) {
765
-            throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace."\\".$daoFactoryClassName.'" is not autoloadable.');
766
-        }
767
-        $possibleFileName = $this->rootPath.$possibleFileNames[0];
763
+		$possibleFileNames = $classNameMapper->getPossibleFileNames($daoNamespace."\\".$daoFactoryClassName);
764
+		if (!$possibleFileNames) {
765
+			throw new TDBMException('Sorry, autoload namespace issue. The class "'.$daoNamespace."\\".$daoFactoryClassName.'" is not autoloadable.');
766
+		}
767
+		$possibleFileName = $this->rootPath.$possibleFileNames[0];
768 768
 
769
-        $this->ensureDirectoryExist($possibleFileName);
769
+		$this->ensureDirectoryExist($possibleFileName);
770 770
 		file_put_contents($possibleFileName ,$str);
771 771
 	}
772 772
 	
@@ -882,22 +882,22 @@  discard block
 block discarded – undo
882 882
 		return strtolower(substr($str, 0, 1)).substr($str, 1);
883 883
 	}
884 884
 
885
-    /**
886
-     * Ensures the file passed in parameter can be written in its directory.
887
-     * @param string $fileName
888
-     */
889
-    private function ensureDirectoryExist($fileName) {
890
-        $dirName = dirname($fileName);
891
-        if (!file_exists($dirName)) {
892
-            $old = umask(0);
893
-            $result = mkdir($dirName, 0775, true);
894
-            umask($old);
895
-            if ($result == false) {
896
-                echo "Unable to create directory: ".$dirName.".";
897
-                exit;
898
-            }
899
-        }
900
-    }
885
+	/**
886
+	 * Ensures the file passed in parameter can be written in its directory.
887
+	 * @param string $fileName
888
+	 */
889
+	private function ensureDirectoryExist($fileName) {
890
+		$dirName = dirname($fileName);
891
+		if (!file_exists($dirName)) {
892
+			$old = umask(0);
893
+			$result = mkdir($dirName, 0775, true);
894
+			umask($old);
895
+			if ($result == false) {
896
+				echo "Unable to create directory: ".$dirName.".";
897
+				exit;
898
+			}
899
+		}
900
+	}
901 901
 
902 902
 	/**
903 903
 	 * @param string $rootPath
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		$baseBeanName = $this->getBaseBeanNameFromTableName($tableName);
93 93
 
94 94
         $connection = $this->dbConnection;
95
-        if ($connection instanceof CachedConnection){
95
+        if ($connection instanceof CachedConnection) {
96 96
             $connection->cacheService->purgeAll();
97 97
         }
98 98
 		
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @dbType '.$normalizedType.'
185 185
 	 * @dbColumn '.$column->name.'
186
-	 * @return '.($castDatesToDateTime?'\\DateTimeImmutable|null':'timestamp|null').'
186
+	 * @return '.($castDatesToDateTime ? '\\DateTimeImmutable|null' : 'timestamp|null').'
187 187
 	 */
188 188
 	public function '.$columnGetterName.'() {
189 189
 		$date = $this->__get(\''.$column->name.'\');
190 190
 		if($date === null) {
191 191
 			return null;
192 192
 		} else {
193
-			return '.($castDatesToDateTime?'new \\DateTimeImmutable':'strtotime').'($date'.($storeInUtc?'.\' UTC\'':'').');
193
+			return '.($castDatesToDateTime ? 'new \\DateTimeImmutable' : 'strtotime').'($date'.($storeInUtc ? '.\' UTC\'' : '').');
194 194
 		}
195 195
 	}
196 196
 	
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
 	 * It must be provided as a PHP timestamp.
200 200
 	 *
201 201
 	 * @dbColumn '.$column->name.'
202
-	 * @param '.($castDatesToDateTime?'\\DateTimeImmutable|null':'timestamp|null').' $'.$column->name.'
202
+	 * @param '.($castDatesToDateTime ? '\\DateTimeImmutable|null' : 'timestamp|null').' $'.$column->name.'
203 203
 	 */
204
-	public function '.$columnSetterName.'('.($castDatesToDateTime?'\\DateTimeImmutable ':'').'$'.$column->name.') {
204
+	public function '.$columnSetterName.'('.($castDatesToDateTime ? '\\DateTimeImmutable ' : '').'$'.$column->name.') {
205 205
 		if($'.$column->name.' === null) {
206 206
 			$this->__set(\''.$column->name.'\', null);
207 207
 		} else {';
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 		
313 313
 		// Now, let's implement the shortcuts to the getter of objects.
314 314
 		// Shortcuts are used to save typing. They are available only if a referenced table is referenced only once by our tables.
315
-		foreach($referencedTablesList as $referrencedTable=>$number) {
315
+		foreach ($referencedTablesList as $referrencedTable=>$number) {
316 316
 			if ($number == 1) {
317 317
 				foreach ($constraints as $array) {
318
-					if ($array['table2'] ==$referrencedTable) {
318
+					if ($array['table2'] == $referrencedTable) {
319 319
 						$columnName = $array['col1'];
320 320
 						$targetColumnName = $array['col2'];
321 321
 						break;
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 
405 405
 }";
406 406
             $this->ensureDirectoryExist($possibleFileName);
407
-			file_put_contents($possibleFileName ,$str);
407
+			file_put_contents($possibleFileName, $str);
408 408
 			@chmod($possibleFileName, 0664);
409 409
 		}
410 410
 	}
@@ -422,11 +422,11 @@  discard block
 block discarded – undo
422 422
 		foreach ($info as $index => $data) {
423 423
 			$comments = $data['column_comment'];
424 424
 			$matches = array();
425
-			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0){
425
+			if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) {
426 426
 				$defaultSort = $data['column_name'];
427
-				if (count($matches == 3)){
427
+				if (count($matches == 3)) {
428 428
 					$defaultSortDirection = $matches[2];
429
-				}else{
429
+				} else {
430 430
 					$defaultSortDirection = 'ASC';
431 431
 				}
432 432
 			}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
         $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0];
667 667
 
668 668
         $this->ensureDirectoryExist($possibleBaseFileName);
669
-		file_put_contents($possibleBaseFileName ,$str);
669
+		file_put_contents($possibleBaseFileName, $str);
670 670
 		@chmod($possibleBaseFileName, 0664);
671 671
 
672 672
         $possibleFileNames = $classNameMapper->getPossibleFileNames($this->daoNamespace."\\".$className);
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 
695 695
 }";
696 696
             $this->ensureDirectoryExist($possibleFileName);
697
-			file_put_contents($possibleFileName ,$str);
697
+			file_put_contents($possibleFileName, $str);
698 698
 			@chmod($possibleFileName, 0664);
699 699
 		}
700 700
 	}
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         $possibleFileName = $this->rootPath.$possibleFileNames[0];
768 768
 
769 769
         $this->ensureDirectoryExist($possibleFileName);
770
-		file_put_contents($possibleFileName ,$str);
770
+		file_put_contents($possibleFileName, $str);
771 771
 	}
772 772
 	
773 773
 	/**
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 	 * @return string
835 835
 	 */
836 836
 	public static function toCamelCase($str) {
837
-		$str = strtoupper(substr($str,0,1)).substr($str,1);
837
+		$str = strtoupper(substr($str, 0, 1)).substr($str, 1);
838 838
 		while (true) {
839 839
 			if (strpos($str, "_") === false && strpos($str, " ") === false)
840 840
 				break;
@@ -843,9 +843,9 @@  discard block
 block discarded – undo
843 843
 			if ($pos === false) {
844 844
 				$pos = strpos($str, " ");
845 845
 			}
846
-			$before = substr($str,0,$pos);
847
-			$after = substr($str,$pos+1);
848
-			$str = $before.strtoupper(substr($after,0,1)).substr($after,1);
846
+			$before = substr($str, 0, $pos);
847
+			$after = substr($str, $pos+1);
848
+			$str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1);
849 849
 		}
850 850
 		return $str;
851 851
 	}
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 				$defaultSort = $data['column_name'];
427 427
 				if (count($matches == 3)){
428 428
 					$defaultSortDirection = $matches[2];
429
-				}else{
429
+				} else{
430 430
 					$defaultSortDirection = 'ASC';
431 431
 				}
432 432
 			}
@@ -836,8 +836,9 @@  discard block
 block discarded – undo
836 836
 	public static function toCamelCase($str) {
837 837
 		$str = strtoupper(substr($str,0,1)).substr($str,1);
838 838
 		while (true) {
839
-			if (strpos($str, "_") === false && strpos($str, " ") === false)
840
-				break;
839
+			if (strpos($str, "_") === false && strpos($str, " ") === false) {
840
+							break;
841
+			}
841 842
 				
842 843
 			$pos = strpos($str, "_");
843 844
 			if ($pos === false) {
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Controllers/TdbmController.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 				
67 67
 		if ($this->daoNamespace == null && $this->beanNamespace == null) {
68
-            $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
68
+			$classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json');
69 69
 
70 70
 			$autoloadNamespaces = $classNameMapper->getManagedNamespaces();
71
-            if ($autoloadNamespaces) {
71
+			if ($autoloadNamespaces) {
72 72
 				$this->autoloadDetected = true;
73 73
 				$rootNamespace = $autoloadNamespaces[0];
74 74
 				$this->daoNamespace = $rootNamespace."Dao";
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		
151 151
 		$tdbmService = new InstanceProxy($name);
152 152
 		/* @var $tdbmService TDBMService */
153
-        $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime);
153
+		$tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime);
154 154
 
155 155
 
156 156
 		$moufManager->declareComponent($daofactoryinstancename, $daonamespace."\\".$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS);
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @Action
43 43
 	 * //@Admin
44 44
 	 */
45
-	public function defaultAction($name, $selfedit="false") {
45
+	public function defaultAction($name, $selfedit = "false") {
46 46
 		$this->initController($name, $selfedit);
47 47
 		
48 48
 		// Fill variables
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @param string $name
94 94
 	 * @param bool $selfedit
95 95
 	 */
96
-	public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 0, $selfedit="false") {
96
+	public function generate($name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 0, $selfedit = "false") {
97 97
 		$this->initController($name, $selfedit);
98 98
 
99 99
 		self::generateDaos($this->moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit, $keepSupport, $storeInUtc, $castDatesToDateTime);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 * @param bool $castDatesToDateTime
117 117
 	 * @throws \Mouf\MoufException
118 118
 	 */
119
-	public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit="false", $keepSupport = null, $storeInUtc = null, $castDatesToDateTime = null) {
119
+	public static function generateDaos(MoufManager $moufManager, $name, $daonamespace, $beannamespace, $daofactoryclassname, $daofactoryinstancename, $selfedit = "false", $keepSupport = null, $storeInUtc = null, $castDatesToDateTime = null) {
120 120
 		$moufManager->setVariable("tdbmDefaultDaoNamespace_".$name, $daonamespace);
121 121
 		$moufManager->setVariable("tdbmDefaultBeanNamespace_".$name, $beannamespace);
122 122
 		$moufManager->setVariable("tdbmDefaultDaoFactoryName_".$name, $daofactoryclassname);
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 			$moufManager->bindComponentViaSetter($instanceName, "setTdbmService", $name);
168 168
 			$moufManager->bindComponentViaSetter($daofactoryinstancename, "set".$daoName, $instanceName);
169 169
 
170
-			$tableToBeanMap[$table] = $beannamespace . "\\" . TDBMDaoGenerator::getBeanNameFromTableName($table);
170
+			$tableToBeanMap[$table] = $beannamespace."\\".TDBMDaoGenerator::getBeanNameFromTableName($table);
171 171
 		}
172 172
 		$tdbmServiceDescriptor = $moufManager->getInstanceDescriptor($name);
173 173
 		$tdbmServiceDescriptor->getSetterProperty("setTableToBeanMap")->setValue($tableToBeanMap);
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/DisplayNode.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	public static $box_height = 30;
34 34
 	public static $interspace_width = 10;
35 35
 	public static $interspace_height = 50;
36
-	public static $text_height=13;
37
-	public static $border =2;
36
+	public static $text_height = 13;
37
+	public static $border = 2;
38 38
 
39 39
 
40 40
 	private $parent_node;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 	public $width;
48 48
 
49
-	public function __construct($table_name, $parent_node=null, $link_type=null, $keyParent=null, $keyNode=null) {
49
+	public function __construct($table_name, $parent_node = null, $link_type = null, $keyParent = null, $keyNode = null) {
50 50
 		$this->table_name = $table_name;
51 51
 		if ($parent_node !== null) {
52 52
 			$this->parent_node = $parent_node;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 	public function computeWidth() {
86
-		if (!is_array($this->children) || count($this->children)==0) {
86
+		if (!is_array($this->children) || count($this->children) == 0) {
87 87
 			$this->width = 1;
88 88
 			return 1;
89 89
 		} else {
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	public function computeDepth($my_depth) {
100
-		if (!is_array($this->children) || count($this->children)==0) {
100
+		if (!is_array($this->children) || count($this->children) == 0) {
101 101
 			return $my_depth+1;
102 102
 		} else {
103 103
 			$max = 0;
104 104
 			foreach ($this->children as $child) {
105
-				$depth = $my_depth + $child->computeDepth($my_depth);
106
-				if ($depth > $max) {
105
+				$depth = $my_depth+$child->computeDepth($my_depth);
106
+				if ($depth>$max) {
107 107
 					$max = $depth;
108 108
 				}
109 109
 			}
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
 
114 114
 	public function draw($x, $y, $left_px, $top_px) {
115 115
 
116
-		$mybox_width_px = $this->width*DisplayNode::$box_width + ($this->width-1)*DisplayNode::$interspace_width;
117
-		$my_x_px = $left_px + DisplayNode::$left_start + $x*(DisplayNode::$box_width + DisplayNode::$interspace_width);
118
-		$my_y_px = $top_px + DisplayNode::$top_start + $y*(DisplayNode::$box_height + DisplayNode::$interspace_height);
116
+		$mybox_width_px = $this->width*DisplayNode::$box_width+($this->width-1)*DisplayNode::$interspace_width;
117
+		$my_x_px = $left_px+DisplayNode::$left_start+$x*(DisplayNode::$box_width+DisplayNode::$interspace_width);
118
+		$my_y_px = $top_px+DisplayNode::$top_start+$y*(DisplayNode::$box_height+DisplayNode::$interspace_height);
119 119
 
120 120
 		// White background first
121 121
 		$str = "<div style='position:absolute; left:".$my_x_px."px; top:".$my_y_px."px; width:".$mybox_width_px."px; height:".DisplayNode::$box_height."; background-color:gray; color: white; text-align:center; border:".DisplayNode::$border."px solid black'>\n<b>".$this->table_name."</b></div>";
122 122
 
123 123
 		if ($this->keyParent != null) {
124
-			$my_x_px_line = $my_x_px + DisplayNode::$box_width/2;
125
-			$my_y_px_line = $my_y_px - DisplayNode::$interspace_height;
124
+			$my_x_px_line = $my_x_px+DisplayNode::$box_width/2;
125
+			$my_y_px_line = $my_y_px-DisplayNode::$interspace_height;
126 126
 			$str .= "<div style='position:absolute; left:".$my_x_px_line."px; top:".($my_y_px_line+DisplayNode::$border)."px; width:2px; height:".(DisplayNode::$interspace_height-DisplayNode::$border)."; background-color:black; '></div>\n";
127 127
 
128
-			$top_key = ($this->link_type=='1*')?'* fk:':'1 pk:';
128
+			$top_key = ($this->link_type == '1*') ? '* fk:' : '1 pk:';
129 129
 			$top_key .= '<i>'.$this->keyParent.'</i>';
130 130
 
131 131
 
132
-			$bottom_key = ($this->link_type=='*1')?'* fk:':'1 pk:';
132
+			$bottom_key = ($this->link_type == '*1') ? '* fk:' : '1 pk:';
133 133
 			$bottom_key .= '<i>'.$this->keyParent.'</i>';
134 134
 
135 135
 			$str .= "<div style='position:absolute; left:".($my_x_px_line+2)."px; top:".($my_y_px_line+DisplayNode::$border*2)."px; background-color:#EEEEEE; font-size: 10px'>$top_key</div>\n";
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,8 +67,7 @@
 block discarded – undo
67 67
 			if ($this->link_type == "*1")
68 68
 			{
69 69
 				echo "Table $this->table_name points to table ".$this->parent_node->table_name." through its foreign key on column $this->keyNode that points to column $this->keyParent<br />";
70
-			}
71
-			else if ($this->link_type == "1*")
70
+			} else if ($this->link_type == "1*")
72 71
 			{
73 72
 				echo "Table $this->table_name is pointed by table ".$this->parent_node->table_name." by its foreign key on column $this->keyParent that points to column $this->keyNode<br />";
74 73
 			}
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/Filters/FilterUtils.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@
 block discarded – undo
9 9
  */
10 10
 class FilterUtils
11 11
 {
12
-    /**
13
-     * @param string|null|DateTimeInterface $value
14
-     */
15
-    public static function valueToSql($value, ConnectionInterface $dbConnection) {
16
-        if ($value instanceof DateTimeInterface) {
17
-            return "'".$value->format('Y-m-d H:i:s')."'";
18
-        } else {
19
-            return $dbConnection->quoteSmart($value);
20
-        }
21
-    }
12
+	/**
13
+	 * @param string|null|DateTimeInterface $value
14
+	 */
15
+	public static function valueToSql($value, ConnectionInterface $dbConnection) {
16
+		if ($value instanceof DateTimeInterface) {
17
+			return "'".$value->format('Y-m-d H:i:s')."'";
18
+		} else {
19
+			return $dbConnection->quoteSmart($value);
20
+		}
21
+	}
22 22
 }
Please login to merge, or discard this patch.
src/views/installStep2.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 <div class="control-group">
38 38
 	<label class="control-label">Cast dates as <code>DateTimeImmutable</code>:</label>
39 39
 	<div class="controls">
40
-		<input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime?'checked="checked"':"" ?>></input>
40
+		<input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime ? 'checked="checked"' : "" ?>></input>
41 41
 	<span class="help-block">Select this option if you want dates to be returned as <code>DateTimeImmutable</code>.
42 42
 	This is highly recommended. If you do not select this box, getters and setters will return / expect a timestamp
43 43
 	(this was the default behaviour up to TDBM 3.3).</span>
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 <div class="control-group">
47 47
 	<label class="control-label">Store dates / timestamps in UTC:</label>
48 48
 	<div class="controls">
49
-		<input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc?'checked="checked"':"" ?>></input>
49
+		<input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc ? 'checked="checked"' : "" ?>></input>
50 50
 		<span class="help-block">Select this option if you want timestamps to be stored in UTC.
51 51
 		If your application supports several time zones, you should select this option to store all dates in
52 52
 		the same time zone.</span>
Please login to merge, or discard this patch.
src/views/tdbmGenerate.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 <div class="control-group">
46 46
 	<label class="control-label">Keep support for previous DAOs:</label>
47 47
 	<div class="controls">
48
-		<input type="checkbox" name="keepSupport" <?php echo $this->keepSupport?'checked="checked"':"" ?>></input>
48
+		<input type="checkbox" name="keepSupport" <?php echo $this->keepSupport ? 'checked="checked"' : "" ?>></input>
49 49
 		<span class="help-block">DAOs generated before TDBM 2.3 had a different method signature. This will ensure this signature
50 50
 		is respected. Use this only if you are migrating legacy code.</span>
51 51
 	</div>
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 <div class="control-group">
54 54
 	<label class="control-label">Cast dates as <code>DateTimeImmutable</code>:</label>
55 55
 	<div class="controls">
56
-		<input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime?'checked="checked"':"" ?>></input>
56
+		<input type="checkbox" name="castDatesToDateTime" value="1" <?php echo $this->castDatesToDateTime ? 'checked="checked"' : "" ?>></input>
57 57
 <span class="help-block">Select this option if you want dates to be returned as <code>DateTimeImmutable</code>.
58 58
 This is highly recommended. If you do not select this box, getters and setters will return / expect a timestamp
59 59
 (this was the default behaviour up to TDBM 3.3).</span>
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 <div class="control-group">
63 63
 	<label class="control-label">Store dates / timestamps in UTC:</label>
64 64
 	<div class="controls">
65
-		<input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc?'checked="checked"':"" ?>></input>
65
+		<input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc ? 'checked="checked"' : "" ?>></input>
66 66
 		<span class="help-block">Select this option if you want timestamps to be stored in UTC.
67 67
 		If your application supports several time zones, you should select this option to store all dates in
68 68
 		the same time zone.</span>
Please login to merge, or discard this patch.