Test Failed
Pull Request — master (#1)
by
unknown
02:09
created

ErrorNormalizer::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 11
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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
    public function normalize($result, NormalizationContext $normalizationContext)
19
    {
20
        return [
21
            'error' => $result->getCode(),
22
            'error_description' => $result->getMessage(),
23
            'error_uri' => $result->getUri(),
24
            'error_properties' => $result->getProperties(),
25
            'error_data' => $result->getData(),
26
            'errors' => $result->getViolations() !== [] ? $result->getViolations() : null,
27
        ];
28
    }
29
30
    public function getType(): string
31
    {
32
        return Error::class;
33
    }
34
}
35