QueryPart   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 0 3 1
A setOperator() 0 3 1
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