Completed
Push — master ( 136e36...8f19ec )
by Nicolas
02:02
created

StatsBucket   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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