ComposerEncoder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 12 2
A decode() 0 10 2
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Serializer\Encoder;
3
4
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
5
6
class ComposerEncoder
7
{
8
    /**
9
     * @param mixed $data
10
     *
11
     * @return string
12
     */
13 2
    public function encode($data)
14
    {
15 2
        $encodedJson = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
16
17 2
        if (JSON_ERROR_NONE !== json_last_error()) {
18 1
            throw new UnexpectedValueException(json_last_error_msg());
19
        } else {
20 1
            $encodedJson .= "\n";
21
        }
22
23 1
        return $encodedJson;
24
    }
25
26
    /**
27
     * @param string $data
28
     *
29
     * @return mixed
30
     */
31 2
    public function decode($data)
32
    {
33 2
        $decoded = json_decode($data, true);
34
35 2
        if (JSON_ERROR_NONE !== json_last_error()) {
36 1
            throw new UnexpectedValueException(json_last_error_msg());
37
        }
38
39 1
        return $decoded;
40
    }
41
}
42