EncoderCollection::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\Encoder;
4
5
use Knik\Binn\Contracts\BinnValueEncoder;
6
7
class EncoderCollection
8
{
9
    /** @var BinnValueEncoder[] */
10
    private $encoders = [];
11
12
    /** @var array */
13
    private $mapper = [];
14
15
    public function getAll(): array
16
    {
17
        return $this->encoders;
18
    }
19
20
    public function findByType(int $type): ?BinnValueEncoder
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, BinnValueEncoder $encoder): void
30
    {
31
        if (!in_array($encoder, $this->encoders, true)) {
32
            $this->encoders[] = $encoder;
33
        }
34
35
        $this->mapper[$type] = $encoder;
36
    }
37
}
38