ObjectTransformer::supports()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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