ObjectTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 10 1
A supports() 0 8 3
1
<?php
2
3
namespace CCT\Kong\Transformer\Response;
4
5
use CCT\Kong\Http\Response;
6
use CCT\Kong\Transformer\SerializerTransformer;
7
use CCT\Kong\Http\ResponseInterface;
8
9
class ObjectTransformer extends SerializerTransformer
10
{
11
    /**
12
     * @param ResponseInterface|Response $response
13
     *
14
     * {@inheritdoc}
15
     */
16 19
    public function transform(ResponseInterface $response)
17
    {
18 19
        $data = $this->serializer->deserialize(
19 19
            $response->getContent(),
0 ignored issues
show
Bug introduced by
The method getContent() 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

19
            $response->/** @scrutinizer ignore-call */ 
20
                       getContent(),
Loading history...
20 19
            $this->class,
21 19
            'json',
22 19
            $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

22
            /** @scrutinizer ignore-type */ $this->context
Loading history...
23
        );
24
25 19
        $response->setData($data);
26 19
    }
27
28
    /**
29
     * @param ResponseInterface|Response $response
30
     *
31
     * {@inheritdoc}
32
     */
33 35
    public function supports(ResponseInterface $response): bool
34
    {
35 35
        $data = $response->getData();
36
37
        return
38 35
            false === isset($data['data'])
39 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

39
            && $response->/** @scrutinizer ignore-call */ isSuccessful()
Loading history...
40 35
            && !empty($data)
41
        ;
42
    }
43
}
44