SymfonyDecoderAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace ElevenLabs\Api\Decoder\Adapter;
3
4
use ElevenLabs\Api\Decoder\DecoderInterface;
5
use Symfony\Component\Serializer\Encoder\DecoderInterface as SymfonyDecoderInterface;
6
7
class SymfonyDecoderAdapter implements DecoderInterface
8
{
9
    /**
10
     * @var SymfonyDecoderInterface
11
     */
12
    private $decoder;
13 10
14
    public function __construct(SymfonyDecoderInterface $decoder)
15 10
    {
16 10
        $this->decoder = $decoder;
17
    }
18 5
19
    public function decode($data, $format)
20 5
    {
21
        $context = [];
22 5
23
        if ($format === 'json') {
24 4
            // the JSON schema validator need an object hierarchy
25
            $context['json_decode_associative'] = false;
26
        }
27 5
28
        $decoded = $this->decoder->decode($data, $format, $context);
29 5
30
        if ($format === 'xml') {
31 1
            // the JSON schema validator need an object hierarchy
32
            $decoded = json_decode(json_encode($decoded));
33
        }
34 5
35
        return $decoded;
36
    }
37
}
38