ObjectIterator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A convertDocument() 0 4 1
A doInitialize() 0 6 1
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 Doctrine\Common\Collections\AbstractLazyCollection;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use ONGR\ElasticsearchBundle\Mapping\Converter;
17
18
/**
19
 * This is for embedded ObjectType's or NestedType's iterator implemented with a lazy loading.
20
 */
21
class ObjectIterator extends AbstractLazyCollection
22
{
23
    private $converter;
24
    protected $collection;
25
    private $namespace;
26
27
    public function __construct(string $namespace, array $array, Converter $converter)
28
    {
29
        $this->converter = $converter;
30
        $this->collection = new ArrayCollection($array);
31
        $this->namespace = $namespace;
32
    }
33
34
    protected function convertDocument(array $data)
35
    {
36
        return $this->converter->convertArrayToDocument($this->namespace, $data);
37
    }
38
39
    protected function doInitialize()
40
    {
41
        $this->collection = $this->collection->map(function ($rawObject) {
42
            return $this->convertDocument($rawObject);
43
        });
44
    }
45
}
46