Skip to content

Commit

Permalink
[TASK] Code CleanUp
Browse files Browse the repository at this point in the history
Apply various inspections of PhpStorm:

* Remove unneeded annotations
* Add void as method return type
* Replace mb_substr/mb_strpos with str_starts_with
* Simplify if conditions

Relates: #3376
  • Loading branch information
froemken authored and dkd-kaehm committed May 15, 2023
1 parent cfce9f1 commit 023cc0f
Show file tree
Hide file tree
Showing 74 changed files with 166 additions and 815 deletions.
2 changes: 1 addition & 1 deletion Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __construct(string $accessRootline = null)
*
* @param RootlineElement $rootlineElement Element to add.
*/
public function push(RootlineElement $rootlineElement)
public function push(RootlineElement $rootlineElement): void
{
$lastElementIndex = max(0, (count($this->rootlineElements) - 1));

Expand Down
4 changes: 2 additions & 2 deletions Classes/Backend/CoreSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(Site $site)
*
* @param string $formElementName Form element name
*/
public function setFormElementName(string $formElementName)
public function setFormElementName(string $formElementName): void
{
$this->formElementName = $formElementName;
}
Expand All @@ -84,7 +84,7 @@ public function getFormElementName(): string
*
* @param array $selectedValues
*/
public function setSelectedValues(array $selectedValues)
public function setSelectedValues(array $selectedValues): void
{
$this->selectedValues = $selectedValues;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/IndexingConfigurationSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(Site $site)
*
* @param string $formElementName Form element name
*/
public function setFormElementName(string $formElementName)
public function setFormElementName(string $formElementName): void
{
$this->formElementName = $formElementName;
}
Expand Down
20 changes: 0 additions & 20 deletions Classes/Backend/SettingsPreviewOnPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SettingsPreviewOnPlugins
{
protected array $pluginsTtContentRecord;
private array $flexformData;

protected array $settings = [];

public function __construct(
Expand Down Expand Up @@ -102,10 +101,6 @@ protected function addTargetPage(): void
}
}

/**
* @param string $settingName
* @param string $flexFormField
*/
protected function addSettingFromFlexForm(string $settingName, string $flexFormField): void
{
$value = $this->getFieldFromFlexform($flexFormField);
Expand All @@ -117,10 +112,6 @@ protected function addSettingFromFlexForm(string $settingName, string $flexFormF
$this->addSettingIfNotEmpty($settingName, (string)$value);
}

/**
* @param string $settingName
* @param array $values
*/
protected function addSettingFromFlexFormArray(string $settingName, array $values): void
{
foreach ($values as $item) {
Expand All @@ -136,10 +127,6 @@ protected function addSettingFromFlexFormArray(string $settingName, array $value
}
}

/**
* @param string $settingName
* @param string $value
*/
protected function addSettingIfNotEmpty(string $settingName, string $value): void
{
if (!empty($value)) {
Expand All @@ -161,8 +148,6 @@ protected function getFieldFromFlexform(string $path): mixed

/**
* Returns the plugin label
*
* @return string
*/
protected function getPluginLabel(): string
{
Expand All @@ -176,11 +161,6 @@ protected function getPluginLabel(): string
return $label;
}

/**
* Returns the language service
*
* @return LanguageService
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
Expand Down
4 changes: 2 additions & 2 deletions Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function getConnectionFromConfiguration(array $config)
* Gets a Solr connection for a page ID.
*
* @param int $pageId A page ID.
* @param ?int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0.
* @param ?string $mount Comma list of MountPoint parameters
* @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0.
* @param string $mount Comma list of MountPoint parameters
* @return SolrConnection A solr connection.
* @throws DBALDriverException
* @throws NoSolrConnectionFoundException
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function buildClassificationsFromConfiguration(array $configuredMapped
// @todo deprecate patterns configuration
$patterns = empty($class['patterns']) ? [] : GeneralUtility::trimExplode(',', $class['patterns']);
$matchPatterns = empty($class['matchPatterns']) ? [] : GeneralUtility::trimExplode(',', $class['matchPatterns']);
$matchPatterns = $matchPatterns + $patterns;
$matchPatterns += $patterns;
$unMatchPatters = empty($class['unmatchPatterns']) ? [] : GeneralUtility::trimExplode(',', $class['unmatchPatterns']);

$className = $class['class'];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/AbstractBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function initializeSettings()

// Make sure plugin.tx_solr.settings are available in the view as {settings}
$this->settings = $typoScriptService->convertTypoScriptArrayToPlainArray(
$this->typoScriptConfiguration->getObjectByPathOrDefault('plugin.tx_solr.settings.', [])
$this->typoScriptConfiguration->getObjectByPathOrDefault('plugin.tx_solr.settings.')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function emptyIndexAction(): ResponseInterface
$writeService = $solrServer->getWriteService();
/* @var SolrConnection $solrServer */
$writeService->deleteByQuery('siteHash:' . $siteHash);
$writeService->commit(false, false, false);
$writeService->commit(false, false);
$affectedCores[] = $writeService->getPrimaryEndpoint()->getCore();
}
$message = LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)]);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public function resultsAction(): ResponseInterface
$currentPage = 1;
}

$itemsPerPage = ($searchResultSet->getUsedResultsPerPage() ?: $this->typoScriptConfiguration->getSearchResultsPerPage(10));
$itemsPerPage = ($searchResultSet->getUsedResultsPerPage() ?: $this->typoScriptConfiguration->getSearchResultsPerPage());
$paginator = GeneralUtility::makeInstance(ResultsPaginator::class, $searchResultSet, $currentPage, $itemsPerPage);
$pagination = GeneralUtility::makeInstance(ResultsPagination::class, $paginator);
$pagination->setMaxPageNumbers((int)$this->typoScriptConfiguration->getMaxPaginatorLinks(0));
$pagination->setMaxPageNumbers($this->typoScriptConfiguration->getMaxPaginatorLinks());

/* @var AfterSearchEvent $afterSearchEvent */
$afterSearchEvent = $this->eventDispatcher->dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
class StrategyFactory
{
/**
* @param string $table
* @return PageStrategy|RecordStrategy
*/
public static function getByTable(string $table): AbstractStrategy
Expand Down
16 changes: 8 additions & 8 deletions Classes/Domain/Index/Queue/QueueItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function flushAllErrors(): int
public function flushErrorsBySite(Site $site): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$this->getPreparedFlushErrorQuery($queryBuilder)
return $this->getPreparedFlushErrorQuery($queryBuilder)
->andWhere(
/** @scrutinizer ignore-type */
$queryBuilder->expr()->eq('root', $site->getRootPageId())
Expand All @@ -157,7 +157,7 @@ public function flushErrorsBySite(Site $site): int
public function flushErrorByItem(Item $item): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$this->getPreparedFlushErrorQuery($queryBuilder)
return $this->getPreparedFlushErrorQuery($queryBuilder)
->andWhere(
/** @scrutinizer ignore-type */
$queryBuilder->expr()->eq('uid', $item->getIndexQueueUid())
Expand Down Expand Up @@ -222,7 +222,7 @@ public function updateExistingItemByItemTypeAndItemUidAndRootPageId(
$queryBuilder->set('indexing_configuration', $indexingConfiguration);
}

return (int)$queryBuilder->executeStatement();
return $queryBuilder->executeStatement();
}

/**
Expand All @@ -249,7 +249,7 @@ public function add(
int $indexingPriority = 0
): int {
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
return $queryBuilder
->insert($this->table)
->values([
'root' => $rootPageId,
Expand Down Expand Up @@ -983,7 +983,7 @@ public function markItemAsFailed($item, string $errorMessage = ''): int
$errorMessage = empty($errorMessage) ? '1' : $errorMessage;

$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
return $queryBuilder
->update($this->table)
->set('errors', $errorMessage)
->where($queryBuilder->expr()->eq('uid', $itemUid))
Expand All @@ -1001,7 +1001,7 @@ public function markItemAsFailed($item, string $errorMessage = ''): int
public function updateIndexTimeByItem(Item $item): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
return $queryBuilder
->update($this->table)
->set('indexed', time())
->where($queryBuilder->expr()->eq('uid', $item->getIndexQueueUid()))
Expand All @@ -1020,7 +1020,7 @@ public function updateIndexTimeByItem(Item $item): int
public function updateChangedTimeByItem(Item $item, int $changedTime = 0): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
return $queryBuilder
->update($this->table)
->set('changed', $changedTime)
->where($queryBuilder->expr()->eq('uid', $item->getIndexQueueUid()))
Expand Down Expand Up @@ -1121,7 +1121,7 @@ public function findAllIndexQueueItemsByRootPidAndMountIdentifierAndMountedPids(
public function updateHasIndexingPropertiesFlagByItemUid(int $itemUid, bool $hasIndexingPropertiesFlag): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
return $queryBuilder
->update($this->table)
->where(
/** @scrutinizer ignore-type */
Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Search/ApacheSolrDocument/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function __construct(IdBuilder $variantIdBuilder = null)
* @param string $url
* @param Rootline $pageAccessRootline
* @param string $mountPointParameter
* @return Document|object
* @throws AspectNotFoundException
* @throws DBALDriverException
*/
Expand Down
Loading

0 comments on commit 023cc0f

Please sign in to comment.