Encoder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Dazzle\Channel\Encoder;
4
5
use Dazzle\Channel\Protocol\ProtocolInterface;
6
use Dazzle\Util\Parser\ParserInterface;
7
8
class Encoder implements EncoderInterface
9
{
10
    /**
11
     * @var ParserInterface
12
     */
13
    protected $parser;
14
15
    /**
16
     * @var ProtocolInterface
17
     */
18
    protected $protocol;
19
20
    /**
21
     * @param ParserInterface $parser
22
     */
23 7
    public function __construct(ParserInterface $parser)
24
    {
25 7
        $this->parser = $parser;
26 7
        $this->protocol = null;
27 7
    }
28
29
    /**
30
     *
31
     */
32 5
    public function __destruct()
33
    {
34 5
        unset($this->parser);
35 5
        unset($this->protocol);
36 5
    }
37
38
    /**
39
     * @override
40
     * @inheritDoc
41
     */
42 3
    public function with(ProtocolInterface $protocol)
43
    {
44 3
        $this->protocol = $protocol;
45
46 3
        return $this;
47
    }
48
49
    /**
50
     * @override
51
     * @inheritDoc
52
     */
53 1
    public function encode()
54
    {
55 1
        return $this->parser->encode($this->protocol->getAll());
56
    }
57
58
    /**
59
     * @override
60
     * @inheritDoc
61
     */
62 1
    public function decode($str)
63
    {
64 1
        return $this->protocol->setAll($this->parser->decode($str));
65
    }
66
}
67