Encoder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 59
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __destruct() 0 5 1
A with() 0 6 1
A encode() 0 4 1
A decode() 0 4 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