Passed
Push — master ( c493bc...401b4d )
by Nikita
03:14 queued 11s
created

BinnEncoder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 1
b 0
f 0
dl 0
loc 42
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsEncoding() 0 3 1
A decode() 0 3 1
A supportsDecoding() 0 3 1
A __construct() 0 8 3
A encode() 0 3 1
1
<?php
2
3
namespace Knik\Binn\Encoder;
4
5
use Knik\Binn\Decoder\BinnDecode;
6
use Knik\Binn\Decoder\DecoderCollectionFactory;
7
use Symfony\Component\Serializer\Encoder\DecoderInterface;
8
use Symfony\Component\Serializer\Encoder\EncoderInterface;
9
10
class BinnEncoder implements EncoderInterface, DecoderInterface
11
{
12
    public const FORMAT = 'binn';
13
14
    protected $encodingImpl;
15
    protected $decodingImpl;
16
17
    public function __construct(BinnEncode $encodingImpl = null, BinnDecode $decodingImpl = null)
18
    {
19
        $this->encodingImpl = $encodingImpl ?: new BinnEncode(
20
            (new EncoderCollectionFactory())->getCollection()
21
        );
22
23
        $this->decodingImpl = $decodingImpl ?: new BinnDecode(
24
            (new DecoderCollectionFactory())->getCollection()
25
        );
26
    }
27
28
    public function decode(string $data, string $format, array $context = [])
29
    {
30
        return $this->decodingImpl->decode($data, $format, $context);
31
    }
32
33
    public function encode($data, string $format, array $context = [])
34
    {
35
        return $this->encodingImpl->encode($data, $format, $context);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function supportsEncoding(string $format)
42
    {
43
        return self::FORMAT === $format;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function supportsDecoding(string $format)
50
    {
51
        return self::FORMAT === $format;
52
    }
53
}
54