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