Completed
Push — master ( 9552d6...4b2b1b )
by Simonas
08:12
created

ParentIdQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A toArray() 0 10 1
1
<?php
2
3
namespace ONGR\ElasticsearchDSL\Query\Joining;
4
5
use ONGR\ElasticsearchDSL\BuilderInterface;
6
use ONGR\ElasticsearchDSL\ParametersTrait;
7
8
/**
9
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html
10
 */
11
class ParentIdQuery implements BuilderInterface
12
{
13
    use ParametersTrait;
14
15
    /**
16
     * @var string
17
     */
18
    private $childType;
19
20
    /**
21
     * @var string
22
     */
23
    private $parentId;
24
25
    /**
26
     * @param string $parentId
27
     * @param string $childType
28
     * @param array  $parameters
29
     */
30
    public function __construct($parentId, string $childType, array $parameters = [])
31
    {
32
        $this->childType = $childType;
33
        $this->parentId = $parentId;
34
        $this->setParameters($parameters);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getType()
41
    {
42
        return 'parent_id';
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function toArray()
49
    {
50
        $query = [
51
            'id' => $this->parentId,
52
            'type' => $this->childType,
53
        ];
54
        $output = $this->processArray($query);
55
56
        return [$this->getType() => $output];
57
    }
58
}
59