Skip to content

Commit

Permalink
[TASK] Activate PHPStan
Browse files Browse the repository at this point in the history
Activates PHPStan in level 2 and performs
required adaptions for this level.
  • Loading branch information
dkd-friedrich committed Mar 13, 2024
1 parent e9d46c7 commit 176c6f2
Show file tree
Hide file tree
Showing 33 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Build/Test/cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ echo "Run PHPStan analysis"
if ! composer tests:phpstan
then
# disable fail temporary
#EXIT_CODE=7
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"
Expand Down
4 changes: 2 additions & 2 deletions Build/Test/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- %rootDir%/../phpstan-phpunit/extension.neon

parameters:
level: 0
level: 1
treatPhpDocTypesAsCertain: false

bootstrapFiles:
Expand All @@ -17,4 +17,4 @@ parameters:
- %currentWorkingDirectory%/Tests

ignoreErrors:
- '#^Variable \$_EXTKEY might not be defined\.#'
- '#Constructor of class .*\\Sorting has an unused parameter \$resultSet.#'
1 change: 0 additions & 1 deletion Classes/Controller/Backend/PageModuleSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ protected function addSettingFromFlexForm($settingName, $flexFormField)
/**
* @param string $settingName
* @param array $values
* @return bool
*/
protected function addSettingFromFlexFormArray($settingName, $values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function importSynonymListAction(

$coreAdmin = $this->selectedSolrCoreConnection->getAdminService();
foreach ($fileLines as $baseWord => $synonyms) {
if (!isset($baseWord) || empty($synonyms)) {
if (empty($synonyms)) {
continue;
}
$this->deleteExistingSynonym($overrideExisting, $deleteSynonymsBefore, $baseWord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function getRecordForIndexConfigurationIsValid(
$row = (array)BackendUtility::getRecord($recordTable, $recordUid, '*', $recordWhereClause);
$cache->set($cacheId, $row);

return $row ?? [];
return $row;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getForJsonFacet(string $sorting, string $direction): string
{
$isMetricSorting = strpos($sorting, 'metrics_') === 0;
$expression = $isMetricSorting ? $sorting : $this->getForFacet($sorting);
$direction = strtolower($direction ?? '');
$direction = strtolower($direction);
if (!empty($direction) && in_array($direction, ['asc', 'desc'])) {
$expression .= ' ' . $direction;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct(

if (!is_null($typoScriptConfiguration)) {
$additionalPersistentArgumentsNames = $typoScriptConfiguration->getSearchAdditionalPersistentArgumentNames();
foreach ($additionalPersistentArgumentsNames ?? [] as $additionalPersistentArgumentsName) {
foreach ($additionalPersistentArgumentsNames as $additionalPersistentArgumentsName) {
$this->persistentArgumentsPaths[] = $this->argumentNameSpace . ':' . $additionalPersistentArgumentsName;
}
$this->persistentArgumentsPaths = array_unique($this->persistentArgumentsPaths);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/SearchRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function applyPassedResultsPerPage(SearchRequest $searchRequest): Sear
$requestedPerPage = $searchRequest->getResultsPerPage();

$perPageSwitchOptions = $this->typoScriptConfiguration->getSearchResultsPerPageSwitchOptionsAsArray();
if (isset($requestedPerPage) && in_array($requestedPerPage, $perPageSwitchOptions)) {
if (in_array($requestedPerPage, $perPageSwitchOptions)) {
$this->session->setPerPage($requestedPerPage);
$searchRequest->setPage(0);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/Suggest/SuggestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected function getSolrSuggestions(SuggestQuery $suggestQuery): array
$facetSuggestions = isset($suggestConfig['suggestField']) ? $results->facet_counts->facet_fields->{$suggestConfig['suggestField']} ?? [] : [];
$facetSuggestions = ParsingUtil::getMapArrayFromFlatArray($facetSuggestions);

return $facetSuggestions ?? [];
return $facetSuggestions;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Site/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getAvailableSites(bool $stopOnInvalidSite = false): array
$sites = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
$this->runtimeCache->set($cacheId, $sites);

return $sites ?? [];
return $sites;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/IndexQueue/PageIndexerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ protected function getUrl(string $url, array $headers, float $timeout): Response
),
[
'HTTP headers' => $response->getHeaders(),
'options' => $options,
'options' => $options ?? [],
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/System/Util/ArrayAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function resetDeepElementWithLoop(array $pathArray)
if (empty($currentElement)) {
unset($currentElement);
}
} else {
} elseif (isset($currentElement[$pathSegment])) {
$currentElement = &$currentElement[$pathSegment];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_bar',
'title' => 'tx_fakeextension_domain_model_bar',
'descriptionColumn' => 'tag',
'label' => 'title',
'hideAtCopy' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_directrelated',
'title' => 'tx_fakeextension_domain_model_directrelated',
'descriptionColumn' => 'category',
'label' => 'category',
'hideAtCopy' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_mmrelated',
'title' => 'tx_fakeextension_domain_model_mmrelated',
'descriptionColumn' => 'tag',
'label' => 'tag',
'hideAtCopy' => true,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/Fixtures/fake_extension_tca.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_foo',
'title' => 'tx_fakeextension_domain_model_foo',
'descriptionColumn' => 'tag',
'label' => 'title',
'hideAtCopy' => true,
Expand Down
1 change: 1 addition & 0 deletions Tests/Integration/GarbageCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ protected function addToQueueAndIndexRecord($table, $uid): bool
self::assertEquals(1, $updatedItems);

// run the indexer
$result = false;
$items = $this->indexQueue->getItems($table, $uid);
foreach ($items as $item) {
$result = $this->indexer->index($item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_bar',
'title' => 'tx_fakeextension_domain_model_bar',
'descriptionColumn' => 'tag',
'label' => 'title',
'hideAtCopy' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_directrelated',
'title' => 'tx_fakeextension_domain_model_directrelated',
'descriptionColumn' => 'category',
'label' => 'category_label',
'hideAtCopy' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_mmrelated',
'title' => 'tx_fakeextension_domain_model_mmrelated',
'descriptionColumn' => 'tag',
'label' => 'tag',
'hideAtCopy' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'ctrl' => [
'title' => $ll . 'tx_fakeextension_domain_model_foo',
'title' => 'tx_fakeextension_domain_model_foo',
'descriptionColumn' => 'tag',
'label' => 'title',
'hideAtCopy' => true,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/IndexQueue/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function canIndexMultipleMMRelatedItems()
// @extensionScannerIgnoreLine
$tags = $decodedSolrContent->response->docs[0]->tags_stringM;

self::assertSame(['the tag', 'another tag'], $tags, $solrContent, 'Did not find MM related tags');
self::assertSame(['the tag', 'another tag'], $tags, 'Did not find MM related tags');
self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr');
self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr');

Expand Down
1 change: 0 additions & 1 deletion Tests/Integration/Task/IndexQueueDependencyFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static function getRequestId()
* @param string $url
* @param bool $flags
* @param resource $context
* @return string
*/
public static function getHttpContent($url, $flags, $context)
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function setUp(): void
$GLOBALS['TSFE'] = $TSFE;

/** @var $GLOBALS ['TSFE']->tmpl \TYPO3\CMS\Core\TypoScript\TemplateService */
$GLOBALS['TSFE']->tmpl = $this->getDumbMock(TemplateService::class, ['linkData']);
$GLOBALS['TSFE']->tmpl = $this->getDumbMock(TemplateService::class);
$GLOBALS['TSFE']->tmpl->getFileName_backPath = Environment::getPublicPath() . '/';
$GLOBALS['TSFE']->tmpl->setup['config.']['typolinkEnableLinksAcrossDomains'] = 0;
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['solr.']['host'] = 'localhost';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DataUpdateHandlerTest extends AbstractUpdateHandlerTest
/**
* @var SolrLogManager|MockObject
*/
protected $solrLogManagerMock;
protected $loggerMock;

protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
abstract class AbstractProcessingFinishedEventTest extends UnitTest
{
protected const EVENT_CLASS = 'stdClass';

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
abstract class AbstractDataUpdateEventTest extends UnitTest
{
protected const EVENT_CLASS = AbstractDataUpdateEvent::class;
protected const EVENT_TEST_TABLE = 'tx_foo_bar';

/**
* @return AbstractDataUpdateEventTest
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ContentElementDeletedEventTest extends AbstractDataUpdateEventTest
*/
public function canInitAndReturnFields(): void
{
$event = new ContentElementDeletedEvent(123, static::EVENT_TEST_TABLE, ['hidden' => 1]);
$event = new ContentElementDeletedEvent(123);
self::assertEmpty($event->getFields());
}

Expand All @@ -41,7 +41,7 @@ public function canInitAndReturnFields(): void
*/
public function canForceTable(): void
{
$event = new ContentElementDeletedEvent(123, 'tx_foo_bar');
$event = new ContentElementDeletedEvent(123);
self::assertEquals('tt_content', $event->getTable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PageMovedEventTest extends AbstractDataUpdateEventTest
*/
public function canInitAndReturnFields(): void
{
$event = new PageMovedEvent(123, static::EVENT_TEST_TABLE, ['hidden' => 1]);
$event = new PageMovedEvent(123);
self::assertEmpty($event->getFields());
}

Expand All @@ -41,7 +41,7 @@ public function canInitAndReturnFields(): void
*/
public function canForceTable(): void
{
$event = new PageMovedEvent(123, 'tx_foo_bar');
$event = new PageMovedEvent(123);
self::assertEquals('pages', $event->getTable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacet;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItemCollection;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy\NodeCollection;

class TestFacet extends AbstractFacet
{
/**
* The implementation of this method should return a "flatten" collection of all items.
*
* @return AbstractFacetItemCollection
*/
public function getAllFacetItems(): AbstractFacetItemCollection
{
// TODO: Implement getAllFacetItems() method.
return new NodeCollection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestParser extends AbstractFacetParser
* @param array $facetConfiguration
* @return AbstractFacet|null
*/
public function parse(SearchResultSet $resultSet, string $facetName, array $facetConfiguration)
public function parse(SearchResultSet $resultSet, string $facetName, array $facetConfiguration): ?AbstractFacet
{
return new TestFacet($resultSet, $facetName, 'testField');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function canWriteExpectedStatisticsData()
$resultSetMock->expects(self::once())->method('getUsedQuery')->willReturn($this->queryMock);
$resultSetMock->expects(self::once())->method('getUsedSearchRequest')->willReturn($this->searchRequestMock);

$self = $this;
$this->statisticsRepositoryMock->expects(self::any())->method('saveStatisticsRecord')->willReturnCallback(function ($statisticData) use ($self) {
$this->statisticsRepositoryMock->expects(self::any())->method('saveStatisticsRecord')->willReturnCallback(function ($statisticData) {
$this->assertSame('my search', $statisticData['keywords'], 'Unexpected keywords given');
$this->assertSame('192.168.2.22', $statisticData['ip'], 'Unexpected ip given');
$this->assertSame(4711, $statisticData['root_pid'], 'Unexpected root pid given');
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/IndexQueue/AbstractIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function isSerializedValueCanHandleCustomValidSerializedValueDetector()
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'topic_stringM'), 'Every value should be treated as serialized by custom detector');
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'csv_stringM'), 'Every value should be treated as serialized by custom detector');
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'categories_stringM'), 'Every value should be treated as serialized by custom detector');
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'category_stringM', 'Every value should be treated as serialized by custom detector'));
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'notConfigured_stringM', 'Every value should be treated as serialized by custom detector'));
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'category_stringM'), 'Every value should be treated as serialized by custom detector');
self::assertTrue(AbstractIndexer::isSerializedValue($indexingConfiguration, 'notConfigured_stringM'), 'Every value should be treated as serialized by custom detector');
}

/**
Expand Down

0 comments on commit 176c6f2

Please sign in to comment.