ErrorNormalizer::normalize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Maba\Bundle\RestBundle\Normalizer;
5
6
use Maba\Bundle\RestBundle\Entity\Error;
7
use Paysera\Component\Normalization\NormalizationContext;
8
use Paysera\Component\Normalization\NormalizerInterface;
9
use Paysera\Component\Normalization\TypeAwareInterface;
10
11
class ErrorNormalizer implements NormalizerInterface, TypeAwareInterface
12
{
13
    /**
14
     * @param Error $result
15
     * @param NormalizationContext $normalizationContext
16
     * @return array
17
     */
18 33
    public function normalize($result, NormalizationContext $normalizationContext)
19
    {
20
        return [
21 33
            'error' => $result->getCode(),
22 33
            'error_description' => $result->getMessage(),
23 33
            'error_uri' => $result->getUri(),
24 33
            'error_properties' => $result->getProperties(),
25 33
            'error_data' => $result->getData(),
26 33
            'errors' => $result->getViolations() !== [] ? $result->getViolations() : null,
27
        ];
28
    }
29
30 81
    public function getType(): string
31
    {
32 81
        return Error::class;
33
    }
34
}
35