Passed
Push — release-11.0.x ( 5eb456...534ada )
by Rafael
25:03
created

SiteHighlighterUrlModifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 26
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A modify() 0 17 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
 */
33
class SiteHighlighterUrlModifier {
34
35
    /**
36
     * @param string $url
37
     * @param string $searchWords
38
     * @param boolean $addNoCache
39
     * @param boolean $keepCHash
40
     * @return string
41
     */
42 4
    public function modify($url, $searchWords, $addNoCache = true, $keepCHash = false) {
43 4
        $searchWords = str_replace('&quot;', '', $searchWords);
44 4
        $searchWords = GeneralUtility::trimExplode(' ', $searchWords, true);
45
46
            /** @var UrlHelper $urlHelper */
47 4
        $urlHelper = GeneralUtility::makeInstance(UrlHelper::class, /** @scrutinizer ignore-type */ $url);
48 4
        $urlHelper->addQueryParameter('sword_list', $searchWords);
49
50 4
        if ($addNoCache) {
51 3
            $urlHelper->addQueryParameter('no_cache', '1');
52
        }
53
54 4
        if (!$keepCHash) {
55 1
            $urlHelper->removeQueryParameter('cHash');
56
        }
57
58 4
        return $urlHelper->getUrl();
59
    }
60
}
61