AbstractCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 56
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkLazyLoad() 0 10 2
A lazyLoadInitiated() 0 3 1
1
<?php
2
3
namespace Zurbaev\ApiClient\Traits;
4
5
trait AbstractCollection
6
{
7
    /**
8
     * The collection items.
9
     *
10
     * @var array
11
     */
12
    protected $items = [];
13
14
    /**
15
     * The collection items keys.
16
     *
17
     * @var array
18
     */
19
    protected $keys = [];
20
21
    /**
22
     * Determines if lazy loading was already initiated.
23
     *
24
     * @var bool
25
     */
26
    protected $lazyLoadInitiated = false;
27
28
    /**
29
     * Performs lazy iterator items load.
30
     */
31
    abstract public function lazyLoad();
32
33
    /**
34
     * Generates item keys.
35
     */
36
    abstract public function generateKeys();
37
38
    /**
39
     * Performs lazy load checks and loads items if required.
40
     */
41
    protected function checkLazyLoad()
42
    {
43
        if ($this->lazyLoadInitiated === true) {
44
            return;
45
        }
46
47
        $this->lazyLoad();
48
        $this->generateKeys();
49
50
        $this->lazyLoadInitiated = true;
51
    }
52
53
    /**
54
     * Determines if lazy load was already initiated.
55
     *
56
     * @return bool
57
     */
58
    protected function lazyLoadInitiated(): bool
59
    {
60
        return $this->lazyLoadInitiated === true;
61
    }
62
}
63