Completed
Push — master ( 6c9334...f3ba17 )
by Simonas
02:26
created

HasParentQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchDSL\Query\Joining;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "has_parent" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
21
 */
22 View Code Duplication
class HasParentQuery implements BuilderInterface
0 ignored issues
show
Duplication introduced by Simonas Šerlinskas
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $parentType;
30
31
    /**
32
     * @var BuilderInterface
33
     */
34
    private $query;
35
36
    /**
37
     * @param string           $parentType
38
     * @param BuilderInterface $query
39
     * @param array            $parameters
40
     */
41
    public function __construct($parentType, BuilderInterface $query, array $parameters = [])
42
    {
43
        $this->parentType = $parentType;
44
        $this->query = $query;
45
        $this->setParameters($parameters);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getType()
52
    {
53
        return 'has_parent';
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function toArray()
60
    {
61
        $query = [
62
            'parent_type' => $this->parentType,
63
            'query' => $this->query->toArray(),
64
        ];
65
66
        $output = $this->processArray($query);
67
68
        return [$this->getType() => $output];
69
    }
70
}
71