InstanceCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A set() 0 3 1
A has() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Container;
6
7
class InstanceCollection
8
{
9
    /** @var array<mixed>  */
10
    private array $instances;
11
12 21
    public function __construct()
13
    {
14 21
        $this->instances = [];
15 21
    }
16
17
    /**
18
     * @param mixed $instance
19
     */
20 21
    public function set(string $id, $instance): void
21
    {
22 21
        $this->instances[$id] = $instance;
23 21
    }
24
25
    /**
26
     * @param int|string $id
27
     * @return bool
28
     */
29 19
    public function has($id): bool
30
    {
31 19
        return array_key_exists($id, $this->instances);
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37 17
    public function get(string $id)
38
    {
39 17
        return $this->instances[$id];
40
    }
41
}
42