Passed
Push — master ( af5995...9e02f8 )
by Ole
02:03
created

Response/Handler/JsonSerializeResponseHandler.php (1 issue)

1
<?php
2
declare(strict_types=1);
3
4
namespace Basster\LazyResponseBundle\Response\Handler;
5
6
use Basster\LazyResponseBundle\Response\JsonSerializeResponse;
7
use Basster\LazyResponseBundle\Response\LazyResponseInterface;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Serializer\SerializerInterface;
11
12
/**
13
 * Class JsonSerializeResponseHandler.
14
 */
15
final class JsonSerializeResponseHandler extends AbstractLazyResponseHandler
16
{
17
    /**
18
     * @var \Symfony\Component\Serializer\SerializerInterface
19
     */
20
    private $serializer;
21
22 4
    public function __construct(SerializerInterface $serializer)
23
    {
24 4
        $this->serializer = $serializer;
25 4
    }
26
27
    /**
28
     * @param JsonSerializeResponse $controllerResult
29
     *
30
     * @psalm-suppress MoreSpecificImplementedParamType
31
     */
32 3
    protected function generateResponse(LazyResponseInterface $controllerResult): Response
33
    {
34 3
        return new JsonResponse(
35 3
            $this->serializer->serialize($controllerResult->getData(), 'json'),
36 3
            $controllerResult->getStatus(),
0 ignored issues
show
The method getStatus() does not exist on Basster\LazyResponseBund...e\LazyResponseInterface. It seems like you code against a sub-type of Basster\LazyResponseBund...e\LazyResponseInterface such as Basster\LazyResponseBund...bstractLazyHttpResponse. ( Ignorable by Annotation )

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

36
            $controllerResult->/** @scrutinizer ignore-call */ 
37
                               getStatus(),
Loading history...
37 3
            $controllerResult->getHeaders(),
38
        );
39
    }
40
41 3
    protected function isSupported(LazyResponseInterface $controllerResult): bool
42
    {
43 3
        return $controllerResult instanceof JsonSerializeResponse;
44
    }
45
}
46