Code Duplication    Length = 65-77 lines in 2 locations

lib/Elastica/Aggregation/SerialDiff.php 1 location

@@ 11-87 (lines=77) @@
8
 *
9
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
10
 */
11
class SerialDiff extends AbstractAggregation
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 lag for this aggregation.
40
     *
41
     * @param int $lag
42
     *
43
     * @return $this
44
     */
45
    public function setLag($lag)
46
    {
47
        return $this->setParam('lag', $lag);
48
    }
49
50
    /**
51
     * Set the gap policy for this aggregation.
52
     *
53
     * @param string $gapPolicy
54
     *
55
     * @return $this
56
     */
57
    public function setGapPolicy($gapPolicy)
58
    {
59
        return $this->setParam('gap_policy', $gapPolicy);
60
    }
61
62
    /**
63
     * Set the format for this aggregation.
64
     *
65
     * @param string $format
66
     *
67
     * @return $this
68
     */
69
    public function setFormat($format)
70
    {
71
        return $this->setParam('format', $format);
72
    }
73
74
    /**
75
     * @throws InvalidException If buckets path is not set
76
     *
77
     * @return array
78
     */
79
    public function toArray()
80
    {
81
        if (!$this->hasParam('buckets_path')) {
82
            throw new InvalidException('Buckets path is required');
83
        }
84
85
        return parent::toArray();
86
    }
87
}
88

lib/Elastica/Aggregation/StatsBucket.php 1 location

@@ 12-76 (lines=65) @@
9
 *
10
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-stats-bucket-aggregation.html
11
 */
12
class StatsBucket extends AbstractAggregation
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