ProxyContainer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 4 1
A set() 0 4 1
A get() 0 13 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Proxy;
5
6
use Moka\Exception\InvalidIdentifierException;
7
use Psr\Container\ContainerInterface;
8
9
/**
10
 * Class ProxyContainer
11
 * @package Moka\Proxy
12
 */
13
final class ProxyContainer implements ContainerInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    private $mocks;
19
20
    /**
21
     * ProxyContainer constructor.
22
     */
23 12
    public function __construct()
24
    {
25 12
        $this->mocks = [];
26
    }
27
28
    /**
29
     * @param string $id
30
     * @return ProxyInterface
31
     *
32
     * @throws InvalidIdentifierException
33
     */
34 8
    public function get($id): ProxyInterface
35
    {
36 8
        if (!$this->has($id)) {
37 1
            throw new InvalidIdentifierException(
38 1
                sprintf(
39 1
                    'Cannot find mock object with identifier "%s"',
40
                    $id
41
                )
42
            );
43
        }
44
45 7
        return $this->mocks[$id];
46
    }
47
48
    /**
49
     * @param string $id
50
     * @return bool
51
     */
52 13
    public function has($id): bool
53
    {
54 13
        return isset($this->mocks[$id]);
55
    }
56
57
    /**
58
     * @param string $id
59
     * @param ProxyInterface $mock
60
     */
61 10
    public function set(string $id, ProxyInterface $mock)
62
    {
63 10
        $this->mocks[$id] = $mock;
64
    }
65
}
66