Completed
Push — master ( 2a17c4...6c9334 )
by Simonas
02:29
created

DiversifiedSamplerAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getShardSize() 4 4 1
A setShardSize() 4 4 1
A getType() 4 4 1
A getArray() 11 11 1

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\ElasticsearchDSL\Aggregation\Bucketing;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
16
17
/**
18
 * Class representing geo diversified sampler aggregation.
19
 *
20
 * @link https://goo.gl/yzXvqD
21
 */
22 View Code Duplication
class DiversifiedSamplerAggregation extends AbstractAggregation
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 BucketingTrait;
25
26
    /**
27
     * Defines how many results will be received from each shard
28
     * @param integer $shardSize
29
     */
30
    private $shardSize;
31
32
    /**
33
     * DiversifiedSamplerAggregation constructor.
34
     *
35
     * @param string $name Aggregation name
36
     * @param string $field Elasticsearch field name
37
     * @param int $shardSize Shard size, by default it's 100
38
     */
39
    public function __construct($name, $field = null, $shardSize = null)
40
    {
41
        parent::__construct($name);
42
43
        $this->setField($field);
44
        $this->setShardSize($shardSize);
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    public function getShardSize()
51
    {
52
        return $this->shardSize;
53
    }
54
55
    /**
56
     * @param mixed $shardSize
57
     */
58
    public function setShardSize($shardSize)
59
    {
60
        $this->shardSize = $shardSize;
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function getType()
67
    {
68
        return 'diversified_sampler';
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    protected function getArray()
75
    {
76
        $out = array_filter(
77
            [
78
                'field' => $this->getField(),
79
                'shard_size' => $this->getShardSize(),
80
            ]
81
        );
82
83
        return $out;
84
    }
85
}
86