Completed
Push — v0.10 ( f42b97...309689 )
by Simonas
8s
created

NestedAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 5
lcom 1
cbo 2
dl 49
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 4 4 1
A setPath() 4 4 1
A getType() 4 4 1
A getArray() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ElasticsearchBundle\DSL\Aggregation;
13
14
use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait;
15
16
/**
17
 * Class representing NestedAggregation.
18
 */
19 View Code Duplication
class NestedAggregation extends AbstractAggregation
0 ignored issues
show
Duplication introduced by
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...
20
{
21
    use BucketingTrait;
22
23
    /**
24
     * @var string
25
     */
26
    private $path;
27
28
    /**
29
     * Return path.
30
     *
31
     * @return string
32
     */
33
    public function getPath()
34
    {
35
        return $this->path;
36
    }
37
38
    /**
39
     * Sets path.
40
     *
41
     * @param string $path
42
     */
43
    public function setPath($path)
44
    {
45
        $this->path = $path;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getType()
52
    {
53
        return 'nested';
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getArray()
60
    {
61
        if (count($this->getAggregations()) == 0) {
62
            throw new \LogicException("Nested aggregation `{$this->getName()}` has no aggregations added");
63
        }
64
65
        return ['path' => $this->getPath()];
66
    }
67
}
68