FormatContainer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 25
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 11 3
A get() 0 8 2
1
<?php
2
namespace Thunder\Serializard\FormatContainer;
3
4
use Thunder\Serializard\Exception\FormatNotFoundException;
5
use Thunder\Serializard\Format\FormatInterface;
6
7
/**
8
 * @author Tomasz Kowalczyk <[email protected]>
9
 */
10
final class FormatContainer implements FormatContainerInterface
11
{
12
    private $formats = [];
13
14 16
    public function add($alias, FormatInterface $handler)
15
    {
16 16
        if(false === \is_string($alias)) {
17 1
            throw new \InvalidArgumentException('Format alias must be a string.');
18
        }
19 15
        if(array_key_exists($alias, $this->formats)) {
20
            throw new \InvalidArgumentException(sprintf('Format with alias `%s` already exists.', $alias));
21
        }
22
23 15
        $this->formats[$alias] = $handler;
24 15
    }
25
26 15
    public function get($alias)
27
    {
28 15
        if(false === array_key_exists($alias, $this->formats)) {
29 3
            throw FormatNotFoundException::fromAlias($alias);
30
        }
31
32 12
        return $this->formats[$alias];
33
    }
34
}
35