QueryPart::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\PrimoSearch;
4
5
class QueryPart
6
{
7
    protected $field;
8
    protected $precision;
9
    protected $value;
10
    protected $conjugation = 'AND';
11
12
    protected $aliases = [
13
        '=' => 'exact',
14
        '~' => 'contains',
15
        '^' => 'begins with',
16
    ];
17
18
    public function __construct($field, $precision, $value, $conjugation = 'AND')
19
    {
20
        $this->field = $field;
21
        $this->precision = $this->aliases[$precision] ?? $precision;
22
        $this->value = $value;
23
        $this->conjugation = $conjugation;
24
    }
25
26
    public function setOperator($conjugation)
27
    {
28
        $this->conjugation = $conjugation;
29
    }
30
31
    public function build()
32
    {
33
        return "{$this->field},{$this->precision},{$this->value},{$this->conjugation}";
34
    }
35
}
36