Completed
Push — devel ( a59919...df32c1 )
by Alex
8s
created

JsonSerializer::encodeNonUtf8ToUtf8()   C

Complexity

Conditions 11
Paths 52

Size

Total Lines 41
Code Lines 23

Duplication

Lines 10
Ratio 24.39 %

Code Coverage

Tests 28
CRAP Score 11.0359

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 41
ccs 28
cts 30
cp 0.9333
rs 5.2653
cc 11
eloc 23
nc 52
nop 1
crap 11.0359

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace PSB\Core\Serialization\Json;
3
4
5
class JsonSerializer
6
{
7
    /**
8
     * @var ObjectNormalizer
9
     */
10
    private $normalizer;
11
12
    /**
13
     * @var JsonEncoder
14
     */
15
    private $encoder;
16
17
    /**
18
     * @param ObjectNormalizer $normalizer
19
     * @param JsonEncoder      $encoder
20
     */
21 3
    public function __construct(ObjectNormalizer $normalizer, JsonEncoder $encoder)
22
    {
23 3
        $this->normalizer = $normalizer;
24 3
        $this->encoder = $encoder;
25 3
    }
26
27
    /**
28
     * @param object $object
29
     *
30
     * @return string
31
     */
32 1
    public function serialize($object)
33
    {
34 1
        return $this->encoder->encode($this->normalizer->normalize($object));
35
    }
36
37
    /**
38
     * @param string $json
39
     *
40
     * @return object
41
     */
42 1
    public function unserialize($json)
43
    {
44 1
        return $this->normalizer->denormalize($this->encoder->decode($json));
45
    }
46
}
47