EncoderCollection::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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