@@ -699,9 +699,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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."'"); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @throws TDBMException |
96 | 96 | * @throws TDBMInvalidOperationException |
97 | 97 | */ |
98 | - public function __construct($tableName=null, array $primaryKeys=array(), TDBMService $tdbmService=null) { |
|
98 | + public function __construct($tableName = null, array $primaryKeys = array(), TDBMService $tdbmService = null) { |
|
99 | 99 | // FIXME: lazy loading should be forbidden on tables with inheritance and dynamic type assignation... |
100 | 100 | if (!empty($tableName)) { |
101 | 101 | $this->dbRows[$tableName] = new DbRow($this, $tableName, $primaryKeys, $tdbmService); |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * $status = TDBMObjectStateEnum::STATE_LOADED when the object is cached in memory. |
200 | 200 | * @param string $state |
201 | 201 | */ |
202 | - public function _setStatus($state){ |
|
202 | + public function _setStatus($state) { |
|
203 | 203 | $this->status = $state; |
204 | 204 | |
205 | 205 | // TODO: we might ignore the loaded => dirty state here! dirty status comes from the db_row itself. |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | |
211 | 211 | public function get($var, $tableName = null) { |
212 | 212 | if ($tableName === null) { |
213 | - if (count($this->dbRows) > 1) { |
|
213 | + if (count($this->dbRows)>1) { |
|
214 | 214 | throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.'); |
215 | 215 | } elseif (count($this->dbRows) === 1) { |
216 | 216 | $tableName = array_keys($this->dbRows)[0]; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function has($var, $tableName = null) { |
238 | 238 | if ($tableName === null) { |
239 | - if (count($this->dbRows) > 1) { |
|
239 | + if (count($this->dbRows)>1) { |
|
240 | 240 | throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.'); |
241 | 241 | } elseif (count($this->dbRows) === 1) { |
242 | 242 | $tableName = array_keys($this->dbRows)[0]; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | public function set($var, $value, $tableName = null) { |
258 | 258 | if ($tableName === null) { |
259 | - if (count($this->dbRows) > 1) { |
|
259 | + if (count($this->dbRows)>1) { |
|
260 | 260 | throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.'); |
261 | 261 | } elseif (count($this->dbRows) === 1) { |
262 | 262 | $tableName = array_keys($this->dbRows)[0]; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function setRef($foreignKeyName, AbstractTDBMObject $bean, $tableName = null) { |
283 | 283 | if ($tableName === null) { |
284 | - if (count($this->dbRows) > 1) { |
|
284 | + if (count($this->dbRows)>1) { |
|
285 | 285 | throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.'); |
286 | 286 | } elseif (count($this->dbRows) === 1) { |
287 | 287 | $tableName = array_keys($this->dbRows)[0]; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function getRef($foreignKeyName, $tableName = null) { |
308 | 308 | if ($tableName === null) { |
309 | - if (count($this->dbRows) > 1) { |
|
309 | + if (count($this->dbRows)>1) { |
|
310 | 310 | throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.'); |
311 | 311 | } elseif (count($this->dbRows) === 1) { |
312 | 312 | $tableName = array_keys($this->dbRows)[0]; |
@@ -422,13 +422,13 @@ discard block |
||
422 | 422 | */ |
423 | 423 | private function setRelationship($pivotTableName, AbstractTDBMObject $remoteBean, $status) { |
424 | 424 | $storage = $this->getRelationshipStorage($pivotTableName); |
425 | - $storage->attach($remoteBean, [ 'status' => $status, 'reverse' => false ]); |
|
425 | + $storage->attach($remoteBean, ['status' => $status, 'reverse' => false]); |
|
426 | 426 | if ($this->status === TDBMObjectStateEnum::STATE_LOADED) { |
427 | 427 | $this->_setStatus(TDBMObjectStateEnum::STATE_DIRTY); |
428 | 428 | } |
429 | 429 | |
430 | 430 | $remoteStorage = $remoteBean->getRelationshipStorage($pivotTableName); |
431 | - $remoteStorage->attach($this, [ 'status' => $status, 'reverse' => true ]); |
|
431 | + $remoteStorage->attach($this, ['status' => $status, 'reverse' => true]); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -516,23 +516,23 @@ discard block |
||
516 | 516 | * |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - private function getPrimaryKeyWhereStatement () { |
|
519 | + private function getPrimaryKeyWhereStatement() { |
|
520 | 520 | // Let's first get the primary keys |
521 | 521 | $pk_table = $this->tdbmService->getPrimaryKeyColumns($this->dbTableName); |
522 | 522 | // Now for the object_id |
523 | 523 | $object_id = $this->TDBMObject_id; |
524 | 524 | // If there is only one primary key: |
525 | - if (count($pk_table)==1) { |
|
525 | + if (count($pk_table) == 1) { |
|
526 | 526 | $sql_where = $this->db_connection->escapeDBItem($this->dbTableName).'.'.$this->db_connection->escapeDBItem($pk_table[0])."=".$this->db_connection->quoteSmart($this->TDBMObject_id); |
527 | 527 | } else { |
528 | 528 | $ids = unserialize($object_id); |
529 | - $i=0; |
|
529 | + $i = 0; |
|
530 | 530 | $sql_where_array = array(); |
531 | 531 | foreach ($pk_table as $pk) { |
532 | 532 | $sql_where_array[] = $this->db_connection->escapeDBItem($this->dbTableName).'.'.$this->db_connection->escapeDBItem($pk)."=".$this->db_connection->quoteSmart($ids[$i]); |
533 | 533 | $i++; |
534 | 534 | } |
535 | - $sql_where = implode(" AND ",$sql_where_array); |
|
535 | + $sql_where = implode(" AND ", $sql_where_array); |
|
536 | 536 | } |
537 | 537 | return $sql_where; |
538 | 538 | } |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | /** |
541 | 541 | * Override the native php clone function for TDBMObjects |
542 | 542 | */ |
543 | - public function __clone(){ |
|
543 | + public function __clone() { |
|
544 | 544 | $this->_dbLoadIfNotLoaded(); |
545 | 545 | //First lets set the status to new (to enter the save function) |
546 | 546 | $this->status = TDBMObjectStateEnum::STATE_NEW; |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | private function registerTable($tableName) { |
568 | 568 | $dbRow = new DbRow($this, $tableName); |
569 | 569 | |
570 | - if (in_array($this->status, [ TDBMObjectStateEnum::STATE_NOT_LOADED, TDBMObjectStateEnum::STATE_LOADED, TDBMObjectStateEnum::STATE_DIRTY ])) { |
|
570 | + if (in_array($this->status, [TDBMObjectStateEnum::STATE_NOT_LOADED, TDBMObjectStateEnum::STATE_LOADED, TDBMObjectStateEnum::STATE_DIRTY])) { |
|
571 | 571 | // Let's get the primary key for the new table |
572 | 572 | $anotherDbRow = array_values($this->dbRows)[0]; |
573 | 573 | /* @var $anotherDbRow DbRow */ |
@@ -94,7 +94,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |