OptionsStack   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A set() 0 3 1
A get() 0 7 2
A __construct() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\Drupal\Debug\Option;
15
16
class OptionsStack
17
{
18
    /**
19
     * @var OptionsInterface[]
20
     */
21
    private $optionsStack;
22
23
    /**
24
     * @param OptionsInterface[] $options
25
     */
26 19
    private function __construct(array $options)
27
    {
28 19
        $this->optionsStack = array();
29
30 19
        foreach ($options as $option) {
31 2
            $this->set($option);
32
        }
33 19
    }
34
35
    /**
36
     * @param OptionsInterface[] $options
37
     *
38
     * @return OptionsStack
39
     */
40 19
    public static function create(array $options = array()): self
41
    {
42 19
        return new self($options);
43
    }
44
45
    /**
46
     * @param string $class
47
     *
48
     * @return OptionsInterface|null
49
     */
50 2
    public function get(string $class): ?OptionsInterface
51
    {
52 2
        if (!isset($this->optionsStack[$class])) {
53 1
            return null;
54
        }
55
56 1
        return $this->optionsStack[$class];
57
    }
58
59
    /**
60
     * @param OptionsInterface $options
61
     */
62 4
    public function set(OptionsInterface $options): void
63
    {
64 4
        $this->optionsStack[\get_class($options)] = $options;
65 4
    }
66
}
67