Completed
Push — master ( c427a2...065b11 )
by Nicolas
02:23
created

SumBucket   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 65
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A setBucketsPath() 4 4 1
A setGapPolicy() 4 4 1
A setFormat() 4 4 1
A toArray() 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
namespace Elastica\Aggregation;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * Class SumBucket.
8
 *
9
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html
10
 */
11 View Code Duplication
class SumBucket 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...
12
{
13
    /**
14
     * @param string      $name
15
     * @param string|null  $bucketsPath
16
     */
17
    public function __construct($name, $bucketsPath = null)
18
    {
19
        parent::__construct($name);
20
21
        if ($bucketsPath !== null) {
22
            $this->setBucketsPath($bucketsPath);
23
        }
24
    }
25
26
    /**
27
     * Set the buckets_path for this aggregation.
28
     *
29
     * @param string $bucketsPath
30
     *
31
     * @return $this
32
     */
33
    public function setBucketsPath($bucketsPath)
34
    {
35
        return $this->setParam('buckets_path', $bucketsPath);
36
    }
37
38
    /**
39
     * Set the gap policy for this aggregation.
40
     *
41
     * @param string $gapPolicy
42
     *
43
     * @return $this
44
     */
45
    public function setGapPolicy($gapPolicy)
46
    {
47
        return $this->setParam('gap_policy', $gapPolicy);
48
    }
49
50
    /**
51
     * Set the format for this aggregation.
52
     *
53
     * @param string $format
54
     *
55
     * @return $this
56
     */
57
    public function setFormat($format)
58
    {
59
        return $this->setParam('format', $format);
60
    }
61
62
    /**
63
     * @throws InvalidException If buckets path or script is not set
64
     *
65
     * @return array
66
     */
67
    public function toArray()
68
    {
69
        if (!$this->hasParam('buckets_path')) {
70
            throw new InvalidException('Buckets path is required');
71
        }
72
73
        return parent::toArray();
74
    }
75
}
76