SerializeAware::deserialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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