SolrSearchQueryWriterBasic   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateQueryString() 0 8 1
A getComparisonConjunction() 0 3 1
A getComparisonPolarity() 0 7 2
1
<?php
2
3
namespace SilverStripe\FullTextSearch\Solr\Writers;
4
5
use SilverStripe\FullTextSearch\Search\Criteria\SearchCriterion;
6
use SilverStripe\FullTextSearch\Search\Queries\AbstractSearchQueryWriter;
7
8
/**
9
 * Class SolrSearchQueryWriter_Basic
10
 * @package SilverStripe\FullTextSearch\Solr\Writers
11
 */
12
class SolrSearchQueryWriterBasic extends AbstractSearchQueryWriter
13
{
14
    /**
15
     * @var SearchCriterion $searchCriterion
16
     * @return string
17
     */
18
    public function generateQueryString(SearchCriterion $searchCriterion)
19
    {
20
        return sprintf(
21
            '%s(%s%s%s)',
22
            $this->getComparisonPolarity($searchCriterion->getComparison()),
23
            addslashes($searchCriterion->getTarget()),
24
            $this->getComparisonConjunction(),
25
            $searchCriterion->getQuoteValue($searchCriterion->getValue())
0 ignored issues
show
Bug introduced by
It seems like $searchCriterion->getValue() can also be of type array; however, parameter $value of SilverStripe\FullTextSea...terion::getQuoteValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

25
            $searchCriterion->getQuoteValue(/** @scrutinizer ignore-type */ $searchCriterion->getValue())
Loading history...
26
        );
27
    }
28
29
    /**
30
     * Is this a positive (+) or negative (-) Solr comparison.
31
     *
32
     * @param string $comparison
33
     * @return string
34
     */
35
    protected function getComparisonPolarity($comparison)
36
    {
37
        switch ($comparison) {
38
            case SearchCriterion::NOT_EQUAL:
39
                return '-';
40
            default:
41
                return '+';
42
        }
43
    }
44
45
    /**
46
     * Decide how we are comparing our left and right values.
47
     *
48
     * @return string
49
     */
50
    protected function getComparisonConjunction()
51
    {
52
        return ':';
53
    }
54
}
55