Skip to content

Commit

Permalink
[TASK:T12] Fix TYPO3 12+ coding standards for 0.7.1+
Browse files Browse the repository at this point in the history
This change contains: 

* Reenable "modernize_strpos" rule and applies it
* The PSR12 rule for import type blocks for PhpcsFixer 
   The ordered_imports.imports_order is now 
   class, function, const
* the coding standards fixes for TYPO3 12+.

Fixes: #3460
  • Loading branch information
dkd-kaehm committed May 15, 2023
1 parent 18b71fc commit 7df3ff7
Show file tree
Hide file tree
Showing 70 changed files with 120 additions and 103 deletions.
9 changes: 8 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config
->addRules(['modernize_strpos' => false])
->addRules(
[
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha'
]
],
)
->getFinder()
->exclude([
'.Build'
Expand Down
2 changes: 1 addition & 1 deletion Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Rootline
*
* @var string
*/
const ELEMENT_DELIMITER = '/';
public const ELEMENT_DELIMITER = '/';

/**
* Storage for access rootline elements
Expand Down
8 changes: 4 additions & 4 deletions Classes/Access/RootlineElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ class RootlineElement
*
* @var int
*/
const ELEMENT_TYPE_PAGE = 1;
public const ELEMENT_TYPE_PAGE = 1;

/**
* Content access rootline element.
*
* @var int
*/
const ELEMENT_TYPE_CONTENT = 2;
public const ELEMENT_TYPE_CONTENT = 2;

/**
* Record access rootline element.
*
* @var int
*/
const ELEMENT_TYPE_RECORD = 3;
public const ELEMENT_TYPE_RECORD = 3;

/**
* Delimiter between the page ID and the groups set for a page.
*
* @var string
*/
const PAGE_ID_GROUP_DELIMITER = ':';
public const PAGE_ID_GROUP_DELIMITER = ':';

/**
* Access type, either page (default) or content. Depending on the type,
Expand Down
3 changes: 2 additions & 1 deletion Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use InvalidArgumentException;
use function json_encode;
use Throwable;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function json_encode;

/**
* ConnectionManager is responsible to create SolrConnection objects.
*
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class Classification extends AbstractContentObject
{
const CONTENT_OBJECT_NAME = 'SOLR_CLASSIFICATION';
public const CONTENT_OBJECT_NAME = 'SOLR_CLASSIFICATION';

/**
* Executes the SOLR_CLASSIFICATION content object.
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Content extends AbstractContentObject
{
const CONTENT_OBJECT_NAME = 'SOLR_CONTENT';
public const CONTENT_OBJECT_NAME = 'SOLR_CONTENT';

/**
* Executes the SOLR_CONTENT content object.
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Multivalue.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
class Multivalue extends AbstractContentObject
{
const CONTENT_OBJECT_NAME = 'SOLR_MULTIVALUE';
public const CONTENT_OBJECT_NAME = 'SOLR_MULTIVALUE';

/**
* Executes the SOLR_MULTIVALUE content object.
Expand Down
8 changes: 4 additions & 4 deletions Classes/ContentObject/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function getRelatedItemsFromMMTable(string $localTableName, int $local
$mmTableName = $localFieldTca['config']['MM'];

// Remove the first option of foreignLabelField for recursion
if (strpos($this->configuration['foreignLabelField'] ?? '', '.') !== false) {
if (str_contains($this->configuration['foreignLabelField'] ?? '', '.')) {
$foreignTableLabelFieldArr = explode('.', $this->configuration['foreignLabelField']);
unset($foreignTableLabelFieldArr[0]);
$this->configuration['foreignLabelField'] = implode('.', $foreignTableLabelFieldArr);
Expand All @@ -200,7 +200,7 @@ protected function getRelatedItemsFromMMTable(string $localTableName, int $local
&& !empty($this->configuration['enableRecursiveValueResolution'])
) {
$this->configuration['localField'] = $foreignTableLabelField;
if (strpos($this->configuration['foreignLabelField'], '.') !== false) {
if (str_contains($this->configuration['foreignLabelField'], '.')) {
$foreignTableLabelFieldArr = explode('.', $this->configuration['foreignLabelField']);
unset($foreignTableLabelFieldArr[0]);
$this->configuration['foreignLabelField'] = implode('.', $foreignTableLabelFieldArr);
Expand Down Expand Up @@ -238,7 +238,7 @@ protected function resolveForeignTableLabelField(array $foreignTableTca): ?strin
return $foreignTableLabelField;
}

if (strpos($this->configuration['foreignLabelField'] ?? '', '.') !== false) {
if (str_contains($this->configuration['foreignLabelField'] ?? '', '.')) {
list($foreignTableLabelField) = explode('.', $this->configuration['foreignLabelField'], 2);
} else {
$foreignTableLabelField = $this->configuration['foreignLabelField'];
Expand Down Expand Up @@ -352,7 +352,7 @@ protected function resolveRelatedValue(
// adjust configuration for next level
$this->configuration['localField'] = $foreignTableLabelField;
$parentContentObject->data = $relatedRecord;
if (strpos($this->configuration['foreignLabelField'], '.') !== false) {
if (str_contains($this->configuration['foreignLabelField'], '.')) {
list(, $this->configuration['foreignLabelField']) = explode(
'.',
$this->configuration['foreignLabelField'],
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function initializeView($view)
return;
}

if (strpos($customTemplate, 'EXT:') !== false) {
if (str_contains($customTemplate, 'EXT:')) {
$view->setTemplatePathAndFilename($customTemplate);
} else {
$view->setTemplate($customTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Doctrine\DBAL\Exception as DBALException;
use InvalidArgumentException;

use function json_encode;

class LastSearchesRepository extends AbstractRepository
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/Query/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function removeAllSortings(): AbstractQueryBuilder
*/
public function useSorting(Sorting $sorting): AbstractQueryBuilder
{
if (strpos($sorting->getFieldName(), 'relevance') !== false) {
if (str_contains($sorting->getFieldName(), 'relevance')) {
$this->removeAllSortings();
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/Query/ParameterBuilder/Faceting.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function build(AbstractQueryBuilder $parentBuilder): AbstractQueryBuilder

$params = $query->getParams();
foreach ($params as $key => $value) {
if (strpos($key, 'f.') !== false) {
if (str_contains($key, 'f.')) {
$query->addParam($key, null);
}
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Search/Query/ParameterBuilder/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder;

use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;

use function str_starts_with;

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Search/Query/ParameterBuilder/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
class Operator extends AbstractDeactivatable
{
const OPERATOR_AND = 'AND';
const OPERATOR_OR = 'OR';
public const OPERATOR_AND = 'AND';
public const OPERATOR_OR = 'OR';

/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(array $fieldList = [])
*/
public function add(string $fieldName)
{
if (strpos($fieldName, '[') === false && strpos($fieldName, ']') === false && in_array('*', $this->fieldList)) {
if (!str_contains($fieldName, '[') && !str_contains($fieldName, ']') && in_array('*', $this->fieldList)) {
$this->fieldList = array_diff($this->fieldList, ['*']);
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/Query/ParameterBuilder/Slops.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class Slops implements ParameterBuilderInterface
{
const NO_SLOP = null;
public const NO_SLOP = null;

/**
* The qs parameter
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Search/Query/ParameterBuilder/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
class Sorting extends AbstractDeactivatable
{
const SORT_ASC = 'ASC';
const SORT_DESC = 'DESC';
public const SORT_ASC = 'ASC';
public const SORT_DESC = 'DESC';

/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/ResultSet/Facets/AbstractFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
abstract class AbstractFacet
{
const TYPE_ABSTRACT = 'abstract';
public const TYPE_ABSTRACT = 'abstract';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class HierarchyFacet extends AbstractFacet
{
const TYPE_HIERARCHY = 'hierarchy';
public const TYPE_HIERARCHY = 'hierarchy';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function getActiveFacetValuesFromRequest(SearchResultSet $resultSet, s

foreach (is_array($values) ? $values : [] as $valueFromRequest) {
// Attach the 'depth' param again to the value
if (strpos($valueFromRequest, '-') === false) {
if (!str_contains($valueFromRequest, '-')) {
$valueFromRequest = HierarchyTool::substituteSlashes($valueFromRequest);
$valueFromRequest = trim($valueFromRequest, '/');
$valueFromRequest = (count(explode('/', $valueFromRequest)) - 1) . '-' . $valueFromRequest . '/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HierarchyUrlDecoder implements FacetUrlDecoderInterface
*
* @var string
*/
const DELIMITER = '/';
public const DELIMITER = '/';

/**
* Parses the given hierarchy filter and returns a Solr filter query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class OptionsFacet extends AbstractOptionsFacet
{
const TYPE_OPTIONS = 'options';
public const TYPE_OPTIONS = 'options';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function getMetricsFromSolrResponse(string $facetName, ResponseAdapter
foreach ($response->facets->{$facetName}->buckets as $bucket) {
$bucketVariables = get_object_vars($bucket);
foreach ($bucketVariables as $key => $value) {
if (strpos($key, 'metrics_') === 0) {
if (str_starts_with($key, 'metrics_')) {
$metricsKey = str_replace('metrics_', '', $key);
$metricsFromSolrResponse[$bucket->val][$metricsKey] = $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class QueryGroupFacet extends AbstractOptionsFacet
{
const TYPE_QUERY_GROUP = 'queryGroup';
public const TYPE_QUERY_GROUP = 'queryGroup';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class DateRangeFacet extends AbstractFacet
{
const TYPE_DATE_RANGE = 'dateRange';
public const TYPE_DATE_RANGE = 'dateRange';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DateRangeUrlDecoder implements FacetUrlDecoderInterface
*
* @var string
*/
const DELIMITER = '-';
public const DELIMITER = '-';

/**
* Parses the given date range from a GET parameter and returns a Solr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class NumericRangeFacet extends AbstractFacet
{
const TYPE_NUMERIC_RANGE = 'numericRange';
public const TYPE_NUMERIC_RANGE = 'numericRange';

/**
* String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NumericRangeUrlDecoder implements FacetUrlDecoderInterface
*
* @var string
*/
const DELIMITER = '-';
public const DELIMITER = '-';

/**
* Parses the given range from a GET parameter and returns a Solr range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getForFacet($sorting): string
*/
public function getForJsonFacet(string $sorting, string $direction): string
{
$isMetricSorting = strpos($sorting, 'metrics_') === 0;
$isMetricSorting = str_starts_with($sorting, 'metrics_');
$expression = $isMetricSorting ? $sorting : $this->getForFacet($sorting);
$direction = strtolower($direction ?? '');
if (!empty($direction) && in_array($direction, ['asc', 'desc'])) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Search/ResultSet/Facets/UrlFacetContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class UrlFacetContainer implements \Countable
/**
* Parameters array has a numeric index
*/
const PARAMETER_STYLE_INDEX = 'index';
public const PARAMETER_STYLE_INDEX = 'index';

/**
* Parameters array uses combination of key and value as index
*/
const PARAMETER_STYLE_ASSOC = 'assoc';
public const PARAMETER_STYLE_ASSOC = 'assoc';

/**
* Used parameter style
Expand Down
3 changes: 2 additions & 1 deletion Classes/Domain/Search/ResultSet/SearchResultSetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter;
use ApacheSolrForTypo3\Solr\System\Solr\SolrIncompleteResponseException;
use Exception;
use function get_class;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use UnexpectedValueException;

use function get_class;

/**
* The SearchResultSetService is responsible to build a SearchResultSet from a SearchRequest.
* It encapsulates the logic to trigger a search in order to be able to reuse it in multiple places.
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Search/ResultSet/Sorting/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
class Sorting
{
const DIRECTION_DESC = 'desc';
public const DIRECTION_DESC = 'desc';

const DIRECTION_ASC = 'asc';
public const DIRECTION_ASC = 'asc';

/**
* @var array
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Search/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SearchRequest
*
* @var string
*/
const DEFAULT_PLUGIN_NAMESPACE = 'tx_solr';
public const DEFAULT_PLUGIN_NAMESPACE = 'tx_solr';

/**
* @var string
Expand Down
3 changes: 1 addition & 2 deletions Classes/Domain/Search/Uri/SearchUriBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ protected function buildLinkWithInMemoryCache(?int $pageUid, array $arguments):
$values = $variableEvent->getVariableValues();
// Take care that everything is urlencoded!
$keys = array_map(function ($value) {
// @TODO: With only PHP 8 support, replace this with str_contains()
if (strpos($value, '###') === false) {
if (!str_contains($value, '###')) {
return $value;
}
return urlencode($value);
Expand Down
2 changes: 1 addition & 1 deletion Classes/IndexQueue/AbstractIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected static function isSerializedResultFromRegisteredHook(array $indexingCo
throw new UnexpectedValueException($message, 1404471741);
}

$isSerialized = (boolean)$serializedValueDetector->isSerializedValue($indexingConfiguration, $solrFieldName);
$isSerialized = (bool)$serializedValueDetector->isSerializedValue($indexingConfiguration, $solrFieldName);
if ($isSerialized) {
return true;
}
Expand Down
Loading

0 comments on commit 7df3ff7

Please sign in to comment.