Passed
Pull Request — release-11.2.x (#3594)
by Markus
14:43 queued 10:47
created

getSearchResultSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\ViewHelpers;
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
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
19
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext;
20
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
21
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22
23
/**
24
 * Class AbstractSolrFrontendViewHelper
25
 *
26
 * @author Frans Saris <[email protected]>
27
 * @author Timo Hund <[email protected]>
28
 */
29
abstract class AbstractSolrFrontendViewHelper extends AbstractSolrViewHelper
30
{
31
    /**
32
     * @var SolrControllerContext
33
     */
34
    protected $controllerContext;
35
36
    /**
37
     * @return TypoScriptConfiguration
38
     */
39
    protected function getTypoScriptConfiguration()
40
    {
41
        return $this->getControllerContext()->getTypoScriptConfiguration();
42
    }
43
44
    /**
45
     * @return SearchResultSet
46
     */
47
    protected function getSearchResultSet()
48
    {
49
        return $this->getControllerContext()->getSearchResultSet();
50
    }
51
52
    /**
53
     * @return SolrControllerContext
54
     * @throws \InvalidArgumentException
55
     */
56
    protected function getControllerContext()
57
    {
58
        $controllerContext = null;
59
        if (method_exists($this->renderingContext, 'getControllerContext')) {
60
            $controllerContext = $this->renderingContext->getControllerContext();
61
        }
62
63
        if (!$controllerContext instanceof SolrControllerContext) {
64
            throw new \InvalidArgumentException('No valid SolrControllerContext found', 1512998673);
65
        }
66
67
        return $controllerContext;
68
    }
69
70
    /**
71
     * @param RenderingContextInterface $renderingContext
72
     * @return SearchResultSet
73
     */
74
    protected static function getUsedSearchResultSetFromRenderingContext(RenderingContextInterface $renderingContext)
75 1
    {
76
        $resultSet = $renderingContext->getVariableProvider()->get('resultSet');
77 1
        return $resultSet;
78 1
    }
79
}
80