Container   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 64
rs 10
c 1
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A forget() 0 4 2
A set() 0 4 2
A has() 0 3 1
1
<?php
2
3
/**
4
 * Container.php
5
 *
6
 * This is the internal storage container for test suites.
7
 *
8
 * PHP version 7.4
9
 *
10
 * @category Core
11
 * @package  RedboxTestSuite
12
 * @author   Johnny Mast <[email protected]>
13
 * @license  https://opensource.org/licenses/MIT MIT
14
 * @link     https://github.com/johnnymast/redbox-testsuite
15
 * @since    1.0
16
 */
17
18
namespace Redbox\Testsuite;
19
20
use Redbox\Testsuite\Interfaces\ContainerInterface;
21
22
/**
23
 * Class Container
24
 *
25
 * @package Redbox\Testsuite
26
 */
27
class Container implements ContainerInterface
28
{
29
    /**
30
     * Internal storage for the container.
31
     *
32
     * @var array
33
     */
34
    protected array $storage = [];
35
    
36
    /**
37
     * Check to see if any information has been stored in the
38
     * container using the provided key.
39
     *
40
     * @param string $key The identification key.
41
     *
42
     * @return bool
43
     */
44
    public function has(string $key): bool
45
    {
46
        return isset($this->storage[$key]);
47
    }
48
    
49
    /**
50
     * Return a value from the container with a key.
51
     *
52
     * @param string $key The identification key.
53
     *
54
     * @return mixed|bool
55
     */
56
    public function get(string $key)
57
    {
58
        if ($this->has($key)) {
59
            return $this->storage[$key];
60
        }
61
        
62
        return false;
63
    }
64
    
65
    /**
66
     * Store a value in the container indicated by this key.
67
     *
68
     * @param string $key   The identification key.
69
     * @param mixed  $value The value for the $key.
70
     *
71
     * @return void
72
     */
73
    public function set(string $key, $value): void
74
    {
75
        if (!is_null($key)) {
0 ignored issues
show
introduced by
The condition is_null($key) is always false.
Loading history...
76
            $this->storage[$key] = $value;
77
        }
78
    }
79
    
80
    /**
81
     * Forget a value in the container by this key.
82
     *
83
     * @param string $key The key to forget.
84
     *
85
     * @return void
86
     */
87
    public function forget(string $key): void
88
    {
89
        if ($this->has($key)) {
90
            unset($this->storage[$key]);
91
        }
92
    }
93
}
94