Issues (18)

Response/Handler/JsonSerializeResponseHandler.php (3 issues)

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 4
    public function __construct(private SerializerInterface $serializer)
0 ignored issues
show
The parameter $serializer is not used and could be removed. ( Ignorable by Annotation )

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

17
    public function __construct(/** @scrutinizer ignore-unused */ private SerializerInterface $serializer)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19 4
    }
20
21
    /**
22
     * @param JsonSerializeResponse $controllerResult
23
     *
24
     * @psalm-suppress MoreSpecificImplementedParamType
25
     */
26 3
    protected function generateResponse(LazyResponseInterface $controllerResult): Response
27
    {
28 3
        return new JsonResponse(
29 3
            $this->serializer->serialize($controllerResult->getData(), 'json'),
0 ignored issues
show
The method getData() 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...sponse\TemplateResponse or Basster\LazyResponseBund...e\JsonSerializeResponse. ( Ignorable by Annotation )

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

29
            $this->serializer->serialize($controllerResult->/** @scrutinizer ignore-call */ getData(), 'json'),
Loading history...
30 3
            $controllerResult->getStatusCode(),
31 3
            $controllerResult->getHeaders(),
0 ignored issues
show
The method getHeaders() does not exist on Basster\LazyResponseBund...e\LazyResponseInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Basster\LazyResponseBund...e\LazyResponseInterface. ( Ignorable by Annotation )

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

31
            $controllerResult->/** @scrutinizer ignore-call */ 
32
                               getHeaders(),
Loading history...
32 3
            true
33
        );
34
    }
35
36 3
    protected function isSupported(LazyResponseInterface $controllerResult): bool
37
    {
38 3
        return $controllerResult instanceof JsonSerializeResponse;
39
    }
40
}
41