Passed
Push — master ( 5197c9...313b01 )
by Sébastien
04:05 queued 15s
created

Match   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
dl 0
loc 47
c 1
b 0
f 0
ccs 11
cts 11
cp 1
rs 10
1
<?php
2
3
namespace Bdf\Prime\Query\Expression;
4
5
/**
6
 * Match
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
 * @package Bdf\Prime\Query\Expression
0 ignored issues
show
Coding Style Documentation introduced by
@package tag is not allowed in class comment
Loading history...
11
 */
12
class Match implements ExpressionInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_MATCH, expecting T_STRING on line 12 at column 6
Loading history...
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $search;
18
    
19
    /**
20
     * @var mixed
21
     */
22
    protected $value;
23
    
24
    /**
25
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
26
     */
27
    protected $booleanMode;
28
    
29
    /**
30
     * Constructor
31
     * 
32
     * @param string  $search
33
     * @param array   $value
34
     * @param boolean $booleanMode
0 ignored issues
show
introduced by
Expected "bool" but found "boolean" for parameter type
Loading history...
35
     */
36 2
    public function __construct($search, $value, $booleanMode = false)
0 ignored issues
show
introduced by
Type hint "array" missing for $value
Loading history...
37
    {
38 2
        $this->search = $search;
39 2
        $this->value = $value;
40 2
        $this->booleanMode = $booleanMode;
41 2
    }
42
    
43
    /**
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...
44
     * FULLTEXT search
45
     * 
46
     * {@inheritdoc}
47
     */
48 2
    public function build($query, $compiler)
49
    {
50 2
        $sql = 'MATCH('.$compiler->quoteIdentifier($query, $query->preprocessor()->field($this->search)).' AGAINST('.$compiler->quote($this->value).')';
51
        
52 2
        if ($this->booleanMode) {
53 1
            $sql .= ' IN BOOLEAN MODE)';
54
        } else {
55 1
            $sql .= ')';
56
        }
57
        
58 2
        return $sql;
59
    }
60
}