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

ErrorDenormalizer::supportsDenormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
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