LazyCollection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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