Test Failed
Push — master ( fc3669...075daf )
by Sébastien
08:09
created

FullTextMatch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Bdf\Prime\Query\Expression;
4
5
/**
6
 * FullTextMatch
7
 * 
8
 * The fulltext search expression
0 ignored issues
show
introduced by
Doc comment long description must end with a full stop
Loading history...
9
 */
10
class FullTextMatch implements ExpressionInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $search;
16
    
17
    /**
18
     * @var mixed
19
     */
20
    protected $value;
21
    
22
    /**
23
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
24
     */
25
    protected $booleanMode;
26
    
27
    /**
28
     * Constructor
29
     * 
30
     * @param string  $search
31
     * @param array   $value
32
     * @param boolean $booleanMode
0 ignored issues
show
introduced by
Expected "bool" but found "boolean" for parameter type
Loading history...
33
     */
34
    public function __construct($search, $value, $booleanMode = false)
0 ignored issues
show
introduced by
Type hint "array" missing for $value
Loading history...
35
    {
36
        $this->search = $search;
37
        $this->value = $value;
38
        $this->booleanMode = $booleanMode;
39
    }
40
    
41
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $query should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $compiler should have a doc-comment as per coding-style.
Loading history...
42
     * FULLTEXT search
43
     * 
44
     * {@inheritdoc}
45
     */
46
    public function build($query, $compiler)
47
    {
48
        $sql = 'MATCH('.$compiler->quoteIdentifier($query, $query->preprocessor()->field($this->search)).' AGAINST('.$compiler->quote($this->value).')';
49
        
50
        if ($this->booleanMode) {
51
            $sql .= ' IN BOOLEAN MODE)';
52
        } else {
53
            $sql .= ')';
54
        }
55
        
56
        return $sql;
57
    }
58
}
59