Passed
Branch 3.4 (b2adff)
by David
21:19
created
src/Mouf/Database/TDBM/TDBMService.php 1 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.
src/Mouf/Database/TDBM/Utils/TDBMDaoGenerator.php 1 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.