SymfonyDecoderAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 17 3
A __construct() 0 3 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