Passed
Push — master ( 80b57f...2460a5 )
by Yo
02:49
created

ComposerEncoder::encode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Serializer\Encoder;
3
4
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
5
6
class ComposerEncoder
7
{
8 2
    public function encode($data)
9
    {
10 2
        $encodedJson = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
11
12 2
        if (JSON_ERROR_NONE !== json_last_error()) {
13 1
            throw new UnexpectedValueException(json_last_error_msg());
14
        } else {
15 1
            $encodedJson .= "\n";
16
        }
17
18 1
        return $encodedJson;
19
    }
20
}
21