LazyCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 11
cp 0.9091
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollection() 0 5 1
A doInitialize() 0 8 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\SkeletonMapper\Collections;
6
7
use Doctrine\Common\Collections\AbstractLazyCollection;
8
use Doctrine\Common\Collections\Collection;
9
use function call_user_func;
10
11
class LazyCollection extends AbstractLazyCollection
12
{
13
    /** @var callable|null */
14
    private $callback;
15
16 4
    public function __construct(callable $callback)
17
    {
18 4
        $this->callback = $callback;
19 4
    }
20
21
    /**
22
     * @return object[]|Collection
23
     */
24 1
    public function getCollection() : Collection
25
    {
26 1
        $this->initialize();
27
28 1
        return $this->collection;
29
    }
30
31 2
    protected function doInitialize() : void
32
    {
33 2
        if ($this->callback === null) {
34
            return;
35
        }
36
37 2
        $this->collection = call_user_func($this->callback);
38 2
        $this->callback   = null;
39 2
    }
40
}
41