Passed
Pull Request — master (#182)
by Arman
12:44 queued 09:39
created

DebuggerStore::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Quantum PHP Framework
4
 *
5
 * An open source software development framework for PHP
6
 *
7
 * @package Quantum
8
 * @author Arman Ag. <[email protected]>
9
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
10
 * @link http://quantum.softberg.org/
11
 * @since 2.9.5
12
 */
13
14
namespace Quantum\Debugger;
15
16
use Quantum\Contracts\StorageInterface;
17
18
/**
19
 * Class DebuggerStore
20
 * @package Quantum\Debugger
21
 */
22
class DebuggerStore implements StorageInterface
23
{
24
    private static $store = [];
25
26
    /**
27
     * @param array $keys
28
     * @return void
29
     */
30
    public function init(array $keys)
31
    {
32
        foreach ($keys as $key) {
33
            if (!isset(self::$store[$key])) {
34
                self::$store[$key] = [];
35
            }
36
        }
37
    }
38
39
    /**
40
     * @return array[]
41
     */
42
    public function all(): array
43
    {
44
        return self::$store;
45
    }
46
47
    /**
48
     * @param string $key
49
     * @return bool
50
     */
51
    public function has(string $key): bool
52
    {
53
        return isset(self::$store[$key]);
54
    }
55
56
    /**
57
     * @param string $key
58
     * @return array
59
     */
60
    public function get(string $key): array
61
    {
62
        return self::$store[$key] ?? [];
63
    }
64
65
    /**
66
     * @param string $key
67
     * @param mixed $value
68
     * @return void
69
     */
70
    public function set(string $key, $value)
71
    {
72
        if (is_array($value)) {
73
            foreach ($value as $level => $data) {
74
                self::$store[$key][] = [$level => $data];
75
            }
76
        }
77
    }
78
79
    /**
80
     * @param string $key
81
     * @return void
82
     */
83
    public function delete(string $key)
84
    {
85
        if ($this->has($key)) {
86
            self::$store[$key] = [];
87
        }
88
    }
89
90
    /**
91
     * @return void
92
     */
93
    public function flush()
94
    {
95
        self::$store = [];
96
    }
97
}
98