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

ErrorDenormalizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 0 6 1
A supportsDenormalization() 0 3 1
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
        return new Error($response->getStatusCode(), $response->getReasonPhrase(), $data['violations'] ?? []);
30
    }
31
32
    /** {@inheritdoc} */
33
    public function supportsDenormalization($data, $type, $format = null)
34
    {
35
        return ErrorInterface::class === $type;
36
    }
37
}
38