Completed
Pull Request — master (#348)
by
unknown
01:15
created

SamplerAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
18
19
/**
20
 * Class representing geo bounds aggregation.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations-bucket-sampler-aggregation.html
23
 */
24
class SamplerAggregation extends AbstractAggregation
25
{
26
    use BucketingTrait;
27
28
    public function __construct(
29
        private string $name,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
30
        private ?string $field = null,
31
        private ?int $shardSize = null
32
    ) {
33
        parent::__construct($name);
34
35
        $this->setField($field);
36
        $this->setShardSize($shardSize);
37
    }
38
39
    public function getShardSize(): ?int
40
    {
41
        return $this->shardSize;
42
    }
43
44
    public function setShardSize(?int $shardSize): static
45
    {
46
        $this->shardSize = $shardSize;
47
48
        return $this;
49
    }
50
51
    public function getType(): string
52
    {
53
        return 'sampler';
54
    }
55
56
    public function getArray(): array
57
    {
58
       return array_filter(
59
            [
60
                'field' => $this->getField(),
61
                'shard_size' => $this->getShardSize(),
62
            ]
63
        );
64
65
    }
66
}
67