SerializeAware::setSerializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Aeq\Hal\Serializer;
3
4
trait SerializeAware
5
{
6
    /**
7
     * @var SerializerInterface
8
     */
9
    private $serializer;
10
11
    /**
12
     * @param object|array $data
13
     * @return string
14
     */
15
    public function serialize($data)
16
    {
17
        if ($this->serializer instanceof SerializerInterface) {
18
            return $this->serializer->serialize($data);
19
        }
20
        throw new \LogicException(sprintf('no client adapter set for "%s"', __CLASS__), 1460016545);
21
    }
22
23
    /**
24
     * @param string $str
25
     * @return array
26
     */
27 5
    public function deserialize($str)
28
    {
29 5
        if ($this->serializer instanceof SerializerInterface) {
30 5
            return $this->serializer->deserialize($str);
31
        }
32
        throw new \LogicException(sprintf('no client adapter set for "%s"', __CLASS__), 1460016579);
33
    }
34
35
    /**
36
     * @param SerializerInterface $serializer
37
     */
38 6
    public function setSerializer(SerializerInterface $serializer)
39
    {
40 6
        $this->serializer = $serializer;
41 6
    }
42
}
43