EncoderCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 29
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 2
A findByType() 0 7 2
A getAll() 0 3 1
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