Passed
Push — master ( b4e3f0...d6a119 )
by Robbie
04:16 queued 02:31
created

src/Solr/Writers/SolrSearchQueryWriterBasic.php (1 issue)

Labels
Severity
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
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