Completed
Push — master ( 0b8f98...686b93 )
by Arnold
08:12 queued 08:12
created

InitializeTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 44
ccs 4
cts 6
cp 0.6667
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setInitializeOption() 0 3 2
A requireInitialization() 0 3 2
A getInitializeOption() 0 3 1
1
<?php
2
/**
3
 * This file is part of the Cache package.
4
 *
5
 * Copyright (c) Daniel González
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Daniel González <[email protected]>
11
 * @author Arnold Daniels <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Desarrolla2\Cache\Option;
17
18
/**
19
 * Auto initialize the cache
20
 */
21
trait InitializeTrait
22
{
23
    /**
24
     * Is cache initialized
25
     * @var bool|null
26
     */
27
    protected $initialized = false;
28
29
30
    /**
31
     * Enable/disable initialization
32
     *
33
     * @param bool $enabled
34
     */
35 395
    public function setInitializeOption(bool $enabled)
36
    {
37 395
        $this->initialized = $enabled ? (bool)$this->initialized : null;
38
    }
39
40
    /**
41
     * Should initialize
42
     *
43
     * @return bool
44
     */
45
    protected function getInitializeOption(): bool
46
    {
47
        return $this->initialized !== null;
48
    }
49
50
    /**
51
     * Mark as initialization required (if enabled)
52
     */
53 198
    protected function requireInitialization()
54
    {
55 198
        $this->initialized = isset($this->initialized) ? false : null;
56
    }
57
58
59
    /**
60
     * Initialize
61
     *
62
     * @return void
63
     */
64
    abstract protected function initialize(): void;
65
}
66