Skip to content

Commit

Permalink
[TASK] Apply TYPO3 coding standards, rector and type hinting
Browse files Browse the repository at this point in the history
This commit  contains the changes after run of TYPO3 
codings standards and Rector.
Each file was checked manually and the unnecessary changes were rejected.

Relates: TYPO3-Solr#3198
Closes: TYPO3-Solr#3170
Fixes: TYPO3-Solr#3208
  • Loading branch information
RafaelKa committed Mar 6, 2022
1 parent ecc3d26 commit b0c0b2e
Show file tree
Hide file tree
Showing 384 changed files with 5,846 additions and 5,191 deletions.
42 changes: 21 additions & 21 deletions Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace ApacheSolrForTypo3\Solr\Access;

use RuntimeException;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
Expand Down Expand Up @@ -57,7 +58,6 @@
*/
class Rootline
{

/**
* Delimiter for page and content access right elements in the rootline.
*
Expand All @@ -70,15 +70,15 @@ class Rootline
*
* @var array
*/
protected $rootlineElements = [];
protected array $rootlineElements = [];

/**
* Constructor, turns a string representation of an access rootline into an
* object representation.
*
* @param string $accessRootline Access Rootline String representation.
* @param string|null $accessRootline Access Rootline String representation.
*/
public function __construct($accessRootline = null)
public function __construct(string $accessRootline = null)
{
if (!is_null($accessRootline)) {
$rawRootlineElements = explode(self::ELEMENT_DELIMITER, $accessRootline);
Expand Down Expand Up @@ -121,22 +121,22 @@ public function push(RootlineElement $rootlineElement)
}

/**
* Gets the Access Rootline for a specific page Id.
* Gets the Access Rootline for a specific page id.
*
* @param int $pageId The page Id to generate the Access Rootline for.
* @param int $pageId The page id to generate the Access Rootline for.
* @param string $mountPointParameter The mount point parameter for generating the rootline.
* @return \ApacheSolrForTypo3\Solr\Access\Rootline Access Rootline for the given page Id.
* @return Rootline Access Rootline for the given page id.
*/
public static function getAccessRootlineByPageId(
$pageId,
$mountPointParameter = ''
) {
int $pageId,
string $mountPointParameter = ''
): Rootline {
/* @var Rootline $accessRootline */
$accessRootline = GeneralUtility::makeInstance(Rootline::class);
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPointParameter);
try {
$rootline = $rootlineUtility->get();
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
$rootline = [];
}
$rootline = array_reverse($rootline);
Expand All @@ -148,20 +148,22 @@ public static function getAccessRootlineByPageId(
) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */ $pageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $pageRecord['fe_group']
/** @scrutinizer ignore-type */
$pageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $pageRecord['fe_group']
));
}
}

/** @var $pageSelector PageRepository */
/** @var $pageSelector PageRepository */
$pageSelector = GeneralUtility::makeInstance(PageRepository::class);

// current page
$currentPageRecord = $pageSelector->getPage($pageId, true);
if ($currentPageRecord['fe_group']) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */ $currentPageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $currentPageRecord['fe_group']
/** @scrutinizer ignore-type */
$currentPageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $currentPageRecord['fe_group']
));
}

Expand All @@ -185,11 +187,11 @@ public function __toString()
}

/**
* Gets a the groups in the Access Rootline.
* Gets the groups in the Access Rootline.
*
* @return array An array of sorted, unique user group IDs required to access a page.
*/
public function getGroups()
public function getGroups(): array
{
$groups = [];

Expand All @@ -198,19 +200,17 @@ public function getGroups()
$groups = array_merge($groups, $rootlineElementGroups);
}

$groups = $this->cleanGroupArray($groups);

return $groups;
return $this->cleanGroupArray($groups);
}

/**
* Cleans an array of frontend user group IDs. Removes duplicates and sorts
* Cleans an array of frontend user group IDs. Removes the duplicates and sorts
* the array.
*
* @param array $groups An array of frontend user group IDs
* @return array An array of cleaned frontend user group IDs, unique, sorted.
*/
public static function cleanGroupArray(array $groups)
public static function cleanGroupArray(array $groups): array
{
$groups = array_unique($groups); // removes duplicates
sort($groups, SORT_NUMERIC); // sort
Expand Down
6 changes: 3 additions & 3 deletions Classes/Access/RootlineElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class RootlineElement
/**
* Page Id for the element. NULL for the content type.
*
* @var int
* @var int|null
*/
protected $pageId = null;
protected ?int $pageId = null;

/**
* Set of access groups assigned to the element.
Expand Down Expand Up @@ -116,7 +116,7 @@ public function __construct($element)
);
}

$this->pageId = intval($elementAccess[0]);
$this->pageId = (int)($elementAccess[0]);
$elementGroups = $elementAccess[1];
}

Expand Down
37 changes: 20 additions & 17 deletions Classes/AdditionalFieldsIndexer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
Expand Down Expand Up @@ -32,37 +34,38 @@
*/
class AdditionalFieldsIndexer implements SubstitutePageIndexer
{

/**
* @var TypoScriptConfiguration
*/
protected $configuration;
protected TypoScriptConfiguration $configuration;

/**
* @var array
*/
protected $additionalIndexingFields = [];
protected array $additionalIndexingFields = [];

/**
* @var array
*/
protected $additionalFieldNames = [];
protected array $additionalFieldNames = [];

/**
* @var ContentObjectService
*/
protected $contentObjectService = null;
protected ContentObjectService $contentObjectService;

/**
* @param TypoScriptConfiguration $configuration
* @param ContentObjectService $contentObjectService
* @param TypoScriptConfiguration|null $configuration
* @param ContentObjectService|null $contentObjectService
*/
public function __construct(TypoScriptConfiguration $configuration = null, ContentObjectService $contentObjectService = null)
{
$this->configuration = $configuration === null ? Util::getSolrConfiguration() : $configuration;
public function __construct(
TypoScriptConfiguration $configuration = null,
ContentObjectService $contentObjectService = null
) {
$this->configuration = $configuration ?? Util::getSolrConfiguration();
$this->additionalIndexingFields = $this->configuration->getIndexAdditionalFieldsConfiguration();
$this->additionalFieldNames = $this->configuration->getIndexMappedAdditionalFieldNames();
$this->contentObjectService = $contentObjectService === null ? GeneralUtility::makeInstance(ContentObjectService::class) : $contentObjectService;
$this->contentObjectService = $contentObjectService ?? GeneralUtility::makeInstance(ContentObjectService::class);
}

/**
Expand All @@ -71,16 +74,16 @@ public function __construct(TypoScriptConfiguration $configuration = null, Conte
* Uses the original document and adds fields as defined in
* plugin.tx_solr.index.additionalFields.
*
* @param Document $pageDocument The original page document.
* @param Document $originalPageDocument The original page document.
* @return Document A Apache Solr Document object that replace the default page document
*/
public function getPageDocument(Document $pageDocument)
public function getPageDocument(Document $originalPageDocument): Document
{
$substitutePageDocument = clone $pageDocument;
$substitutePageDocument = clone $originalPageDocument;
$additionalFields = $this->getAdditionalFields();

foreach ($additionalFields as $fieldName => $fieldValue) {
if (!isset($pageDocument->{$fieldName})) {
if (!isset($originalPageDocument->{$fieldName})) {
// making sure we only _add_ new fields
$substitutePageDocument->setField($fieldName, $fieldValue);
}
Expand All @@ -94,7 +97,7 @@ public function getPageDocument(Document $pageDocument)
*
* @return array An array mapping additional field names to their values.
*/
protected function getAdditionalFields()
protected function getAdditionalFields(): array
{
$additionalFields = [];

Expand All @@ -111,7 +114,7 @@ protected function getAdditionalFields()
* @param string $fieldName The name of the field to get.
* @return string The field's value.
*/
protected function getFieldValue($fieldName)
protected function getFieldValue(string $fieldName): string
{
return $this->contentObjectService->renderSingleContentObjectByArrayAndKey($this->additionalIndexingFields, $fieldName);
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/AdditionalPageIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
*/
interface AdditionalPageIndexer
{

/**
* Provides additional documents that should be indexed together with a page.
*
* @param Document $pageDocument The original page document.
* @param array $allDocuments An array containing all the documents collected until here, including the page document
* @return array An array of additional \ApacheSolrForTypo3\Solr\System\Solr\Document\Document objects
*/
public function getAdditionalPageDocuments(Document $pageDocument, array $allDocuments);
public function getAdditionalPageDocuments(Document $pageDocument, array $allDocuments): array;
}
2 changes: 1 addition & 1 deletion Classes/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Api
*/
public static function isValidApiKey($apiKey)
{
return ($apiKey === self::getApiKey());
return $apiKey === self::getApiKey();
}

/**
Expand Down
9 changes: 6 additions & 3 deletions Classes/Backend/CoreSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ protected function renderSelectCheckbox(array $items, array $selectedValues): st
'itemFormElName' => $this->formElementName,
'itemFormElValue' => $selectedValues,
'fieldConf' => ['config' => ['items' => $items]],
'fieldTSConfig' => ['noMatchingValue_label' => '']
'fieldTSConfig' => ['noMatchingValue_label' => ''],
];

$nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
$options = [
'renderType' => 'selectCheckBox', 'table' => 'tx_solr_classes_backend_coreselector',
'fieldName' => 'additionalFields', 'databaseRow' => [], 'parameterArray' => $parameterArray
'renderType' => 'selectCheckBox',
'table' => 'tx_solr_classes_backend_coreselector',
'fieldName' => 'additionalFields',
'databaseRow' => [],
'parameterArray' => $parameterArray,
];

$selectCheckboxResult = $nodeFactory->create($options)->render();
Expand Down
8 changes: 5 additions & 3 deletions Classes/Backend/IndexingConfigurationSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@ protected function renderSelectCheckbox(array $items, ?array $selectedValues = [
'itemFormElName' => $this->formElementName,
'itemFormElValue' => $selectedValues,
'fieldConf' => ['config' => ['items' => $items]],
'fieldTSConfig' => ['noMatchingValue_label' => '']
'fieldTSConfig' => ['noMatchingValue_label' => ''],
];

$nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
$options = [
'type' => 'select', 'renderType' => 'selectCheckBox',
'table' => 'tx_solr_classes_backend_indexingconfigurationselector',
'tableName' => 'tx_solr_classes_backend_indexingconfigurationselector',
'fieldName' => 'additionalFields', 'databaseRow' => ['uid' => 0], 'parameterArray' => $parameterArray,
'processedTca' => ['columns' => ['additionalFields' => ['config' => ['type' => 'select']]]]
'fieldName' => 'additionalFields',
'databaseRow' => ['uid' => 0],
'parameterArray' => $parameterArray,
'processedTca' => ['columns' => ['additionalFields' => ['config' => ['type' => 'select']]]],
];
$options['parameterArray']['fieldConf']['config']['items'] = $items;
$options['parameterArray']['fieldTSConfig']['noMatchingValue_label'] = '';
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/SiteSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

namespace ApacheSolrForTypo3\Solr\Backend;

use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Throwable;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down
Loading

0 comments on commit b0c0b2e

Please sign in to comment.