CollectionObjectTransformer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B supports() 0 10 5
A transform() 0 15 2
1
<?php
2
3
namespace CCT\Kong\Transformer\Response;
4
5
use CCT\Kong\Model\Response\ContentCollection;
6
use CCT\Kong\Transformer\SerializerTransformer;
7
use CCT\Kong\Http\ResponseInterface;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class CollectionObjectTransformer extends SerializerTransformer
11
{
12
    /**
13
     * @param ResponseInterface|Response $response
14
     *
15
     * {@inheritdoc}
16
     */
17 5
    public function transform(ResponseInterface $response)
18
    {
19 5
        $data = $response->getData();
20
21 5
        foreach ($data['data'] as $k => $object) {
22 5
            $data['data'][$k] = $this->serializer->deserialize(
23 5
                json_encode($object),
24 5
                $this->class,
25 5
                'json',
26 5
                $this->context
0 ignored issues
show
Bug introduced by
It seems like $this->context can also be of type JMS\Serializer\SerializationContext; however, parameter $context of JMS\Serializer\Serializer::deserialize() does only seem to accept null|JMS\Serializer\DeserializationContext, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
                /** @scrutinizer ignore-type */ $this->context
Loading history...
27
            );
28
        }
29
30 5
        $data = new ContentCollection($data);
31 5
        $response->setData($data);
32 5
    }
33
34
    /**
35
     * @param ResponseInterface|Response $response
36
     *
37
     * {@inheritdoc}
38
     */
39 35
    public function supports(ResponseInterface $response): bool
40
    {
41 35
        $data = $response->getData();
42
43
        return (
44 35
            is_array($data)
45 35
            && isset($data['data'])
46 35
            && isset($data['total'])
47 35
            && $response->isSuccessful()
0 ignored issues
show
Bug introduced by
The method isSuccessful() does not exist on CCT\Kong\Http\ResponseInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to CCT\Kong\Http\ResponseInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            && $response->/** @scrutinizer ignore-call */ isSuccessful()
Loading history...
48 35
            && !empty($data)
49
        );
50
    }
51
}