Skip to content

Commit

Permalink
[BUGFIX] Avoid yoda-style conditions in PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Jul 6, 2022
1 parent eb87e83 commit 48e52db
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 27 deletions.
7 changes: 2 additions & 5 deletions .gitignore
@@ -1,13 +1,14 @@
.Build
.buildpath
*.cache
.DS_Store
.idea/
.php_cs.cache
.project/
.settings/
atlassian-ide-plugin.xml
composer.lock
Documentation/_make
Documentation-GENERATED-temp
index.php
typo3
typo3conf
Expand All @@ -16,7 +17,3 @@ typo3_src
uploads
var
vendor
/composer.lock
.Build
Documentation/_make
/Documentation-GENERATED-temp/
Expand Up @@ -227,7 +227,7 @@ protected function initializeView($view)
'
top.fsMod.recentIds["searchbackend"] = ' . $this->selectedPageUID . ';'
);
if (null === $this->selectedSite) {
if ($this->selectedSite === null) {
return;
}

Expand All @@ -236,7 +236,7 @@ protected function initializeView($view)
$permissionClause = $beUser->getPagePermsClause(1);
$pageRecord = BackendUtility::readPageAccess($this->selectedSite->getRootPageId(), $permissionClause);

if (false === $pageRecord) {
if ($pageRecord === false) {
throw new InvalidArgumentException(vsprintf('There is something wrong with permissions for page "%s" for backend user "%s".', [$this->selectedSite->getRootPageId(), $beUser->user['username']]), 1496146317);
}
$this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
Expand All @@ -249,7 +249,7 @@ protected function initializeView($view)
*/
public function generateCoreSelectorMenuUsingPageTree(string $uriToRedirectTo = null)
{
if ($this->selectedPageUID < 1 || null === $this->selectedSite) {
if ($this->selectedPageUID < 1 || $this->selectedSite === null) {
return;
}

Expand Down
Expand Up @@ -158,7 +158,7 @@ public function getRootPageId(
bool $forceFallback = false,
string $mountPointIdentifier = ''
): int {
if (0 === $pageId) {
if ($pageId === 0) {
return 0;
}

Expand Down
Expand Up @@ -90,8 +90,8 @@ public function __construct(
*/
protected function getRangeString(): string
{
$from = null === $this->startRequested ? '' : $this->startRequested->format('Ymd') . '0000';
$till = null === $this->endRequested ? '' : $this->endRequested->format('Ymd') . '0000';
$from = $this->startRequested === null ? '' : $this->startRequested->format('Ymd') . '0000';
$till = $this->endRequested === null ? '' : $this->endRequested->format('Ymd') . '0000';
return $from . '-' . $till;
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public function build(string $facetName, TypoScriptConfiguration $configuration)
$facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName);

$tag = '';
if (true === (bool)($facetConfiguration['keepAllOptionsOnSelection'] ?? null)) {
if ((bool)($facetConfiguration['keepAllOptionsOnSelection'] ?? null) === true) {
$tag = '{!ex=' . $facetConfiguration['field'] . '}';
}
$facetParameters['facet.range'][] = $tag . $facetConfiguration['field'];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/Suggest/SuggestService.php
Expand Up @@ -181,7 +181,7 @@ protected function getSolrSuggestions(SuggestQuery $suggestQuery): array
$response = $search->search($suggestQuery, 0, 0);

$rawResponse = $response->getRawResponse();
if (null === $rawResponse) {
if ($rawResponse === null) {
return [];
}
$results = json_decode($rawResponse);
Expand Down
Expand Up @@ -43,7 +43,7 @@ class FrontendGroupsModifier
*/
public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
{
if (null === $event->getRequest() || !$event->getRequest()->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) {
if ($event->getRequest() === null || !$event->getRequest()->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/IndexQueue/Indexer.php
Expand Up @@ -283,7 +283,7 @@ protected function isAFreeContentModeItemRecord(Item $item): bool
$itemRecord = $item->getRecord();

$l10nParentField = $GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'] ?? null;
if (null === $languageField || null === $l10nParentField) {
if ($languageField === null || $l10nParentField === null) {
return true;
}
$languageOfRecord = (int)($itemRecord[$languageField] ?? null);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Middleware/SolrRoutingMiddleware.php
Expand Up @@ -381,7 +381,7 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
*/
protected function getRoutingService(): RoutingService
{
if (null === $this->routingService) {
if ($this->routingService === null) {
$this->routingService = GeneralUtility::makeInstance(
RoutingService::class,
$this->settings,
Expand Down
2 changes: 1 addition & 1 deletion Classes/Routing/RoutingService.php
Expand Up @@ -452,7 +452,7 @@ public function shouldConcatQueryParameters(): bool
return true;
}

return isset($this->settings['query']['concat']) && true === (bool)$this->settings['query']['concat'];
return isset($this->settings['query']['concat']) && (bool)$this->settings['query']['concat'] === true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/System/Configuration/ExtensionConfiguration.php
Expand Up @@ -139,7 +139,7 @@ function ($pluginNamespace) {

$exclusions = array_merge($pluginNamespaces, $enhancersRouteParts);

if (false === $this->getIncludeGlobalQParameterInCacheHash()) {
if ($this->getIncludeGlobalQParameterInCacheHash() === false) {
$exclusions[] = 'q';
}
return array_combine($exclusions, $exclusions);
Expand Down
Expand Up @@ -71,8 +71,8 @@ private function unsetModuleDataIfCanNotBeSerialized(string &$serializedModuleDa
$serializedModuleData = '';
return;
}
if (false !== strpos($serializedModuleData, 'ApacheSolrForTypo3\\Solr\\Domain\\Model\\ModuleData')
|| false !== strpos($serializedModuleData, 'Tx_Solr_Site')) {
if (strpos($serializedModuleData, 'ApacheSolrForTypo3\\Solr\\Domain\\Model\\ModuleData') !== false
|| strpos($serializedModuleData, 'Tx_Solr_Site') !== false) {
$serializedModuleData = '';
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/System/Solr/ResponseAdapter.php
Expand Up @@ -164,7 +164,7 @@ public function getHttpStatusMessage(): string
*/
public function count(): int
{
if (null !== $this->data) {
if ($this->data !== null) {
return count(get_object_vars($this->data));
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions Classes/System/UserFunctions/FlexFormUserFunctions.php
Expand Up @@ -117,7 +117,7 @@ protected function getParsedSolrFieldsFromSchema(array $configuredFacets, array
*/
protected function getConfiguredFacetsForPage(?int $pid = null): ?array
{
if (null === $pid) {
if ($pid === null) {
return null;
}
$typoScriptConfiguration = $this->getConfigurationFromPageId($pid);
Expand Down Expand Up @@ -215,7 +215,7 @@ protected function getTypoScriptTemplateKeyFromFieldName(array $parentInformatio
*/
protected function getConfigurationFromPageId(?int $pid = null): ?TypoScriptConfiguration
{
if (null === $pid) {
if ($pid === null) {
return null;
}
return $this->frontendEnvironment->getSolrConfigurationFromPageId($pid);
Expand Down
Expand Up @@ -81,7 +81,7 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$debugData = '';
if (
null !== $resultSet->getUsedSearch()->getDebugResponse()
$resultSet->getUsedSearch()->getDebugResponse() !== null
&& !empty($resultSet->getUsedSearch()->getDebugResponse()->explain)
) {
$debugData = $resultSet->getUsedSearch()->getDebugResponse()->explain->{$document->getId()} ?? '';
Expand Down
6 changes: 3 additions & 3 deletions Classes/ViewHelpers/Debug/QueryViewHelper.php
Expand Up @@ -54,10 +54,10 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
$content = '';
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$backendUserIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn');
if (true === $backendUserIsLoggedIn && $resultSet && null !== $resultSet->getUsedSearch()) {
if ($backendUserIsLoggedIn === true && $resultSet && $resultSet->getUsedSearch() !== null) {
if (
true === $resultSet->getHasSearched()
&& null !== $resultSet->getUsedSearch()->getDebugResponse()
$resultSet->getHasSearched() === true
&& $resultSet->getUsedSearch()->getDebugResponse() !== null
&& !empty($resultSet->getUsedSearch()->getDebugResponse()->parsedquery)
) {
$renderingContext->getVariableProvider()->add('parsedQuery', $resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
Expand Down

0 comments on commit 48e52db

Please sign in to comment.