DecoderCollection::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Knik\Binn\Decoder;
4
5
use Knik\Binn\Contracts\BinnValueDecoder;
6
7
class DecoderCollection
8
{
9
    /** @var BinnValueDecoder[] */
10
    private $decoders = [];
11
12
    /** @var array */
13
    private $mapper = [];
14
15
    public function getAll(): array
16
    {
17
        return $this->decoders;
18
    }
19
20
    public function findByType(int $type): ?BinnValueDecoder
21
    {
22
        if (array_key_exists($type, $this->mapper)) {
23
            return $this->mapper[$type];
24
        }
25
26
        return null;
27
    }
28
29
    public function add(int $type, BinnValueDecoder $decoder): void
30
    {
31
        if (!in_array($decoder, $this->decoders, true)) {
32
            $this->decoders[] = $decoder;
33
        }
34
35
        $this->mapper[$type] = $decoder;
36
    }
37
}
38