Passed
Pull Request — release-11.5.x (#3312)
by Markus
50:02 queued 28:19
created

getUsedSearchResultSetFromRenderingContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace ApacheSolrForTypo3\Solr\ViewHelpers;
19
20
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Grouping\GroupItem;
21
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
22
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext;
23
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
24
use InvalidArgumentException;
25
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
26
27
/**
28
 * Class AbstractSolrFrontendViewHelper
29
 *
30
 * @author Frans Saris <[email protected]>
31
 * @author Timo Hund <[email protected]>
32
 */
33
abstract class AbstractSolrFrontendViewHelper extends AbstractSolrViewHelper
34
{
35
    /**
36
     * @var SolrControllerContext|null
37
     */
38
    protected ?SolrControllerContext $controllerContext = null;
39
40
    /**
41
     * @return TypoScriptConfiguration|null
42
     */
43
    protected function getTypoScriptConfiguration(): ?TypoScriptConfiguration
44
    {
45
        return $this->getControllerContext()->getTypoScriptConfiguration();
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...:getControllerContext() has been deprecated: Will be removed with v12. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        return /** @scrutinizer ignore-deprecated */ $this->getControllerContext()->getTypoScriptConfiguration();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
46
    }
47
48
    /**
49
     * @return SearchResultSet|null
50
     * @deprecated Will be removed with v12.
51
     */
52
    protected function getSearchResultSet(): ?SearchResultSet
53
    {
54
        return $this->getControllerContext()->getSearchResultSet();
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...:getControllerContext() has been deprecated: Will be removed with v12. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

54
        return /** @scrutinizer ignore-deprecated */ $this->getControllerContext()->getSearchResultSet();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
    }
56
57
    /**
58
     * @return SolrControllerContext
59
     * @throws InvalidArgumentException
60
     * @deprecated Will be removed with v12.
61
     */
62
    protected function getControllerContext(): SolrControllerContext
63
    {
64
        $controllerContext = null;
65
        if (method_exists($this->renderingContext, 'getControllerContext')) {
66
            $controllerContext = $this->renderingContext->getControllerContext();
67
        }
68
69
        if (!$controllerContext instanceof SolrControllerContext) {
70
            throw new InvalidArgumentException('No valid SolrControllerContext found', 1512998673);
71
        }
72
73
        return $controllerContext;
74
    }
75
76
    /**
77
     * @param RenderingContextInterface $renderingContext
78
     * @return SearchResultSet|GroupItem|null
79
     */
80 29
    protected static function getUsedSearchResultSetFromRenderingContext(
81
        RenderingContextInterface $renderingContext
82
    ) {
83 29
        return $renderingContext->getVariableProvider()->get('resultSet')
84 29
            ?? $renderingContext->getControllerContext()->getSearchResultSet();
0 ignored issues
show
Bug introduced by
The method getControllerContext() does not exist on TYPO3Fluid\Fluid\Core\Re...nderingContextInterface. Did you maybe mean getControllerAction()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
            ?? $renderingContext->/** @scrutinizer ignore-call */ getControllerContext()->getSearchResultSet();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
    }
86
}
87