HasParent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 HasParent implements Query
19
{
20
    use Traits\IgnoreUnmapped;
21
22
    /**
23
     * @var string
24
     */
25
    private $type;
26
27
    /**
28
     * @var Query
29
     */
30
    private $query;
31
32
    /**
33
     * @var bool
34
     */
35
    private $score;
36
37
    /**
38
     * @param string $type
39
     * @param Query  $query
40
     */
41
    public function __construct(string $type, Query $query)
42
    {
43
        $this->type  = $type;
44
        $this->query = $query;
45
    }
46
47
    /**
48
     * @param bool $value
49
     *
50
     * @return self
51
     */
52
    public function score(bool $value): self
53
    {
54
        $this->score = $value;
55
56
        return $this;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function name(): string
63
    {
64
        return 'has_parent';
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function compile(): array
71
    {
72
        $query = [
73
            'parent_type' => $this->type,
74
            'query'       => $this->query,
75
        ];
76
77
        if ($this->score !== null) {
78
            $query['score'] = $this->score;
79
        }
80
81
        if ($this->ignoreUnmapped !== null) {
82
            $query['ignore_unmapped'] = $this->ignoreUnmapped;
83
        }
84
85
        return $query;
86
    }
87
}
88