Commit 15932f95 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Frank Nägler
Browse files

[TASK] Harden \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend

- Use strict type mode
- Use type hints whereever possible
- Use type casts according to phpstan results

Releases: master
Resolves: #88666
Change-Id: I4d93c3e3c75f5f6ca6b53bd73acffe73d7b6a58e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61205


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
parent 66302a14
...@@ -619,8 +619,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -619,8 +619,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
{ {
if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject) { if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject) {
$result = $this->getUidOfAlreadyPersistedValueObject($object); $result = $this->getUidOfAlreadyPersistedValueObject($object);
if ($result !== false) { if ($result !== null) {
$object->_setProperty('uid', (int)$result); $object->_setProperty('uid', $result);
return; return;
} }
} }
...@@ -708,7 +708,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -708,7 +708,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
* Tests, if the given Value Object already exists in the storage backend and if so, it returns the uid. * Tests, if the given Value Object already exists in the storage backend and if so, it returns the uid.
* *
* @param \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object The object to be tested * @param \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object The object to be tested
* @return mixed The matching uid if an object was found, else FALSE * @return int|null The matching uid if an object was found, else null
*/ */
protected function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object) protected function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object)
{ {
...@@ -776,11 +776,11 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -776,11 +776,11 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
if (is_array($relationTableMatchFields)) { if (is_array($relationTableMatchFields)) {
$row = array_merge($relationTableMatchFields, $row); $row = array_merge($relationTableMatchFields, $row);
} }
$res = $this->storageBackend->updateRelationTableRow( $this->storageBackend->updateRelationTableRow(
$relationTableName, $relationTableName,
$row $row
); );
return $res; return true;
} }
/** /**
...@@ -802,8 +802,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -802,8 +802,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
if (is_array($relationTableMatchFields)) { if (is_array($relationTableMatchFields)) {
$relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields); $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
} }
$res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, false); $this->storageBackend->removeRow($relationTableName, $relationMatchFields, false);
return $res; return true;
} }
/** /**
...@@ -827,8 +827,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -827,8 +827,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
if (is_array($relationTableMatchFields)) { if (is_array($relationTableMatchFields)) {
$relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields); $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
} }
$res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, false); $this->storageBackend->removeRow($relationTableName, $relationMatchFields, false);
return $res; return true;
} }
/** /**
...@@ -905,15 +905,14 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -905,15 +905,14 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
$row['uid'] = $object->_getProperty('_localizedUid'); $row['uid'] = $object->_getProperty('_localizedUid');
} }
} }
$res = $this->storageBackend->updateRow($dataMap->getTableName(), $row); $this->storageBackend->updateRow($dataMap->getTableName(), $row);
if ($res === true) { $this->emitAfterUpdateObjectSignal($object);
$this->emitAfterUpdateObjectSignal($object);
}
$frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') { if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') {
$this->referenceIndex->updateRefIndexTable($dataMap->getTableName(), $row['uid']); $this->referenceIndex->updateRefIndexTable($dataMap->getTableName(), $row['uid']);
} }
return $res; return true;
} }
/** /**
...@@ -1003,13 +1002,12 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface ...@@ -1003,13 +1002,12 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
$deletedColumnName => 1 $deletedColumnName => 1
]; ];
$this->addCommonDateFieldsToRow($object, $row); $this->addCommonDateFieldsToRow($object, $row);
$res = $this->storageBackend->updateRow($tableName, $row); $this->storageBackend->updateRow($tableName, $row);
} else { } else {
$res = $this->storageBackend->removeRow($tableName, ['uid' => $object->getUid()]); $this->storageBackend->removeRow($tableName, ['uid' => $object->getUid()]);
}
if ($res === true) {
$this->emitAfterRemoveObjectSignal($object);
} }
$this->emitAfterRemoveObjectSignal($object);
$this->removeRelatedObjects($object); $this->removeRelatedObjects($object);
$frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') { if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') {
......
<?php <?php
declare(strict_types = 1);
namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage; namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage;
/* /*
...@@ -27,7 +29,7 @@ interface BackendInterface ...@@ -27,7 +29,7 @@ interface BackendInterface
* @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
* @return int the UID of the inserted row * @return int the UID of the inserted row
*/ */
public function addRow($tableName, array $fieldValues, $isRelation = false); public function addRow(string $tableName, array $fieldValues, bool $isRelation = false): int;
/** /**
* Updates a row in the storage * Updates a row in the storage
...@@ -35,18 +37,16 @@ interface BackendInterface ...@@ -35,18 +37,16 @@ interface BackendInterface
* @param string $tableName The database table name * @param string $tableName The database table name
* @param array $fieldValues The fieldValues to update * @param array $fieldValues The fieldValues to update
* @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
* @return mixed|void
*/ */
public function updateRow($tableName, array $fieldValues, $isRelation = false); public function updateRow(string $tableName, array $fieldValues, bool $isRelation = false): void;
/** /**
* Updates a relation row in the storage * Updates a relation row in the storage
* *
* @param string $tableName The database relation table name * @param string $tableName The database relation table name
* @param array $fieldValues The fieldValues to be updated * @param array $fieldValues The fieldValues to be updated
* @return bool
*/ */
public function updateRelationTableRow($tableName, array $fieldValues); public function updateRelationTableRow(string $tableName, array $fieldValues): void;
/** /**
* Deletes a row in the storage * Deletes a row in the storage
...@@ -54,9 +54,8 @@ interface BackendInterface ...@@ -54,9 +54,8 @@ interface BackendInterface
* @param string $tableName The database table name * @param string $tableName The database table name
* @param array $where An array of where array('fieldname' => value). This array will be transformed to a WHERE clause * @param array $where An array of where array('fieldname' => value). This array will be transformed to a WHERE clause
* @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
* @return mixed|void
*/ */
public function removeRow($tableName, array $where, $isRelation = false); public function removeRow(string $tableName, array $where, bool $isRelation = false): void;
/** /**
* Fetches maximal value for given table column * Fetches maximal value for given table column
...@@ -66,7 +65,7 @@ interface BackendInterface ...@@ -66,7 +65,7 @@ interface BackendInterface
* @param string $columnName column name to get the max value from * @param string $columnName column name to get the max value from
* @return mixed the max value * @return mixed the max value
*/ */
public function getMaxValueFromTable($tableName, array $where, $columnName); public function getMaxValueFromTable(string $tableName, array $where, string $columnName);
/** /**
* Returns the number of items matching the query. * Returns the number of items matching the query.
...@@ -74,7 +73,7 @@ interface BackendInterface ...@@ -74,7 +73,7 @@ interface BackendInterface
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return int * @return int
*/ */
public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query); public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query): int;
/** /**
* Returns the object data matching the $query. * Returns the object data matching the $query.
...@@ -82,14 +81,14 @@ interface BackendInterface ...@@ -82,14 +81,14 @@ interface BackendInterface
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return array * @return array
*/ */
public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query); public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query): array;
/** /**
* Checks if a Value Object equal to the given Object exists in the data base * Checks if a Value Object equal to the given Object exists in the data base
* *
* @param \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object The Value Object * @param \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object The Value Object
* @return mixed The matching uid if an object was found, else FALSE * @return int|null The matching uid if an object was found, else null
* @todo this is the last monster in this persistence series. refactor! * @todo this is the last monster in this persistence series. refactor!
*/ */
public function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object); public function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object): ?int;
} }
<?php <?php
declare(strict_types = 1);
namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage; namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage;
/* /*
...@@ -81,7 +83,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -81,7 +83,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
/** /**
* @param ConfigurationManagerInterface $configurationManager * @param ConfigurationManagerInterface $configurationManager
*/ */
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
{ {
$this->configurationManager = $configurationManager; $this->configurationManager = $configurationManager;
} }
...@@ -89,7 +91,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -89,7 +91,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
/** /**
* @param CacheService $cacheService * @param CacheService $cacheService
*/ */
public function injectCacheService(CacheService $cacheService) public function injectCacheService(CacheService $cacheService): void
{ {
$this->cacheService = $cacheService; $this->cacheService = $cacheService;
} }
...@@ -97,7 +99,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -97,7 +99,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
/** /**
* @param EnvironmentService $environmentService * @param EnvironmentService $environmentService
*/ */
public function injectEnvironmentService(EnvironmentService $environmentService) public function injectEnvironmentService(EnvironmentService $environmentService): void
{ {
$this->environmentService = $environmentService; $this->environmentService = $environmentService;
} }
...@@ -105,7 +107,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -105,7 +107,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
/** /**
* @param ObjectManagerInterface $objectManager * @param ObjectManagerInterface $objectManager
*/ */
public function injectObjectManager(ObjectManagerInterface $objectManager) public function injectObjectManager(ObjectManagerInterface $objectManager): void
{ {
$this->objectManager = $objectManager; $this->objectManager = $objectManager;
} }
...@@ -127,7 +129,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -127,7 +129,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @return int The uid of the inserted row * @return int The uid of the inserted row
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function addRow($tableName, array $fieldValues, $isRelation = false) public function addRow(string $tableName, array $fieldValues, bool $isRelation = false): int
{ {
if (isset($fieldValues['uid'])) { if (isset($fieldValues['uid'])) {
unset($fieldValues['uid']); unset($fieldValues['uid']);
...@@ -153,10 +155,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -153,10 +155,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
$uid = 0; $uid = 0;
if (!$isRelation) { if (!$isRelation) {
// Relation tables have no auto_increment column, so no retrieval must be tried. // Relation tables have no auto_increment column, so no retrieval must be tried.
$uid = $connection->lastInsertId($tableName); $uid = (int)$connection->lastInsertId($tableName);
$this->clearPageCache($tableName, $uid); $this->clearPageCache($tableName, $uid);
} }
return (int)$uid; return $uid;
} }
/** /**
...@@ -165,11 +167,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -165,11 +167,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @param string $tableName The database table name * @param string $tableName The database table name
* @param array $fieldValues The row to be updated * @param array $fieldValues The row to be updated
* @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
* @return bool
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function updateRow($tableName, array $fieldValues, $isRelation = false) public function updateRow(string $tableName, array $fieldValues, bool $isRelation = false): void
{ {
if (!isset($fieldValues['uid'])) { if (!isset($fieldValues['uid'])) {
throw new \InvalidArgumentException('The given row must contain a value for "uid".', 1476045164); throw new \InvalidArgumentException('The given row must contain a value for "uid".', 1476045164);
...@@ -187,6 +188,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -187,6 +188,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
// mssql needs to set proper PARAM_LOB and others to update fields // mssql needs to set proper PARAM_LOB and others to update fields
$tableDetails = $connection->getSchemaManager()->listTableDetails($tableName); $tableDetails = $connection->getSchemaManager()->listTableDetails($tableName);
foreach ($fieldValues as $columnName => $columnValue) { foreach ($fieldValues as $columnName => $columnValue) {
$columnName = (string)$columnName;
$types[$columnName] = $tableDetails->getColumn($columnName)->getType()->getBindingType(); $types[$columnName] = $tableDetails->getColumn($columnName)->getType()->getBindingType();
} }
} }
...@@ -199,9 +201,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -199,9 +201,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
if (!$isRelation) { if (!$isRelation) {
$this->clearPageCache($tableName, $uid); $this->clearPageCache($tableName, $uid);
} }
// always returns true
return true;
} }
/** /**
...@@ -209,11 +208,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -209,11 +208,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* *
* @param string $tableName The database relation table name * @param string $tableName The database relation table name
* @param array $fieldValues The row to be updated * @param array $fieldValues The row to be updated
* @return bool
* @throws SqlErrorException * @throws SqlErrorException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function updateRelationTableRow($tableName, array $fieldValues) public function updateRelationTableRow(string $tableName, array $fieldValues): void
{ {
if (!isset($fieldValues['uid_local']) && !isset($fieldValues['uid_foreign'])) { if (!isset($fieldValues['uid_local']) && !isset($fieldValues['uid_foreign'])) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
...@@ -222,6 +220,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -222,6 +220,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
); );
} }
$where = [];
$where['uid_local'] = (int)$fieldValues['uid_local']; $where['uid_local'] = (int)$fieldValues['uid_local'];
$where['uid_foreign'] = (int)$fieldValues['uid_foreign']; $where['uid_foreign'] = (int)$fieldValues['uid_foreign'];
unset($fieldValues['uid_local']); unset($fieldValues['uid_local']);
...@@ -241,9 +240,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -241,9 +240,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
} catch (DBALException $e) { } catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768, $e); throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768, $e);
} }
// always returns true
return true;
} }
/** /**
...@@ -252,10 +248,9 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -252,10 +248,9 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @param string $tableName The database table name * @param string $tableName The database table name
* @param array $where An array of where array('fieldname' => value). * @param array $where An array of where array('fieldname' => value).
* @param bool $isRelation TRUE if we are currently manipulating a relation table, FALSE by default * @param bool $isRelation TRUE if we are currently manipulating a relation table, FALSE by default
* @return bool
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function removeRow($tableName, array $where, $isRelation = false) public function removeRow(string $tableName, array $where, bool $isRelation = false): void
{ {
try { try {
$this->connectionPool->getConnectionForTable($tableName)->delete($tableName, $where); $this->connectionPool->getConnectionForTable($tableName)->delete($tableName, $where);
...@@ -264,11 +259,8 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -264,11 +259,8 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
} }
if (!$isRelation && isset($where['uid'])) { if (!$isRelation && isset($where['uid'])) {
$this->clearPageCache($tableName, $where['uid']); $this->clearPageCache($tableName, (int)$where['uid']);
} }
// always returns true
return true;
} }
/** /**
...@@ -280,7 +272,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -280,7 +272,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @return mixed the max value * @return mixed the max value
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function getMaxValueFromTable($tableName, array $where, $columnName) public function getMaxValueFromTable(string $tableName, array $where, string $columnName)
{ {
try { try {
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName); $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
...@@ -312,8 +304,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -312,8 +304,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @return array|bool * @return array|bool
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function getRowByIdentifier($tableName, array $where) public function getRowByIdentifier(string $tableName, array $where)
{ {
// todo: this method is not in use, consider removing it.
try { try {
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName); $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
$queryBuilder->getRestrictions()->removeAll(); $queryBuilder->getRestrictions()->removeAll();
...@@ -328,10 +322,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -328,10 +322,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
} }
$row = $queryBuilder->execute()->fetch(); $row = $queryBuilder->execute()->fetch();
return is_array($row) ? $row : false;
} catch (DBALException $e) { } catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230771, $e); throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230771, $e);
} }
return $row ?: false;
} }
/** /**
...@@ -341,14 +335,16 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -341,14 +335,16 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @return array * @return array
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function getObjectDataByQuery(QueryInterface $query) public function getObjectDataByQuery(QueryInterface $query): array
{ {
$statement = $query->getStatement(); $statement = $query->getStatement();
// todo: remove instanceof checks as soon as getStatement() strictly returns Qom\Statement only
if ($statement instanceof Qom\Statement if ($statement instanceof Qom\Statement
&& !$statement->getStatement() instanceof QueryBuilder && !$statement->getStatement() instanceof QueryBuilder
) { ) {
$rows = $this->getObjectDataByRawQuery($statement); $rows = $this->getObjectDataByRawQuery($statement);
} else { } else {
/** @var Typo3DbQueryParser $queryParser */
$queryParser = $this->objectManager->get(Typo3DbQueryParser::class); $queryParser = $this->objectManager->get(Typo3DbQueryParser::class);
if ($statement instanceof Qom\Statement if ($statement instanceof Qom\Statement
&& $statement->getStatement() instanceof QueryBuilder && $statement->getStatement() instanceof QueryBuilder
...@@ -389,7 +385,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -389,7 +385,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @return array * @return array
* @throws SqlErrorException when the raw SQL statement fails in the database * @throws SqlErrorException when the raw SQL statement fails in the database
*/ */
protected function getObjectDataByRawQuery(Qom\Statement $statement) protected function getObjectDataByRawQuery(Qom\Statement $statement): array
{ {
$realStatement = $statement->getStatement(); $realStatement = $statement->getStatement();
$parameters = $statement->getBoundVariables(); $parameters = $statement->getBoundVariables();
...@@ -435,7 +431,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -435,7 +431,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
* @throws BadConstraintException * @throws BadConstraintException
* @throws SqlErrorException * @throws SqlErrorException
*/ */
public function getObjectCountByQuery(QueryInterface $query) public function getObjectCountByQuery(QueryInterface $query): int
{ {
if ($query->getConstraint() instanceof Qom\Statement) { if ($query->getConstraint() instanceof Qom\Statement) {
throw new BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045); throw new BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045);
...@@ -448,6 +444,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface ...@@ -448,6 +444,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
$rows = $this->getObjectDataByQuery($query); $rows = $this->getObjectDataByQuery($query);
$count = count($rows); $count = count($rows);