Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Integrate phpstan #3639

Merged
merged 9 commits into from
May 26, 2023
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/.dockerignore export-ignore
/.gitattributes export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/.styleci.yml export-ignore
/Dockerfile export-ignore
/CONTRIBUTING.md export-ignore
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ jobs:
${{ env.CI_BUILD_DIRECTORY }}/bin
${{ env.CI_BUILD_DIRECTORY }}/vendor
${{ env.COMPOSER_GLOBAL_REQUEREMENTS }}
composer.json
composer.lock
key: ${{ env.CI_BUILD_CACHE_KEY }}
-
name: CI-Bootstrap
Expand Down
40 changes: 3 additions & 37 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ filter:

tools:
php_cpd:
enabled: true
enabled: false

# we do this on GitHub-Actions via typo3/coding-standards
php_code_sniffer:
Expand All @@ -19,45 +19,11 @@ tools:
enabled: false

php_mess_detector:
enabled: true
config:
controversial_rules:
superglobals: false
enabled: false

php_pdepend:
enabled: true

php_analyzer:
enabled: true
dependency_paths:
- 'Resources/Private/Php/*'
enabled: false

external_code_coverage:
runs: 2
timeout: 2400

checks:
php:
excluded_dependencies:
- typo3/cms-install
avoid_superglobals: false

build_failure_conditions:
- 'patches.label("Doc Comments").count > 10'
- 'patches.label("Spacing").count > 15'
- 'issues.label("coding-style").count > 10'
- 'issues.severity(>= MAJOR).count > 260'
- 'project.metric("scrutinizer.quality", < 8)'
- 'project.metric_change("scrutinizer.test_coverage", < -0.10)'


build:
environment:
php:
# We want to test with the smallest supported TYPO3 PHP version
version: 8.1
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
9 changes: 9 additions & 0 deletions Build/Test/cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ else
fi
fi

echo -e "\n\n"
echo "Run PHPStan analysis"
if ! composer tests:phpstan
then
EXIT_CODE=7
echo "Error during running the PHPStan analysis, please check and fix them."
echo "Tip for working on them: "
echo " TYPO3_VERSION="${TYPO3_VERSION}" composer tests:setup && composer tests:phpstan"
fi

echo -e "\n\n"
echo "Run unit tests"
Expand Down
5 changes: 5 additions & 0 deletions Build/Test/phpstan-constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// testing-framework defines this, used in various tests.
define('ORIGINAL_ROOT', dirname(__FILE__, 2) . '/');
define('LF', "\n");
23 changes: 23 additions & 0 deletions Build/Test/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
includes:
- ../../.Build/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 3
treatPhpDocTypesAsCertain: false

bootstrapFiles:
- phpstan-constants.php

universalObjectCratesClasses:
- ApacheSolrForTypo3\Solr\System\Solr\Document\Document
- ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResult

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests

ignoreErrors:
- '#^Variable \$_EXTKEY might not be defined\.#'
- '#^Method .*\\QueryBuilder::buildSuggestQuery\(\) should return .*\\SuggestQuery but returns .*\\Search\\Query\\Query\|null.#'
- '#^Method .*\\QueryBuilder::use.*FromTypoScript\(\) should return .*\\QueryBuilder but returns .*\\AbstractQueryBuilder.#'
- '#^Access to protected property .*\\PageRepository::\$where_groupAccess.#'
4 changes: 1 addition & 3 deletions Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(string $accessRootline = null)
$rawRootlineElements = explode(self::ELEMENT_DELIMITER, $accessRootline);
foreach ($rawRootlineElements as $rawRootlineElement) {
try {
$this->push(GeneralUtility::makeInstance(RootlineElement::class, /** @scrutinizer ignore-type */ $rawRootlineElement));
$this->push(GeneralUtility::makeInstance(RootlineElement::class, $rawRootlineElement));
} catch (RootlineElementFormatException) {
// just ignore the faulty element for now, might log this later
}
Expand Down Expand Up @@ -144,7 +144,6 @@ public static function getAccessRootlineByPageId(
) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */
$pageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $pageRecord['fe_group']
));
}
Expand All @@ -158,7 +157,6 @@ public static function getAccessRootlineByPageId(
if ($currentPageRecord['fe_group']) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */
$currentPageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $currentPageRecord['fe_group']
));
}
Expand Down
3 changes: 0 additions & 3 deletions Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,9 @@ protected function throwExceptionOnInvalidSite(?Site $site, string $message): vo
*/
protected function buildNoConnectionException(string $message): NoSolrConnectionFoundException
{
/* @var NoSolrConnectionFoundException $noSolrConnectionException */
return GeneralUtility::makeInstance(
NoSolrConnectionFoundException::class,
/** @scrutinizer ignore-type */
$message,
/** @scrutinizer ignore-type */
1575396474
);
}
Expand Down
3 changes: 0 additions & 3 deletions Classes/ContentObject/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ protected function buildClassificationsFromConfiguration(array $configuredMapped
$className = $class['class'];
$classifications[] = GeneralUtility::makeInstance(
ClassificationItem::class,
/** @scrutinizer ignore-type */
$matchPatterns,
/** @scrutinizer ignore-type */
$unMatchPatters,
/** @scrutinizer ignore-type */
$className
);
}
Expand Down
1 change: 0 additions & 1 deletion Classes/ContentObject/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function render($conf = [])
{
$contentExtractor = GeneralUtility::makeInstance(
HtmlContentExtractor::class,
/** @scrutinizer ignore-type */
$this->getRawContent($this->cObj, $conf)
);

Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected function getRelatedRecords(string $foreignTable, int ...$uids): array
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($foreignTable);
$queryBuilder->select('*')
->from($foreignTable)
->where(/** @scrutinizer ignore-type */ $queryBuilder->expr()->in('uid', $uids));
->where($queryBuilder->expr()->in('uid', $uids));
if (isset($this->configuration['additionalWhereClause'])) {
$queryBuilder->andWhere($this->configuration['additionalWhereClause']);
}
Expand Down
6 changes: 2 additions & 4 deletions Classes/Controller/AbstractBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ protected function initializeSearch(): void

$this->searchService = GeneralUtility::makeInstance(
SearchResultSetService::class,
/** @scrutinizer ignore-type */
$this->typoScriptConfiguration,
/** @scrutinizer ignore-type */
$search
);
} catch (NoSolrConnectionFoundException) {
Expand All @@ -179,7 +177,7 @@ protected function initializeSearch(): void
protected function getSearchRequestBuilder(): SearchRequestBuilder
{
if ($this->searchRequestBuilder === null) {
$this->searchRequestBuilder = GeneralUtility::makeInstance(SearchRequestBuilder::class, /** @scrutinizer ignore-type */ $this->typoScriptConfiguration);
$this->searchRequestBuilder = GeneralUtility::makeInstance(SearchRequestBuilder::class, $this->typoScriptConfiguration);
}

return $this->searchRequestBuilder;
Expand All @@ -192,7 +190,7 @@ protected function logSolrUnavailable(): void
{
if ($this->typoScriptConfiguration->getLoggingExceptions()) {
/* @var SolrLogManager $logger */
$logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$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 @@ -147,7 +147,7 @@ public function importSynonymListAction(

$coreAdmin = $this->selectedSolrCoreConnection->getAdminService();
foreach ($fileLines as $baseWord => $synonyms) {
if (!isset($baseWord) || empty($synonyms)) {
if (empty($baseWord) || empty($synonyms)) {
continue;
}
$this->deleteExistingSynonym($overrideExisting, $deleteSynonymsBefore, $baseWord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function canQueueSelectedSite(): bool
*/
protected function getIndexQueueInitializationSelector(): string
{
$selector = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, /** @scrutinizer ignore-type */ $this->selectedSite);
$selector = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, $this->selectedSite);
$selector->setFormElementName('tx_solr-index-queue-initialization');

return $selector->render();
Expand Down Expand Up @@ -229,7 +229,7 @@ public function showErrorAction(int $indexQueueItemId): ResponseInterface
public function doIndexingRunAction(): ResponseInterface
{
/* @var IndexService $indexService */
$indexService = GeneralUtility::makeInstance(IndexService::class, /** @scrutinizer ignore-type */ $this->selectedSite);
$indexService = GeneralUtility::makeInstance(IndexService::class, $this->selectedSite);
$indexWithoutErrors = $indexService->indexItems(1);

$label = 'solr.backend.index_queue_module.flashmessage.success.index_manual';
Expand Down
6 changes: 2 additions & 4 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
use TYPO3Fluid\Fluid\View\ViewInterface;

/**
* Class SearchController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
* @property AbstractTemplateView $view {@link AbstractTemplateView} is used in this scope. Line required by PhpStan.
*/
class SearchController extends AbstractBaseController
{
protected $view;

/**
* Provide search query in extbase arguments.
*/
Expand Down
3 changes: 0 additions & 3 deletions Classes/Controller/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ public function suggestAction(string $queryString, ?string $callback = null, ?ar
/* @var SuggestService $suggestService */
$suggestService = GeneralUtility::makeInstance(
SuggestService::class,
/** @scrutinizer ignore-type */
$this->typoScriptFrontendController,
/** @scrutinizer ignore-type */
$this->searchService,
/** @scrutinizer ignore-type */
$this->typoScriptConfiguration
);

Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Index/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(
$this->site = $site;
$this->indexQueue = $queue ?? GeneralUtility::makeInstance(Queue::class);
$this->eventDispatcher = $eventDispatcher ?? GeneralUtility::makeInstance(EventDispatcherInterface::class);
$this->logger = $solrLogManager ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$this->logger = $solrLogManager ?? GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
}

public function setContextTask(IndexQueueWorkerTask $contextTask): void
Expand Down Expand Up @@ -195,7 +195,7 @@ protected function getIndexerByItem(
$indexerClass = $configuration->getIndexQueueIndexerByConfigurationName($indexingConfigurationName);
$indexerConfiguration = $configuration->getIndexQueueIndexerConfigurationByConfigurationName($indexingConfigurationName);

$indexer = GeneralUtility::makeInstance($indexerClass, /** @scrutinizer ignore-type */ $indexerConfiguration);
$indexer = GeneralUtility::makeInstance($indexerClass, $indexerConfiguration);
if (!($indexer instanceof Indexer)) {
throw new RuntimeException(
'The indexer class "' . $indexerClass . '" for indexing configuration "' . $indexingConfigurationName . '" is not a valid indexer. Must be a subclass of ApacheSolrForTypo3\Solr\IndexQueue\Indexer.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class AbstractUriStrategy
public function __construct(
SolrLogManager $logger = null
) {
$this->logger = $logger ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$this->logger = $logger ?? GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
}

protected function applyTypoScriptOverridesOnIndexingUrl(UrlHelper $urlHelper, array $overrideConfiguration = []): UrlHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function deleteRecordInAllSolrConnections(
$response = $solr->getWriteService()->deleteByQuery($query);

if ($response->getHttpStatus() !== 200) {
$logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
$logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
$logger->log(
SolrLogManager::ERROR,
'Couldn\'t delete index document',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public function removeByRootPidAndIndexQueueUid(int $rootPid, int $indexQueueUid
return $queryBuilder
->delete($this->table)
->where(
/** @scrutinizer ignore-type */
$queryBuilder->expr()->eq(
'root',
$queryBuilder->createNamedParameter($rootPid, PDO::PARAM_INT)
),
/** @scrutinizer ignore-type */
$queryBuilder->expr()->eq(
'item_id',
$queryBuilder->createNamedParameter($indexQueueUid, PDO::PARAM_INT)
Expand Down Expand Up @@ -71,7 +69,6 @@ public function findAllByIndexQueueUid(int $indexQueueUid): array
->select('property_key', 'property_value')
->from($this->table)
->where(
/** @scrutinizer ignore-type */
$queryBuilder->expr()->eq(
'item_id',
$queryBuilder->createNamedParameter($indexQueueUid, PDO::PARAM_INT)
Expand Down