Lines 80.00% 4 / 5
Functions and Methods 66.66% 2 / 3
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Container 80.00% 4 / 5 66.66% 2 / 3 4.13 0.00% 0 / 1
 get 66.66% 2 / 3 0.00% 0 / 1 2.15
 has 100.00% 1 / 1 100.00% 1 / 1 1
 set 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3/**
4 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
5 **/
6
7declare(strict_types=1);
8
9namespace BO\Slim;
10
11use Psr\Container\ContainerInterface;
12use Psr\Container\NotFoundExceptionInterface;
13use BO\Slim\Exception\UnknownIdentifierException;
14
15/**
16 * PSR compatible container implementation, compatible with the ArrayAccess usage in zms
17 *
18 * @extends \ArrayObject<array-key, mixed>
19 */
20class Container extends \ArrayObject implements ContainerInterface
21{
22    /**
23     * @param string $id
24     * @return mixed
25     *
26     * @throws NotFoundExceptionInterface
27     */
28    #[\Override]
29    public function get(string $id)
30    {
31        if (!$this->has($id)) {
32            throw new UnknownIdentifierException('The container has no value identified by ' . $id);
33        }
34
35        return $this->offsetGet($id);
36    }
37
38    /**
39     * @param string $id The value identifier
40     *
41     * @return bool
42     */
43    #[\Override]
44    public function has(string $id): bool
45    {
46        return $this->offsetExists($id);
47    }
48
49    /**
50     * @param string $identifier
51     * @param mixed $value
52     */
53    public function set(string $identifier, $value): void
54    {
55        $this->offsetSet($identifier, $value);
56    }
57}