Passed
Pull Request — master (#13)
by
unknown
03:28
created

ErrorDenormalizer::denormalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ElevenLabs\Api\Service\Denormalizer;
6
7
use ElevenLabs\Api\Definition\ResponseDefinition;
8
use ElevenLabs\Api\Service\Pagination\Provider\PaginationProviderInterface;
9
use ElevenLabs\Api\Service\Resource\Collection;
10
use ElevenLabs\Api\Service\Resource\Error;
11
use ElevenLabs\Api\Service\Resource\ErrorInterface;
12
use ElevenLabs\Api\Service\Resource\Item;
13
use ElevenLabs\Api\Service\Resource\ResourceInterface;
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
17
18
/**
19
 * Class ErrorDenormalizer.
20
 */
21
class ErrorDenormalizer implements DenormalizerInterface
22
{
23
    /** {@inheritdoc} */
24
    public function denormalize($data, $class, $format = null, array $context = array())
25
    {
26
        /** @var ResponseInterface $response */
27
        $response = $context['response'];
28
29
        /** @var RequestInterface $request */
30
        $request = $context['request'];
0 ignored issues
show
Unused Code introduced by
The assignment to $request is dead and can be removed.
Loading history...
31
32
        /** @var ResponseDefinition $definition */
33
        $definition = $context['responseDefinition'];
0 ignored issues
show
Unused Code introduced by
The assignment to $definition is dead and can be removed.
Loading history...
34
35
        return new Error($response->getStatusCode(), $response->getReasonPhrase(), $data['violations'] ?? []);
36
    }
37
38
    /** {@inheritdoc} */
39
    public function supportsDenormalization($data, $type, $format = null)
40
    {
41
        return ErrorInterface::class === $type;
42
    }
43
}
44