Passed
Push — master ( deb522...4fcdf3 )
by Gabriel
02:32
created

IsLazyLoadedTrait::isLoaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nip\Collections\Lazy\Traits;
4
5
/**
6
 * Trait IsLazyLoadedTrait
7
 * @package Nip\Collections\Lazy\Traits
8
 * @internal
9
 */
10
trait IsLazyLoadedTrait
11
{
12
    /** @var bool */
13
    protected $loaded = false;
14
15
    /**
16
     * Is the lazy collection already initialized?
17
     */
18
    public function isLoaded() : bool
19
    {
20
        return $this->loaded;
21
    }
22
23
    /**
24
     * Initialize the collection
25
     */
26 2
    protected function load() : void
27
    {
28 2
        if ($this->loaded) {
29 2
            return;
30
        }
31
32 2
        $this->loaded = true;
33 2
        $this->doLoad();
34 2
    }
35
36
    /**
37
     * Do the initialization logic
38
     */
39
    abstract protected function doLoad() : void;
40
}