Passed
Push — master ( 0ba0e3...644d9b )
by Timo
19:06
created

SiteHighlighterUrlModifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A modify() 0 18 3
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\Highlight;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
16
17
/**
18
 * Provides highlighting of the search words on the document's actual page by
19
 * adding parameters to a document's URL property.
20
 *
21
 * Initial code from ApacheSolrForTypo3\Solr\ResultDocumentModifier\SiteHighlighter
22
 *
23
 * @author Stefan Sprenger <[email protected]>
24
 * @author Timo Hund <[email protected]>
25
 */
26
27
use ApacheSolrForTypo3\Solr\System\Url\UrlHelper;
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30
/**
31
 * Class SiteHighlighterUrlModifier
32
 * @package ApacheSolrForTypo3\Solr\System\Service
33
 */
34
class SiteHighlighterUrlModifier {
35
36
    /**
37
     * @param string $url
38
     * @param string $searchWords
39
     * @param boolean $addNoCache
40
     * @param boolean $keepCHash
41
     * @return string
42
     */
43
    public function modify($url, $searchWords, $addNoCache = true, $keepCHash = false) {
44
        $searchWords = str_replace('&quot;', '', $searchWords);
45
        $searchWords = GeneralUtility::trimExplode(' ', $searchWords, true);
46
47
            /** @var UrlHelper $urlHelper */
48
        $urlHelper = GeneralUtility::makeInstance(UrlHelper::class, $url);
49
        $urlHelper->addQueryParameter('sword_list', $searchWords);
50
51
        if ($addNoCache) {
52
            $urlHelper->addQueryParameter('no_cache', '1');
53
        }
54
55
        if (!$keepCHash) {
56
            $urlHelper->removeQueryParameter('cHash');
57
        }
58
59
        return $urlHelper->getUrl();
60
    }
61
}