OptionsStack::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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