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

IsLazyLoadedTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 7
c 1
b 0
f 1
dl 0
loc 30
rs 10
ccs 6
cts 8
cp 0.75

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isLoaded() 0 3 1
A load() 0 8 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
}