Passed
Pull Request — release-11.5.x (#3219)
by Markus
40:42 queued 16:54
created

QueryViewHelper::renderStatic()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8.1515

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 21
ccs 13
cts 15
cp 0.8667
rs 8.4444
cc 8
nc 4
nop 3
crap 8.1515
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Debug;
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
            if (
59 2
                true === $resultSet->getHasSearched()
60 2
                && null !== $resultSet->getUsedSearch()->getDebugResponse()
61 2
                && !empty($resultSet->getUsedSearch()->getDebugResponse()->parsedquery)
62
            ) {
63 1
                $renderingContext->getVariableProvider()->add('parsedQuery', $resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
64 1
                $content = $renderChildrenClosure();
65 1
                $renderingContext->getVariableProvider()->remove('parsedQuery');
66
67 1
                if ($content === null) {
68
                    $content = '<br><strong>Parsed Query:</strong><br>' . htmlspecialchars($resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
69
                }
70
            }
71
        }
72 27
        return $content;
73
    }
74
}
75