Completed
Pull Request — 3.4 (#46)
by David
12:52 queued 01:27
created
src/Mouf/Database/TDBM/TDBMService.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -699,9 +699,9 @@  discard block
 block discarded – undo
699 699
 		// 4-2, let's take all the objects out of the orderby bag, and let's make objects from them
700 700
 		$orderby_bag2 = array();
701 701
 		foreach ($orderby_bag as $thing) {
702
-			if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) {
702
+			if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) {
703 703
 				$orderby_bag2[] = $thing;
704
-			} elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) {
704
+			} elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) {
705 705
 				$orderby_bag2[] = $thing;
706 706
 			} elseif (is_string($thing)) {
707 707
 				$orderby_bag2[] = new OrderBySQLString($thing);
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
 		$schemaAnalyzer = $this->schemaAnalyzer;
1205 1205
 
1206 1206
 		foreach ($tables as $currentTable) {
1207
-			$allParents = [ $currentTable ];
1207
+			$allParents = [$currentTable];
1208 1208
 			$currentFk = null;
1209 1209
 			while ($currentFk = $schemaAnalyzer->getParentRelationship($currentTable)) {
1210 1210
 				$currentTable = $currentFk->getForeignTableName();
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 		// Let's scan the parent tables
1247 1247
 		$currentTable = $table;
1248 1248
 
1249
-		$parentTables = [ ];
1249
+		$parentTables = [];
1250 1250
 
1251 1251
 		// Get parent relationship
1252 1252
 		while ($currentFk = $schemaAnalyzer->getParentRelationship($currentTable)) {
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
 	 * @return ResultIterator An object representing an array of results.
1337 1337
 	 * @throws TDBMException
1338 1338
 	 */
1339
-	public function findObjects($mainTable, $filter=null, array $parameters = array(), $orderString=null, array $additionalTablesFetch = array(), $mode = null, $className=null) {
1339
+	public function findObjects($mainTable, $filter = null, array $parameters = array(), $orderString = null, array $additionalTablesFetch = array(), $mode = null, $className = null) {
1340 1340
 		// $mainTable is not secured in MagicJoin, let's add a bit of security to avoid SQL injection.
1341 1341
 		if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $mainTable)) {
1342 1342
 			throw new TDBMException(sprintf("Invalid table name: '%s'", $mainTable));
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
 			throw new TDBMException("Unknown fetch mode: '".$this->mode."'");
1406 1406
 		}
1407 1407
 
1408
-		$mode = $mode?:$this->mode;
1408
+		$mode = $mode ?: $this->mode;
1409 1409
 
1410 1410
 		return new ResultIterator($sql, $countSql, $parameters, $columnDescList, $this->objectStorage, $className, $this, $this->magicQuery, $mode);
1411 1411
 	}
@@ -1419,7 +1419,7 @@  discard block
 block discarded – undo
1419 1419
 	 * @return AbstractTDBMObject
1420 1420
 	 * @throws TDBMException
1421 1421
 	 */
1422
-	public function findObjectByPk($table, array $primaryKeys, array $additionalTablesFetch = array(), $lazy = false, $className=null) {
1422
+	public function findObjectByPk($table, array $primaryKeys, array $additionalTablesFetch = array(), $lazy = false, $className = null) {
1423 1423
 		$primaryKeys = $this->_getPrimaryKeysFromObjectData($table, $primaryKeys);
1424 1424
 		$hash = $this->getObjectHash($primaryKeys);
1425 1425
 
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 			// Only allowed if no inheritance.
1440 1440
 			if (count($tables) === 1) {
1441 1441
 				if ($className === null) {
1442
-					$className = isset($this->tableToBeanMap[$table])?$this->tableToBeanMap[$table]:"Mouf\\Database\\TDBM\\TDBMObject";
1442
+					$className = isset($this->tableToBeanMap[$table]) ? $this->tableToBeanMap[$table] : "Mouf\\Database\\TDBM\\TDBMObject";
1443 1443
 				}
1444 1444
 
1445 1445
 				// Let's construct the bean
@@ -1468,11 +1468,11 @@  discard block
 block discarded – undo
1468 1468
 	 * @return AbstractTDBMObject|null The object we want, or null if no object matches the filters.
1469 1469
 	 * @throws TDBMException
1470 1470
 	 */
1471
-	public function findObject($mainTable, $filterString=null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) {
1471
+	public function findObject($mainTable, $filterString = null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) {
1472 1472
 		$objects = $this->findObjects($mainTable, $filterString, $parameters, null, $additionalTablesFetch, self::MODE_ARRAY, $className);
1473 1473
 		$page = $objects->take(0, 2);
1474 1474
 		$count = $page->count();
1475
-		if ($count > 1) {
1475
+		if ($count>1) {
1476 1476
 			throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one.");
1477 1477
 		} elseif ($count === 0) {
1478 1478
 			return null;
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
 	 * @return AbstractTDBMObject The object we want
1493 1493
 	 * @throws TDBMException
1494 1494
 	 */
1495
-	public function findObjectOrFail($mainTable, $filterString=null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) {
1495
+	public function findObjectOrFail($mainTable, $filterString = null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) {
1496 1496
 		$bean = $this->findObject($mainTable, $filterString, $parameters, $additionalTablesFetch, $className);
1497 1497
 		if ($bean === null) {
1498 1498
 			throw new NoBeanFoundException("No result found for query on table '".$mainTable."'");
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/DbRow.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @throws TDBMException
95 95
 	 * @throws TDBMInvalidOperationException
96 96
 	 */
97
-	public function __construct(AbstractTDBMObject $object, $table_name, array $primaryKeys=array(), TDBMService $tdbmService=null, array $dbRow = array()) {
97
+	public function __construct(AbstractTDBMObject $object, $table_name, array $primaryKeys = array(), TDBMService $tdbmService = null, array $dbRow = array()) {
98 98
 		$this->object = $object;
99 99
 		$this->dbTableName = $table_name;
100 100
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * $status = TDBMObjectStateEnum::STATE_LOADED when the object is cached in memory.
142 142
 	 * @param string $state
143 143
 	 */
144
-	public function _setStatus($state){
144
+	public function _setStatus($state) {
145 145
 		$this->status = $state;
146 146
 	}
147 147
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			$sql = "SELECT * FROM ".$connection->quoteIdentifier($this->dbTableName)." WHERE ".$sql_where;
164 164
 			$result = $connection->executeQuery($sql, $parameters);
165 165
 
166
-			if ($result->rowCount()==0)
166
+			if ($result->rowCount() == 0)
167 167
 			{
168 168
 				throw new TDBMException("Could not retrieve object from table \"$this->dbTableName\" with ID \"".$this->TDBMObject_id."\".");
169 169
 			}
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     /**
327 327
      * Override the native php clone function for TDBMObjects
328 328
      */
329
-    public function __clone(){
329
+    public function __clone() {
330 330
         $this->_dbLoadIfNotLoaded();
331 331
         //First lets set the status to new (to enter the save function)
332 332
         $this->status = TDBMObjectStateEnum::STATE_NEW;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             $pkValues = array_values($firstRefDbRow->_getPrimaryKeys());
359 359
             $localColumns = $fk->getLocalColumns();
360 360
 
361
-            for ($i=0, $count=count($localColumns); $i<$count; $i++) {
361
+            for ($i = 0, $count = count($localColumns); $i<$count; $i++) {
362 362
                 $dbRow[$localColumns[$i]] = $pkValues[$i];
363 363
             }
364 364
         }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/AbstractTDBMObject.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @throws TDBMException
76 76
 	 * @throws TDBMInvalidOperationException
77 77
 	 */
78
-	public function __construct($tableName=null, array $primaryKeys=array(), TDBMService $tdbmService=null) {
78
+	public function __construct($tableName = null, array $primaryKeys = array(), TDBMService $tdbmService = null) {
79 79
 		// FIXME: lazy loading should be forbidden on tables with inheritance and dynamic type assignation...
80 80
 		if (!empty($tableName)) {
81 81
 			$this->dbRows[$tableName] = new DbRow($this, $tableName, $primaryKeys, $tdbmService);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * $status = TDBMObjectStateEnum::STATE_LOADED when the object is cached in memory.
160 160
 	 * @param string $state
161 161
 	 */
162
-	public function _setStatus($state){
162
+	public function _setStatus($state) {
163 163
 		$this->status = $state;
164 164
 
165 165
 		// TODO: we might ignore the loaded => dirty state here! dirty status comes from the db_row itself.
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
 	public function get($var, $tableName = null) {
172 172
 		if ($tableName === null) {
173
-			if (count($this->dbRows) > 1) {
173
+			if (count($this->dbRows)>1) {
174 174
 				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
175 175
 			} elseif (count($this->dbRows) === 1) {
176 176
 				$tableName = array_keys($this->dbRows)[0];
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	public function has($var, $tableName = null) {
198 198
 		if ($tableName === null) {
199
-			if (count($this->dbRows) > 1) {
199
+			if (count($this->dbRows)>1) {
200 200
 				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
201 201
 			} elseif (count($this->dbRows) === 1) {
202 202
 				$tableName = array_keys($this->dbRows)[0];
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	
217 217
 	public function set($var, $value, $tableName = null) {
218 218
 		if ($tableName === null) {
219
-			if (count($this->dbRows) > 1) {
219
+			if (count($this->dbRows)>1) {
220 220
 				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
221 221
 			} elseif (count($this->dbRows) === 1) {
222 222
 				$tableName = array_keys($this->dbRows)[0];
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	public function setRef($foreignKeyName, AbstractTDBMObject $bean, $tableName = null) {
243 243
 		if ($tableName === null) {
244
-			if (count($this->dbRows) > 1) {
244
+			if (count($this->dbRows)>1) {
245 245
 				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
246 246
 			} elseif (count($this->dbRows) === 1) {
247 247
 				$tableName = array_keys($this->dbRows)[0];
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 */
267 267
 	public function getRef($foreignKeyName, $tableName = null) {
268 268
 		if ($tableName === null) {
269
-			if (count($this->dbRows) > 1) {
269
+			if (count($this->dbRows)>1) {
270 270
 				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
271 271
 			} elseif (count($this->dbRows) === 1) {
272 272
 				$tableName = array_keys($this->dbRows)[0];
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
 	 */
383 383
 	private function setRelationship($pivotTableName, AbstractTDBMObject $remoteBean, $status) {
384 384
 		$storage = $this->getRelationshipStorage($pivotTableName);
385
-		$storage->attach($remoteBean, [ 'status' => $status, 'reverse' => false ]);
385
+		$storage->attach($remoteBean, ['status' => $status, 'reverse' => false]);
386 386
 		if ($this->status === TDBMObjectStateEnum::STATE_LOADED) {
387 387
 			$this->_setStatus(TDBMObjectStateEnum::STATE_DIRTY);
388 388
 		}
389 389
 
390 390
 		$remoteStorage = $remoteBean->getRelationshipStorage($pivotTableName);
391
-		$remoteStorage->attach($this, [ 'status' => $status, 'reverse' => true ]);
391
+		$remoteStorage->attach($this, ['status' => $status, 'reverse' => true]);
392 392
 	}
393 393
 
394 394
 	/**
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 				$metadata = $storage[$remoteBean];
459 459
 
460 460
 				$remoteStorage = $remoteBean->getRelationshipStorage($pivotTable);
461
-				$remoteStorage->attach($this, [ 'status' => $metadata['status'], 'reverse' => !$metadata['reverse'] ]);
461
+				$remoteStorage->attach($this, ['status' => $metadata['status'], 'reverse' => !$metadata['reverse']]);
462 462
 			}
463 463
 		}
464 464
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	private function registerTable($tableName) {
486 486
 		$dbRow = new DbRow($this, $tableName);
487 487
 
488
-		if (in_array($this->status, [ TDBMObjectStateEnum::STATE_NOT_LOADED, TDBMObjectStateEnum::STATE_LOADED, TDBMObjectStateEnum::STATE_DIRTY ])) {
488
+		if (in_array($this->status, [TDBMObjectStateEnum::STATE_NOT_LOADED, TDBMObjectStateEnum::STATE_LOADED, TDBMObjectStateEnum::STATE_DIRTY])) {
489 489
 			// Let's get the primary key for the new table
490 490
 			$anotherDbRow = array_values($this->dbRows)[0];
491 491
 			/* @var $anotherDbRow DbRow */
Please login to merge, or discard this patch.