Skip to content

Commit

Permalink
[TASK] Raise phpstan to level 5 and fix issues within Classes/
Browse files Browse the repository at this point in the history
This change contains fixes for PHPStan issues inside of Classes/ folder in nested level 5.

Byside of that PHPStan requires `/** @var TYPE $variavle */ to resolve the type properly.
So all accurences `/* @var ` are replaced with `/** @var `
  • Loading branch information
dkd-kaehm committed May 31, 2023
1 parent f0c3d6c commit d9e4f9d
Show file tree
Hide file tree
Showing 146 changed files with 302 additions and 287 deletions.
1 change: 1 addition & 0 deletions Build/Test/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ parameters:
- '#^Method .*\\QueryBuilder::use.*FromTypoScript\(\) should return .*\\QueryBuilder but returns .*\\AbstractQueryBuilder.#'
- '#^Access to protected property .*\\PageRepository::\$where_groupAccess.#'
- '#^Unreachable statement - code above always terminates.#'
- '#^Parameter \#1 \$queryAlternative of method .*\\DisMax::setQueryAlternative\(\) expects string, null given.#'
4 changes: 2 additions & 2 deletions Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function getAccessRootlineByPageId(
int $pageId,
string $mountPointParameter = ''
): Rootline {
/* @var Rootline $accessRootline */
/** @var Rootline $accessRootline */
$accessRootline = GeneralUtility::makeInstance(Rootline::class);
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPointParameter);
try {
Expand All @@ -149,7 +149,7 @@ public static function getAccessRootlineByPageId(
}
}

/* @var PageRepository $pageSelector */
/** @var PageRepository $pageSelector */
$pageSelector = GeneralUtility::makeInstance(PageRepository::class);

// current page
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/CoreSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function renderSelectCheckbox(array $items, array $selectedValues): st
'fieldTSConfig' => ['noMatchingValue_label' => ''],
];

/* @var NodeFactory $nodeFactory */
/** @var NodeFactory $nodeFactory */
$nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
$options = [
'renderType' => 'selectCheckBox',
Expand Down
4 changes: 2 additions & 2 deletions Classes/Backend/IndexingConfigurationSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function getIndexQueueConfigurationTableMap(): array
protected function buildSelectorItems(array $tablesToIndex): array
{
$selectorItems = [];
/* @var IconRegistry $iconRegistry */
/** @var IconRegistry $iconRegistry */
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$defaultIcon = 'mimetypes-other-other';
Expand Down Expand Up @@ -189,7 +189,7 @@ protected function renderSelectCheckbox(array $items, ?array $selectedValues = [
'fieldTSConfig' => ['noMatchingValue_label' => ''],
];

/* @var NodeFactory $nodeFactory */
/** @var NodeFactory $nodeFactory */
$nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
$options = [
'type' => 'select', 'renderType' => 'selectCheckBox',
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/SettingsPreviewOnPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function getPreviewContent(): string
{
$this->collectSummary();

/* @var StandaloneView $standaloneView */
/** @var StandaloneView $standaloneView */
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
$standaloneView->setTemplatePathAndFilename(
GeneralUtility::getFileAbsFileName('EXT:solr/Resources/Private/Templates/Backend/PageModule/Summary.html')
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/SiteSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getAvailableSitesSelector(
$selectedAttribute = ' selected="selected"';
}

$selector .= '<option value="' . htmlspecialchars($site->getRootPageId()) . '"' . $selectedAttribute . '>'
$selector .= '<option value="' . htmlspecialchars((string)$site->getRootPageId()) . '"' . $selectedAttribute . '>'
. htmlspecialchars($site->getLabel())
. '</option>';
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function render($conf = [])
$data = $this->cObj->stdWrap($data, $conf);
}
$classifications = $this->buildClassificationsFromConfiguration($configuredMappedClasses);
/* @var ClassificationService $classificationService */
/** @var ClassificationService $classificationService */
$classificationService = GeneralUtility::makeInstance(ClassificationService::class);

return serialize($classificationService->getMatchingClassNames((string)$data, $classifications));
Expand Down
4 changes: 2 additions & 2 deletions Classes/ContentObject/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected function getRelatedItemsFromForeignTable(
$foreignTableLabelField = $this->resolveForeignTableLabelField($foreignTableTca);
$localField = $this->configuration['localField'];

/* @var RelationHandler $relationHandler */
/** @var RelationHandler $relationHandler */
$relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
if (!empty($localFieldTca['config']['MM'] ?? '')) {
$relationHandler->start(
Expand Down Expand Up @@ -367,7 +367,7 @@ protected function resolveRelatedValue(
*/
protected function getRelatedRecords(string $foreignTable, int ...$uids): array
{
/* @var QueryBuilder $queryBuilder */
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($foreignTable);
$queryBuilder->select('*')
->from($foreignTable)
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/AbstractBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function initializeAction(): void
if ($this->resetConfigurationBeforeInitialize) {
$this->solrConfigurationManager->reset();
}
/* @var TypoScriptService $typoScriptService */
/** @var TypoScriptService $typoScriptService */
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);

// Merge settings done by typoscript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr)
Expand Down Expand Up @@ -189,7 +189,7 @@ protected function getSearchRequestBuilder(): SearchRequestBuilder
protected function logSolrUnavailable(): void
{
if ($this->typoScriptConfiguration->getLoggingExceptions()) {
/* @var SolrLogManager $logger */
/** @var SolrLogManager $logger */
$logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
$logger->log(SolrLogManager::ERROR, 'Solr server is not available');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function initializeView(ViewInterface $view): void
return;
}

/* @var BackendUserAuthentication $beUser */
/** @var BackendUserAuthentication $beUser */
$beUser = $GLOBALS['BE_USER'];
$permissionClause = $beUser->getPagePermsClause(1);
$pageRecord = BackendUtility::readPageAccess($this->selectedSite->getRootPageId(), $permissionClause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function emptyIndexAction(): ResponseInterface
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite);
foreach ($solrServers as $solrServer) {
$writeService = $solrServer->getWriteService();
/* @var SolrConnection $solrServer */
/** @var SolrConnection $solrServer */
$writeService->deleteByQuery('siteHash:' . $siteHash);
$writeService->commit(false, false);
$affectedCores[] = $writeService->getPrimaryEndpoint()->getCore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function showErrorAction(int $indexQueueItemId): ResponseInterface
*/
public function doIndexingRunAction(): ResponseInterface
{
/* @var IndexService $indexService */
/** @var IndexService $indexService */
$indexService = GeneralUtility::makeInstance(IndexService::class, $this->selectedSite);
$indexWithoutErrors = $indexService->indexItems(1);

Expand Down
9 changes: 6 additions & 3 deletions Classes/Controller/Backend/Search/InfoModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function indexAction(): ResponseInterface
* Renders the details of Apache Solr documents
*
* @noinspection PhpUnused
* @throws DBALException
*/
public function documentsDetailsAction(string $type, int $uid, int $pageId, int $languageUid): ResponseInterface
{
Expand All @@ -90,7 +91,7 @@ protected function collectConnectionInfos(): void
$missingHosts = [];
$invalidPaths = [];

/* @var Path $path */
/** @var Path $path */
$path = GeneralUtility::makeInstance(Path::class);
$connections = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite);

Expand Down Expand Up @@ -142,7 +143,7 @@ protected function collectStatistics(): void
$queriesDays = (int)($statisticsConfig['queries.']['days'] ?? 30);

$siteRootPageId = $this->selectedSite->getRootPageId();
/* @var StatisticsRepository $statisticsRepository */
/** @var StatisticsRepository $statisticsRepository */
$statisticsRepository = GeneralUtility::makeInstance(StatisticsRepository::class);

$this->view->assign(
Expand Down Expand Up @@ -207,7 +208,7 @@ protected function collectIndexFieldsInfo(): void
if ($coreAdmin->ping()) {
$lukeData = $coreAdmin->getLukeMetaData();

/* @var Registry $registry */
/** @var Registry $registry */
$registry = GeneralUtility::makeInstance(Registry::class);
$limit = $registry->get('tx_solr', 'luke.limit', 20000);
$limitNote = '';
Expand Down Expand Up @@ -243,6 +244,8 @@ protected function collectIndexFieldsInfo(): void

/**
* Retrieves the information for the index inspector.
*
* @throws DBALException
*/
protected function collectIndexInspectorInfo(): void
{
Expand Down
8 changes: 4 additions & 4 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function resultsAction(): ResponseInterface
$pagination = GeneralUtility::makeInstance(ResultsPagination::class, $paginator);
$pagination->setMaxPageNumbers($this->typoScriptConfiguration->getMaxPaginatorLinks());

/* @var AfterSearchEvent $afterSearchEvent */
/** @var AfterSearchEvent $afterSearchEvent */
$afterSearchEvent = $this->eventDispatcher->dispatch(
new AfterSearchEvent(
$searchResultSet,
Expand Down Expand Up @@ -166,7 +166,7 @@ public function formAction(): ResponseInterface
return $this->handleSolrUnavailable();
}

/* @var FormEvent $formEvent */
/** @var FormEvent $formEvent */
$formEvent = $this->eventDispatcher->dispatch(
new FormEvent(
$this->searchService->getSearch(),
Expand All @@ -193,7 +193,7 @@ public function formAction(): ResponseInterface
*/
public function frequentlySearchedAction(): ResponseInterface
{
/* @var SearchResultSet $searchResultSet */
/** @var SearchResultSet $searchResultSet */
$searchResultSet = GeneralUtility::makeInstance(SearchResultSet::class);

$pageId = $this->typoScriptFrontendController->getRequestedId();
Expand All @@ -203,7 +203,7 @@ public function frequentlySearchedAction(): ResponseInterface

$this->view->getRenderingContext()->getVariableProvider()->add('searchResultSet', $searchResultSet);

/* @var AfterFrequentlySearchedEvent $afterFrequentlySearchedEvent*/
/** @var AfterFrequentlySearchedEvent $afterFrequentlySearchedEvent*/
$afterFrequentlySearchedEvent = $this->eventDispatcher->dispatch(
new AfterFrequentlySearchedEvent(
$searchResultSet,
Expand Down
4 changes: 3 additions & 1 deletion Classes/Controller/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrUnavailableException;
use ApacheSolrForTypo3\Solr\Util;
use Doctrine\DBAL\Exception as DBALException;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -37,6 +38,7 @@ class SuggestController extends AbstractBaseController
* This method creates a suggest json response that can be used in a suggest layer.
*
* @throws AspectNotFoundException
* @throws DBALException
* @throws InvalidFacetPackageException
* @throws NoSolrConnectionFoundException
*
Expand All @@ -52,7 +54,7 @@ public function suggestAction(string $queryString, ?string $callback = null, ?ar
}

try {
/* @var SuggestService $suggestService */
/** @var SuggestService $suggestService */
$suggestService = GeneralUtility::makeInstance(
SuggestService::class,
$this->typoScriptFrontendController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function deleteIndexDocuments(string $table, int $uid, int $language =
foreach ($indexQueueItems as $indexQueueItem) {
try {
$site = $indexQueueItem->getSite();
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
$this->queue->deleteItem($indexQueueItem->getType(), $indexQueueItem->getIndexQueueUid());
continue;
}
Expand Down Expand Up @@ -125,6 +125,7 @@ protected function deleteRecordInAllSolrConnections(
$response = $solr->getWriteService()->deleteByQuery($query);

if ($response->getHttpStatus() !== 200) {
/** @var SolrLogManager $logger */
$logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
$logger->log(
SolrLogManager::ERROR,
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Index/Queue/QueueInitializationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function initializeBySitesAndConfigurations(array $sites, array $indexing
{
$initializationStatesBySiteId = [];
foreach ($sites as $site) {
/* @var Site $site */
/** @var Site $site */
$initializationResult = $this->initializeBySiteAndIndexConfigurations($site, $indexingConfigurationNames);
$initializationStatesBySiteId[$site->getRootPageId()] = $initializationResult;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ protected function executeInitializer(
array $indexConfiguration
): bool {
$initializer = GeneralUtility::makeInstance($initializerClass);
/* @var AbstractInitializer $initializer */
/** @var AbstractInitializer $initializer */
$initializer->setSite($site);
$initializer->setType($type);
$initializer->setIndexingConfigurationName($indexingConfigurationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function update(int $pageId): void
return;
}

/* @var Rootline $rootLine */
/** @var Rootline $rootLine */
$rootLine = GeneralUtility::makeInstance(Rootline::class, $rootLineArray);
$rootLineParentPageIds = array_map('intval', $rootLine->getParentPageIds());
$destinationMountProperties = $this->pagesRepository->findMountPointPropertiesByPageIdOrByRootLineParentPageIds($currentPageUid, $rootLineParentPageIds);
Expand All @@ -88,7 +88,7 @@ protected function addPageToMountingSiteIndexQueue(int $mountedPageId, array $mo
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
$mountingSite = $siteRepository->getSiteByPageId($mountProperties['mountPageDestination']);

/* @var Page $pageInitializer */
/** @var Page $pageInitializer */
$pageInitializer = GeneralUtility::makeInstance(Page::class);
$pageInitializer->setSite($mountingSite);
$pageInitializer->setIndexingConfigurationName('pages');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function getResponsibleRootPageIds(string $table, int $uid): array

/**
* Checks if the passed pageId is a root page.
*
* @throws RootPageRecordNotFoundException
*/
public function getIsRootPageId(int $pageId): bool
{
Expand Down Expand Up @@ -136,7 +138,7 @@ public function getRootPageId(
return 0;
}

/* @var Rootline $rootLine */
/** @var Rootline $rootLine */
$rootLine = GeneralUtility::makeInstance(Rootline::class);

// frontend
Expand All @@ -146,7 +148,7 @@ public function getRootPageId(

// fallback, backend
if ($forceFallback || !$rootLine->getHasRootPage()) {
/* @var RootlineUtility $rootlineUtility */
/** @var RootlineUtility $rootlineUtility */
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPointIdentifier);
try {
$rootLineArray = $rootlineUtility->get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function findOneByRootPidAndOptionalIndexingConfigurationName(
*/
protected function buildQueueStatisticFromResultSet(array $indexQueueStatisticResultSet): QueueStatistic
{
/* @var QueueStatistic $statistic */
/** @var QueueStatistic $statistic */
$statistic = GeneralUtility::makeInstance(QueueStatistic::class);
foreach ($indexQueueStatisticResultSet as $row) {
if ($row['failed'] == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function __construct(
*
* @throws DBALException
* @throws UnexpectedTYPO3SiteInitializationException
* @throws RootPageRecordNotFoundException
*/
public function handleContentElementUpdate(int $uid, array $updatedFields = []): void
{
Expand Down Expand Up @@ -164,6 +165,7 @@ public function handleContentElementDeletion(int $uid): void
*
* @throws DBALException
* @throws UnexpectedTYPO3SiteInitializationException
* @throws RootPageRecordNotFoundException
*/
public function handlePageUpdate(int $uid, array $updatedFields = []): void
{
Expand Down Expand Up @@ -352,6 +354,7 @@ protected function getRecordRootPageIds(string $recordTable, int $recordUid): ar
*
* @throws DBALException
* @throws UnexpectedTYPO3SiteInitializationException
* @throws RootPageRecordNotFoundException
*/
protected function processPageRecord(int $uid, int $pid, array $updatedFields = []): void
{
Expand Down Expand Up @@ -437,6 +440,7 @@ protected function processRecord(string $recordTable, int $recordUid, array $roo
* This method is used to determine the pageId that should be used to retrieve the index queue configuration.
*
* @throws UnexpectedTYPO3SiteInitializationException
* @throws RootPageRecordNotFoundException
*/
protected function getConfigurationPageId(string $recordTable, int $recordPageId, int $recordUid): int
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Exception\RootPageRecordNotFoundException;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\ProcessingFinishedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\ContentElementDeletedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\DataUpdateEventInterface;
Expand Down Expand Up @@ -114,6 +115,7 @@ protected function handleRecordMovedEvent(RecordMovedEvent $event): void
*
* @throws DBALException
* @throws UnexpectedTYPO3SiteInitializationException
* @throws RootPageRecordNotFoundException
*
* @noinspection PhpUnused
*/
Expand Down
Loading

0 comments on commit d9e4f9d

Please sign in to comment.