Fuzzy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A name() 0 3 1
C compile() 0 30 7
1
<?php
2
/*
3
 * This file is part of PHPinnacle/Elastics.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace PHPinnacle\Elastics\Query;
14
15
use PHPinnacle\Elastics\Query;
16
use PHPinnacle\Elastics\Traits;
17
18
class Fuzzy implements Query
19
{
20
    use Traits\Fuzzy;
21
22
    /**
23
     * @var string
24
     */
25
    private $field;
26
27
    /**
28
     * @var string
29
     */
30
    private $value;
31
32
    /**
33
     * @param string $field
34
     * @param string $value
35
     * @param string $fuzziness
36
     */
37 7
    public function __construct(string $field, string $value, string $fuzziness = null)
38
    {
39 7
        $this->field = $field;
40 7
        $this->value = $value;
41
42 7
        if ($fuzziness !== null) {
43 1
            $this->fuzziness($fuzziness);
44
        }
45 7
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 1
    public function name(): string
51
    {
52 1
        return 'fuzzy';
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 6
    public function compile(): array
59
    {
60 6
        $options = [];
61
62 6
        if ($this->boost !== null) {
63 1
            $options['boost'] = $this->boost;
64
        }
65
66 6
        if ($this->prefixLength !== null) {
67 1
            $options['prefix_length'] = $this->prefixLength;
68
        }
69
70 6
        if ($this->maxExpansions !== null) {
71 1
            $options['max_expansions'] = $this->maxExpansions;
72
        }
73
74 6
        if ($this->fuzziness !== null) {
75 2
            $options['fuzziness'] = $this->fuzziness;
76
        }
77
78 6
        if ($this->transpositions !== null) {
79 1
            $options['transpositions'] = $this->transpositions;
80
        }
81
82 6
        return $options ? [
83 6
            $this->field => $options + [
84 6
                'value' => $this->value,
85
            ],
86
        ] : [
87 6
            $this->field => $this->value,
88
        ];
89
    }
90
}
91