Completed
Pull Request — master (#555)
by Mantas
02:53
created

DocumentIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 23.4 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 1
cbo 3
dl 11
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getAggregation() 11 11 2
A convertDocument() 0 4 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\ElasticsearchBundle\Result;
13
14
use ONGR\ElasticsearchBundle\Result\Aggregation\ValueAggregation;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
18
/**
19
 * Class DocumentIterator.
20
 */
21
class DocumentIterator extends AbstractResultsIterator
22
{
23
    /**
24
     * @var array
25
     */
26
    private $aggregations;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __construct(array $rawData, Manager $manager, array $scroll = [])
32
    {
33
        if (isset($rawData['aggregations'])) {
34
            $this->aggregations = $rawData['aggregations'];
35
            unset($rawData['aggregations']);
36
        }
37
38
        parent::__construct($rawData, $manager, $scroll);
39
    }
40
41
    /**
42
     * Get a specific aggregation by name. It fetches from the top level only.
43
     *
44
     * @param string $name
45
     *
46
     * @return ValueAggregation|null
47
     */
48 View Code Duplication
    public function getAggregation($name)
0 ignored issues
show
Duplication introduced by
This method 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...
49
    {
50
        // TODO: remove this *** after DSL update
51
        $name = AbstractAggregation::PREFIX . $name;
52
53
        if (!isset($this->aggregations[$name])) {
54
            return null;
55
        }
56
57
        return new ValueAggregation($this->aggregations[$name]);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function convertDocument(array $document)
64
    {
65
        return $this->getConverter()->convertToDocument($document, $this->getManager());
66
    }
67
}
68