Passed
Pull Request — master (#2985)
by
unknown
34:31
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);
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...er::addQueryParameter() has been deprecated: Will be removed with v12. Use withQueryParameter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        /** @scrutinizer ignore-deprecated */ $urlHelper->addQueryParameter('sword_list', $searchWords);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
50 4
        if ($addNoCache) {
51 3
            $urlHelper->addQueryParameter('no_cache', '1');
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...er::addQueryParameter() has been deprecated: Will be removed with v12. Use withQueryParameter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
            /** @scrutinizer ignore-deprecated */ $urlHelper->addQueryParameter('no_cache', '1');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
52
        }
53
54 4
        if (!$keepCHash) {
55 1
            $urlHelper->removeQueryParameter('cHash');
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...:removeQueryParameter() has been deprecated: Will be removed with v12. Use withoutQueryParameter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

55
            /** @scrutinizer ignore-deprecated */ $urlHelper->removeQueryParameter('cHash');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
56
        }
57
58 4
        return $urlHelper->getUrl();
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...Url\UrlHelper::getUrl() has been deprecated: Will be removed with v12. Use __toString() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

58
        return /** @scrutinizer ignore-deprecated */ $urlHelper->getUrl();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
59
    }
60
}
61