Passed
Push — task/2976_TYPO3.11_compatibili... ( d7dfd0...4be1cc )
by Rafael
03:40
created

QueryViewHelper::renderStatic()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 8.8333
c 1
b 0
f 0
cc 7
nc 3
nop 3
crap 7
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Debug;
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\ViewHelpers\AbstractSolrFrontendViewHelper;
19
use Closure;
20
use TYPO3\CMS\Core\Context\Context;
21
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25
26
/**
27
 * Class QueryViewHelper
28
 *
29
 * @author Frans Saris <[email protected]>
30
 * @author Timo Hund <[email protected]>
31
 *
32
 * @noinspection PhpUnused used in Fluid templates <s:debug.query />
33
 */
34
class QueryViewHelper extends AbstractSolrFrontendViewHelper
35
{
36
    use CompileWithRenderStatic;
37
38
    /**
39
     * @var bool
40
     */
41
    protected $escapeOutput = false;
42
43
    /**
44
     * @param array $arguments
45
     * @param Closure $renderChildrenClosure
46
     * @param RenderingContextInterface $renderingContext
47
     * @return string
48
     * @throws AspectNotFoundException
49
     * @noinspection PhpMissingReturnTypeInspection
50
     * @noinspection PhpUnused
51
     */
52 27
    public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
53
    {
54 27
        $content = '';
55 27
        $resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
56 27
        $backendUserIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn');
57 27
        if (true === $backendUserIsLoggedIn && $resultSet && null !== $resultSet->getUsedSearch()) {
58 2
            if (true === $resultSet->getHasSearched() && null !== $resultSet->getUsedSearch()->getDebugResponse()
59 2
                && !empty($resultSet->getUsedSearch()->getDebugResponse()->parsedquery)) {
60 1
                $content = '<br><strong>Parsed Query:</strong><br>' . htmlspecialchars($resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
61
            }
62
        }
63 27
        return $content;
64
    }
65
}
66