Skip to content

Commit

Permalink
[TASK] Fix scrutinizer issues on Routing-Enhancers feature
Browse files Browse the repository at this point in the history
Fixes: #2257
  • Loading branch information
dkd-kaehm committed Aug 18, 2021
1 parent 552b45c commit ec72de7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Expand Up @@ -64,7 +64,8 @@ public function __invoke(BeforeProcessCachedVariablesEvent $event): void

$standardizedKeys = $variableKeys;

for ($i = 0; $i < count($variableKeys); $i++) {
$variableKeysCount = count($variableKeys);
for ($i = 0; $i < $variableKeysCount; $i++) {
$standardizedKey = $this->standardizeKey($variableKeys[$i]);
if (!$this->containsPathVariable($standardizedKey, $pathVariables) || empty($variableValues[$standardizedKey])) {
continue;
Expand Down
15 changes: 8 additions & 7 deletions Classes/Middleware/SolrRoutingMiddleware.php
Expand Up @@ -188,9 +188,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
protected function configure(array $enhancerConfiguration): void
{
$this->settings = $enhancerConfiguration['solr'];
$this->namespace = isset($enhancerConfiguration['extensionKey']) ?
$enhancerConfiguration['extensionKey'] :
$this->namespace;
$this->namespace = $enhancerConfiguration['extensionKey'] ?? $this->namespace;
$this->routingService = null;
}

Expand Down Expand Up @@ -274,7 +272,8 @@ protected function extractParametersFromUriPath(UriInterface $uri, string $path,
}

// Extract the values
for ($i = 0; $i < count($uriElements); $i++) {
$uriElementsCount = count($uriElements);
for ($i = 0; $i < $uriElementsCount; $i++) {
// Skip empty elements
if (empty($uriElements[$i])) {
continue;
Expand Down Expand Up @@ -315,7 +314,8 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
);
if (empty($items)) {
$this->logger
->error(
->/** @scrutinizer ignore-call */
error(
vsprintf(
'Could not determine page for slug "%1$s" and language "%2$s". Given path "%3$s"',
[
Expand All @@ -328,7 +328,8 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
$scan = false;
} elseif (empty($path)) {
$this->logger
->error(
->/** @scrutinizer ignore-call */
error(
vsprintf(
'Could resolve page by path "%1$s" and language "%2$s".',
[
Expand Down Expand Up @@ -377,7 +378,7 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
*/
protected function getRoutingService(): RoutingService
{
if (!($this->routingService instanceof RoutingService)) {
if (null === $this->routingService) {
$this->routingService = GeneralUtility::makeInstance(
RoutingService::class,
$this->settings,
Expand Down
5 changes: 3 additions & 2 deletions Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php
Expand Up @@ -102,7 +102,7 @@ public function enhanceForGeneration(RouteCollection $collection, array $paramet
$variables = array_flip($compiledRoute->getPathVariables());
$mergedParams = array_replace($variant->getDefaults(), $deflatedParameters);
// all params must be given, otherwise we exclude this variant
if ($diff = array_diff_key($variables, $mergedParams)) {
if (array_diff_key($variables, $mergedParams) !== []) {
return;
}

Expand Down Expand Up @@ -214,7 +214,8 @@ protected function replaceVariableWithHash(Route $route, array $parameters = [])

$keepVariables = [];

for ($i = 0; $i < count($pathTokens); $i++) {
$pathTokensCount = count($pathTokens);
for ($i = 0; $i < $pathTokensCount; $i++) {
// wee only looking for variables
if ($pathTokens[$i][0] !== 'variable') {
continue;
Expand Down
15 changes: 9 additions & 6 deletions Classes/Routing/RoutingService.php
Expand Up @@ -268,7 +268,8 @@ public function finalizePathQuery(string $uriPath): string
* 2. Apply character replacements
* 3. Filter duplicate values
*/
for ($i = 0; $i < count($queryValues); $i++) {
$queryValuesCount = count($queryValues);
for ($i = 0; $i < $queryValuesCount; $i++) {
$queryValues[$i] = urldecode($queryValues[$i]);
if ($this->containsFacetAndValueSeparator((string)$queryValues[$i])) {
[$facetName, $facetValue] = explode(
Expand Down Expand Up @@ -326,13 +327,15 @@ public function maskQueryParameters(array $queryParams): array

if (!isset($queryParams[$this->getPluginNamespace()])) {
$this->logger
->error('Mask error: Query parameters has no entry for namespace ' . $this->getPluginNamespace());
->/** @scrutinizer ignore-call */
error('Mask error: Query parameters has no entry for namespace ' . $this->getPluginNamespace());
return $queryParams;
}

if (!isset($queryParams[$this->getPluginNamespace()]['filter'])) {
$this->logger
->info('Mask info: Query parameters has no filter in namespace ' . $this->getPluginNamespace());
->/** @scrutinizer ignore-call */
info('Mask info: Query parameters has no filter in namespace ' . $this->getPluginNamespace());
return $queryParams;
}
$queryParameterMap = $this->getQueryParameterMap();
Expand All @@ -345,7 +348,7 @@ public function maskQueryParameters(array $queryParams): array
$keep = false;
if (isset($queryParameterMap[$facetName]) &&
isset($newQueryParams[$queryParameterMap[$facetName]])) {
$this->logger->error(
$this->logger->/** @scrutinizer ignore-call */error(
'Mask error: Facet "' . $facetName . '" as "' . $queryParameterMap[$facetName] .
'" already in query!'
);
Expand Down Expand Up @@ -589,7 +592,6 @@ public function inflateQueryParameter(array $queryParams = []): array
foreach ($queryParams[$this->getPluginNamespace()]['filter'] as $set) {
$separator = $this->detectFacetAndValueSeparator((string)$set);
[$facetName, $facetValuesString] = explode($separator, $set, 2);
$facetValues = [$facetValuesString];
$facetValues = explode($this->urlFacetQueryService->getMultiValueSeparator(), $facetValuesString);

/**
Expand Down Expand Up @@ -686,7 +688,8 @@ public function containsFacetAndValueSeparator(string $facetWithValue): bool
*/
public function cleanupFacetValues(array $facetValues): array
{
for ($i = 0; $i < count($facetValues); $i++) {
$facetValuesCount = count($facetValues);
for ($i = 0; $i < $facetValuesCount; $i++) {
if (!$this->containsFacetAndValueSeparator((string)$facetValues[$i])) {
continue;
}
Expand Down

0 comments on commit ec72de7

Please sign in to comment.