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

BinnEncoder::encode()   A

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 3
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