LazyCollection::doInitialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
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