Passed
Push — master ( 5adbd6...5901ba )
by Timo
20:55
created

StatisticsComponent::initializeSearchComponent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
crap 3.0261
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Search;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2012-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest;
28
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestAware;
29
use ApacheSolrForTypo3\Solr\Domain\Search\Statistics\StatisticsWriterProcessor;
30
use ApacheSolrForTypo3\Solr\Query\Modifier\Statistics;
31
32
/**
33
 * Statistics search component
34
 *
35
 * @author Ingo Renner <[email protected]>
36
 */
37
class StatisticsComponent extends AbstractComponent implements SearchRequestAware
38
{
39
40
    /**
41
     * @var SearchRequest
42
     */
43
    protected $seachRequest;
44
45
    /**
46
     * Provides a component that is aware of the current SearchRequest
47
     *
48
     * @param SearchRequest $searchRequest
49
     */
50 31
    public function setSearchRequest(SearchRequest $searchRequest)
51
    {
52 31
        $this->seachRequest = $searchRequest;
53 31
    }
54
55
    /**
56
     * Initializes the search component.
57
     *
58
     */
59 31
    public function initializeSearchComponent()
60
    {
61 31
        $solrConfiguration = $this->seachRequest->getContextTypoScriptConfiguration();
62
63 31
        if ($solrConfiguration->getStatistics()) {
64 27
            $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['statistics'] = StatisticsWriterProcessor::class;
65
            // Only if addDebugData is enabled add Query modifier
66 27
            if ($solrConfiguration->getStatisticsAddDebugData()) {
67
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['statistics'] = Statistics::class;
68
            }
69
        }
70 31
    }
71
72
}
73