Commit 902126db authored by crell's avatar crell Committed by Nikita Hovratov
Browse files

[TASK] Resolve "right side of && is always true" in PHPStan

The PHPStan baseline file has several entries for this error.
This patch resolves them by adjusting the code so the
issue is not relevant.

Resolves: #97458
Releases: main, 11.5
Change-Id: Ida192b1168dbf9c9cc3ba7f2ca9e635187137a05
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74378

Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
parent 5b3af51f
......@@ -120,11 +120,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Form/Element/SelectMultipleSideBySideElement.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php
-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
......@@ -515,11 +510,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Crypto/PasswordHashing/BcryptPasswordHash.php
-
message: "#^Binary operation \"\\*\\=\" between non\\-empty\\-string and \\-1 results in an error\\.$#"
count: 1
......@@ -965,11 +955,6 @@ parameters:
count: 2
path: ../../typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#2 \\$folder of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceStorage\\:\\:checkFolderActionPermission\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\|null, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface given\\.$#"
count: 1
......@@ -1020,11 +1005,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/LinkHandling/LinkService.php
-
message: "#^Right side of && is always true\\.$#"
count: 2
path: ../../typo3/sysext/core/Classes/LinkHandling/LinkService.php
-
message: "#^Variable \\$result in empty\\(\\) always exists and is always falsy\\.$#"
count: 1
......@@ -1050,11 +1030,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Mail/FluidEmail.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Mail/MemorySpool.php
-
message: "#^Cannot assign offset 'address' to string\\.$#"
count: 1
......@@ -1325,11 +1300,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Resource/ResourceCompressor.php
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceFactory\\:\\:getCollectionObject\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Collection\\\\AbstractFileCollection but returns TYPO3\\\\CMS\\\\Core\\\\Collection\\\\CollectionInterface\\<TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File\\>\\.$#"
count: 1
......@@ -2430,11 +2400,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Extbase\\\\DomainObject\\\\DomainObjectInterface\\:\\:_memorizeCleanState\\(\\)\\.$#"
count: 1
......@@ -2515,11 +2480,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
-
message: "#^Right side of && is always true\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
-
message: "#^Strict comparison using \\=\\=\\= between TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\Qom\\\\StaticOperandInterface and null will always evaluate to false\\.$#"
count: 3
......
......@@ -83,7 +83,7 @@ class SelectTreeElement extends AbstractFormElement
// Field configuration from TCA:
$config = $parameterArray['fieldConf']['config'];
$readOnly = !empty($config['readOnly']) && $config['readOnly'];
$readOnly = !empty($config['readOnly']);
$exclusiveKeys = !empty($config['exclusiveKeys']) ? $config['exclusiveKeys'] : '';
$exclusiveKeys = $exclusiveKeys . ',';
$appearance = !empty($config['treeConfig']['appearance']) ? $config['treeConfig']['appearance'] : [];
......
......@@ -75,7 +75,6 @@ class BcryptPasswordHash implements PasswordHashInterface
public function isAvailable(): bool
{
return defined('PASSWORD_BCRYPT')
&& PASSWORD_BCRYPT
&& function_exists('hash')
&& function_exists('hash_algos')
&& in_array('sha384', hash_algos());
......
......@@ -751,25 +751,23 @@ class GraphicalFunctions
$theBBoxInfo['lineHeight'] = (int)$conf['lineHeight'];
}
// If any kind of spacing applys, we use this function:
if ($spacing || $wordSpacing) {
if ($spacing) {
$x = 0;
if (!$spacing && $wordSpacing) {
$bits = explode(' ', $theText);
foreach ($bits as $word) {
$word .= ' ';
$wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'], $sF);
$wordW = $wordInf[2] - $wordInf[0];
$x += $wordW + $wordSpacing;
}
} else {
$utf8Chars = $this->csConvObj->utf8_to_numberarray($theText);
// For each UTF-8 char, do:
foreach ($utf8Chars as $char) {
$charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $char, $conf['splitRendering.'], $sF);
$charW = $charInf[2] - $charInf[0];
$x += $charW + ($char === ' ' ? $wordSpacing : $spacing);
}
$utf8Chars = $this->csConvObj->utf8_to_numberarray($theText);
// For each UTF-8 char, do:
foreach ($utf8Chars as $char) {
$charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $char, $conf['splitRendering.'], $sF);
$charW = $charInf[2] - $charInf[0];
$x += $charW + ($char === ' ' ? $wordSpacing : $spacing);
}
} elseif ($wordSpacing) {
$x = 0;
$bits = explode(' ', $theText);
foreach ($bits as $word) {
$word .= ' ';
$wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'], $sF);
$wordW = $wordInf[2] - $wordInf[0];
$x += $wordW + $wordSpacing;
}
} elseif (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($conf['text'], $conf) > $conf['breakWidth']) {
$maxWidth = 0;
......
......@@ -131,10 +131,10 @@ class LinkService implements SingletonInterface
} elseif ($this->handlers[self::TYPE_URL] && PathUtility::hasProtocolAndScheme($urn)) {
$result = $this->handlers[self::TYPE_URL]->resolveHandlerData(['url' => $urn]);
$result['type'] = self::TYPE_URL;
} elseif (stripos($urn, 'mailto:') === 0 && $this->handlers[self::TYPE_EMAIL]) {
} elseif (($this->handlers[self::TYPE_EMAIL] ?? false) && str_starts_with(strtolower($urn), 'mailto:')) {
$result = $this->handlers[self::TYPE_EMAIL]->resolveHandlerData(['email' => $urn]);
$result['type'] = self::TYPE_EMAIL;
} elseif (stripos($urn, 'tel:') === 0 && $this->handlers[self::TYPE_TELEPHONE]) {
} elseif (($this->handlers[self::TYPE_TELEPHONE] ?? false) && str_starts_with(strtolower($urn), 'tel:')) {
$result = $this->handlers[self::TYPE_TELEPHONE]->resolveHandlerData(['telephone' => $urn]);
$result['type'] = self::TYPE_TELEPHONE;
} else {
......
......@@ -94,7 +94,7 @@ class MemorySpool extends AbstractTransport implements SingletonInterface, Delay
$count++;
}
} catch (TransportExceptionInterface $exception) {
if ($retries && $message) {
if ($retries) {
// re-queue the message at the end of the queue to give a chance
// to the other messages to be sent, in case the failure was due to
// this message and not just the transport failing
......
......@@ -188,7 +188,7 @@ class ResourceCompressor
} else {
$filesToInclude[$fileOptions['section']][] = $filenameFromMainDir;
}
if (!empty($fileOptions['async']) && (bool)$fileOptions['async']) {
if ($fileOptions['async'] ?? false) {
$concatenatedJsFileIsAsync = true;
} else {
$allFilesToConcatenateAreAsync = false;
......
......@@ -27,7 +27,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
*/
class LazyLoadingProxy implements \Iterator, LoadingStrategyInterface
{
protected DataMapper $dataMapper;
protected ?DataMapper $dataMapper = null;
/**
* The object this property is contained in.
......
......@@ -721,7 +721,7 @@ class Typo3DbQueryParser
}
} elseif (!$ignoreEnableFields && !$includeDeleted) {
$statement .= $this->getPageRepository()->enableFields($tableName);
} elseif (!$ignoreEnableFields && $includeDeleted) {
} elseif (!$ignoreEnableFields) {
throw new InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1460975922);
}
return $statement;
......
Markdown is supported
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