Commit 074cb535 authored by crell's avatar crell Committed by Stefan Bürk
Browse files

[TASK] Remove dead code paths identified by PHPStan

According to PHPStan, these checks are all unnecessary.
Most of them appear to be type checks that have been
rendered unnecessary due later type additions. They
are therefore removed without replacement.

Used command:

> Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Resolves: #97622
Releases: main, 11.5
Change-Id: I9aac41e98b22fcce55afb97f8aeaebe3209a8bfb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74637


Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 6f3d45da
......@@ -35,11 +35,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/File/FileController.php
-
message: "#^Strict comparison using \\=\\=\\= between TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/File/ThumbnailController.php
-
message: "#^Strict comparison using \\=\\=\\= between int and '' will always evaluate to false\\.$#"
count: 2
......@@ -380,11 +375,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Authentication/IpLocker.php
-
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<int, string\\> and false will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Authentication/IpLocker.php
-
message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, array given\\.$#"
count: 4
......@@ -615,11 +605,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Database/Connection.php
-
message: "#^Strict comparison using \\=\\=\\= between int and false will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Database/Connection.php
-
message: "#^Parameter \\#4 \\$condition of method Doctrine\\\\DBAL\\\\Query\\\\QueryBuilder\\:\\:leftJoin\\(\\) expects string\\|null, TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\CompositeExpression given\\.$#"
count: 1
......@@ -1025,11 +1010,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Page/PageRenderer.php
-
message: "#^Strict comparison using \\=\\=\\= between array\\{settings\\?\\: non\\-empty\\-array, lang\\?\\: non\\-empty\\-array\\}&non\\-empty\\-array and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Page/PageRenderer.php
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\AbstractFile\\:\\:copyTo\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File but returns TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface\\.$#"
count: 1
......@@ -2105,11 +2085,6 @@ parameters:
count: 2
path: ../../typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
-
message: "#^Strict comparison using \\=\\=\\= between array and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Site\\\\SiteFinder\\:\\:method\\(\\)\\.$#"
count: 2
......@@ -2210,11 +2185,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Domain/Model/FileReference.php
-
message: "#^Strict comparison using \\=\\=\\= between TYPO3\\\\CMS\\\\Extbase\\\\Error\\\\Result and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php
-
message: "#^Parameter \\#2 \\$optionKey of method TYPO3\\\\CMS\\\\Extbase\\\\Property\\\\PropertyMappingConfiguration\\:\\:setTypeConverterOption\\(\\) expects string, int given\\.$#"
count: 3
......@@ -2295,11 +2265,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php
-
message: "#^Strict comparison using \\=\\=\\= between int and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php
-
message: "#^Property TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\Mapper\\\\ColumnMap\\:\\:\\$relationTableWhereStatement is unused\\.$#"
count: 1
......@@ -3105,11 +3070,6 @@ parameters:
count: 1
path: ../../typo3/sysext/fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php
-
message: "#^Strict comparison using \\=\\=\\= between array\\<TYPO3\\\\CMS\\\\Core\\\\Messaging\\\\FlashMessage\\> and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php
-
message: "#^Call to an undefined method TYPO3Fluid\\\\Fluid\\\\Core\\\\Rendering\\\\RenderingContextInterface\\:\\:getRequest\\(\\)\\.$#"
count: 1
......@@ -3950,11 +3910,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/Variables.php
-
message: "#^Strict comparison using \\=\\=\\= between array\\<TYPO3\\\\CMS\\\\Frontend\\\\Tests\\\\Functional\\\\SiteHandling\\\\Framework\\\\Builder\\\\Applicable\\> and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/VariablesContext.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
......@@ -4340,11 +4295,6 @@ parameters:
count: 1
path: ../../typo3/sysext/install/Classes/Updates/BackendUserLanguageMigration.php
-
message: "#^Strict comparison using \\=\\=\\= between Doctrine\\\\DBAL\\\\Schema\\\\AbstractSchemaManager and null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/install/Classes/Updates/ShortcutRecordsMigration.php
-
message: "#^Call to an undefined method Psr\\\\Container\\\\ContainerInterface\\:\\:set\\(\\)\\.$#"
count: 1
......
......@@ -92,7 +92,7 @@ class ThumbnailController
protected function generateThumbnail($fileId, array $configuration): ResponseInterface
{
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileId);
if ($file === null || $file->isMissing()) {
if ($file->isMissing()) {
return $this->generateNotFoundResponse();
}
......
......@@ -79,9 +79,7 @@ class IpLocker
$numberOfParts = MathUtility::forceIntegerInRange($numberOfParts, 1, $maxParts);
$ipParts = explode($delimiter, $ipAddress);
if ($ipParts === false) {
return $ipAddress;
}
for ($a = $maxParts; $a > $numberOfParts; $a--) {
$ipPartValue = $delimiter === '.' ? '0' : str_pad('', strlen($ipParts[$a - 1]), '0');
$ipParts[$a - 1] = $ipPartValue;
......
......@@ -101,9 +101,7 @@ class Connection extends \Doctrine\DBAL\Connection implements LoggerAwareInterfa
}
foreach ($this->prepareConnectionCommands as $command) {
if ($this->executeStatement($command) === false) {
$this->logger->critical('Could not initialize DB connection with query: {query}', ['query' => $command]);
}
$this->executeStatement($command);
}
return true;
......
......@@ -2051,7 +2051,7 @@ class PageRenderer implements SingletonInterface
sprintf(
'Object.fromEntries(Object.entries(%s).filter((entry) => '
. "!['__proto__', 'prototype', 'constructor'].includes(entry[0])))",
json_encode($assignments === [] ? new \stdClass() : $assignments)
json_encode($assignments)
),
$this->inlineJavascriptWrap[1],
);
......
......@@ -170,19 +170,15 @@ class ResourceStorageTest extends BaseTestCase
$driverConfiguration['basePath'] = $this->getMountRootUrl();
}
if ($mockedDriverMethods === null) {
$driver = new LocalDriver($driverConfiguration);
} else {
// We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
// when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
$driver = $this->getMockBuilder(LocalDriver::class)
->onlyMethods($mockedDriverMethods)
->setConstructorArgs([$driverConfiguration])
->getMock();
}
if ($storageObject !== null) {
$storageObject->setDriver($driver);
}
// We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
// when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
$driver = $this->getMockBuilder(LocalDriver::class)
->onlyMethods($mockedDriverMethods)
->setConstructorArgs([$driverConfiguration])
->getMock();
$storageObject?->setDriver($driver);
$driver->setStorageUid(6);
$driver->processConfiguration();
$driver->initialize();
......
......@@ -288,10 +288,6 @@ class Arguments extends \ArrayObject
/** @var Argument $argument */
foreach ($this as $argument) {
$argumentValidationResults = $argument->validate();
if ($argumentValidationResults === null) {
// @todo: Obsolete?! "validate(): Result", can't be null!
continue;
}
$results->forProperty($argument->getName())->merge($argumentValidationResults);
}
return $results;
......
......@@ -176,9 +176,6 @@ class LazyObjectStorage extends ObjectStorage implements LoadingStrategyInterfac
$this->initialize();
$numberOfElements = count($this->storage);
}
if ($numberOfElements === null) {
throw new Exception('The number of elements could not be determined.', 1252514486);
}
return $numberOfElements;
}
......
......@@ -147,7 +147,7 @@ final class FlashMessagesViewHelper extends AbstractViewHelper
$flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)->getMessageQueueByIdentifier($queueIdentifier);
$flashMessages = $flashMessageQueue->getAllMessagesAndFlush();
if ($flashMessages === null || count($flashMessages) === 0) {
if (count($flashMessages) === 0) {
return '';
}
......
......@@ -46,7 +46,7 @@ class VariablesContext implements Applicable
public function matchesRequiredApplicables(Applicable ...$applicables): bool
{
if ($this->requiredApplicables === null || $this->requiredApplicables === []) {
if ($this->requiredApplicables === []) {
return true;
}
$missingApplicables = array_udiff(
......
......@@ -107,10 +107,6 @@ class ShortcutRecordsMigration implements UpgradeWizardInterface
{
$schemaManager = $this->getConnectionPool()->getConnectionForTable(self::TABLE_NAME)->createSchemaManager();
if ($schemaManager === null) {
return false;
}
$tableColumns = $schemaManager->listTableColumns(self::TABLE_NAME);
foreach (['module_name', 'url', 'route', 'arguments'] as $column) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment