[TASK] Improve code to avoid Scrutinizer warnings 05/58505/5
authorMarkus Klein <markus.klein@typo3.org>
Sun, 30 Sep 2018 16:23:40 +0000 (18:23 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 1 Oct 2018 13:34:55 +0000 (15:34 +0200)
Releases: master
Resolves: #86481
Change-Id: I87b9a07b6cc10c4379a6bf3e1c0e1695354b574a
Reviewed-on: https://review.typo3.org/58505
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Stephan GroƟberndt <stephan.grossberndt@typo3.org>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jan Stockfisch <typo3@jan-stockfisch.de>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php

index 21cf921..dfcac6b 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
 use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
@@ -22,7 +23,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
  * A proxy that can replace any object and replaces itself in it's parent on
  * first access (call, get, set, isset, unset).
  */
-class LazyLoadingProxy implements \Iterator, \TYPO3\CMS\Extbase\Persistence\Generic\LoadingStrategyInterface
+class LazyLoadingProxy implements \Iterator, LoadingStrategyInterface
 {
     /**
      * @var ?DataMapper
@@ -99,7 +100,10 @@ class LazyLoadingProxy implements \Iterator, \TYPO3\CMS\Extbase\Persistence\Gene
         // this check safeguards against a proxy being activated multiple times
         // usually that does not happen, but if the proxy is held from outside
         // its parent ... the result would be weird.
-        if ($this->parentObject->_getProperty($this->propertyName) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
+        if ($this->parentObject instanceof AbstractDomainObject
+            && $this->parentObject->_getProperty($this->propertyName) instanceof LazyLoadingProxy
+            && $this->dataMapper
+        ) {
             $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false);
             $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
             $this->parentObject->_setProperty($this->propertyName, $propertyValue);
index 147d68f..e727a1d 100644 (file)
@@ -441,7 +441,7 @@ class DataMapper
         $columnMap = $dataMap->getColumnMap($propertyName);
         $type = $this->getType(get_class($parentObject), $propertyName);
         $query = $this->queryFactory->create($type);
-        if ($this->query) {
+        if ($this->query && $query instanceof Persistence\Generic\Query) {
             $query->setParentQuery($this->query);
         }
         $query->getQuerySettings()->setRespectStoragePage(false);
index accdecd..fcff438 100644 (file)
@@ -30,6 +30,7 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractValueObject;
 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
 use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
+use TYPO3\CMS\Extbase\Persistence\Generic\Query;
 use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException;
@@ -643,9 +644,10 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      *
      * @param Qom\SourceInterface $source The source (selector or join)
      * @param array $rows
-     * @param QueryInterface $querySettings The TYPO3 CMS specific query settings
+     * @param QueryInterface $query
      * @param int|null $workspaceUid
      * @return array
+     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
      */
     protected function overlayLanguageAndWorkspace(Qom\SourceInterface $source, array $rows, QueryInterface $query, int $workspaceUid = null): array
     {
@@ -707,7 +709,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
                     $languageUid = (int)$querySettings->getLanguageUid();
                     if (!$querySettings->getRespectSysLanguage()
                         && isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']]) > 0
-                        && !$query->getParentQuery()) {
+                        && (!$query instanceof Query || !$query->getParentQuery())) {
                         //we're mapping the aggregate root.
                         $languageUid = $row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']];
                     }
index 65c44fa..05c7546 100644 (file)
@@ -23,7 +23,7 @@ use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
+use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException;
@@ -561,7 +561,7 @@ class Typo3DbQueryParser
     {
         $consistentHandlingEnabled = $this->configurationManager->isFeatureEnabled('consistentTranslationOverlayHandling');
         if ($consistentHandlingEnabled
-            && $value instanceof DomainObjectInterface
+            && $value instanceof AbstractDomainObject
             && $value->_hasProperty('_localizedUid')
             && $value->_getProperty('_localizedUid') > 0
         ) {