These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types = 1); |
||
2 | /* |
||
3 | * This file is part of the KleijnWeb\PhpApi\Descriptions package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | */ |
||
8 | namespace KleijnWeb\PhpApi\Middleware; |
||
9 | |||
10 | use Interop\Http\ServerMiddleware\DelegateInterface; |
||
11 | use KleijnWeb\PhpApi\Middleware\Body\BodySerializer; |
||
12 | use KleijnWeb\PhpApi\Middleware\Util\PhpApiMiddleware; |
||
13 | use KleijnWeb\PhpApi\Hydrator\Hydrator; |
||
14 | use Psr\Http\Message\ResponseInterface; |
||
15 | use Psr\Http\Message\ServerRequestInterface; |
||
16 | |||
17 | class ResponseBodyDehydrator extends PhpApiMiddleware |
||
18 | { |
||
19 | /** |
||
20 | * @var Hydrator |
||
21 | */ |
||
22 | private $hydrator; |
||
23 | |||
24 | /** |
||
25 | * @var BodySerializer|OkStatusResolver |
||
26 | */ |
||
27 | private $okStatusResolver; |
||
28 | |||
29 | /** |
||
30 | * @param Hydrator $hydrator |
||
31 | * @param OkStatusResolver|null $okStatusResolver |
||
32 | */ |
||
33 | public function __construct(Hydrator $hydrator, OkStatusResolver $okStatusResolver = null) |
||
34 | { |
||
35 | $this->hydrator = $hydrator; |
||
36 | $this->okStatusResolver = $okStatusResolver ?: new OkStatusResolver(); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Process a server request and return a response. |
||
41 | * |
||
42 | * @param ServerRequestInterface $request |
||
43 | * @param DelegateInterface $delegate |
||
44 | * |
||
45 | * @return ResponseInterface |
||
46 | */ |
||
47 | public function process(ServerRequestInterface $request, DelegateInterface $delegate) |
||
48 | { |
||
49 | if (null !== ($data = $request->getAttribute(CommandDispatcher::ATTRIBUTE))) { |
||
50 | $operation = $this->getOperation($request); |
||
51 | $schema = $operation |
||
52 | ->getResponse($this->okStatusResolver->resolve($data, $operation)) |
||
0 ignored issues
–
show
|
|||
53 | ->getSchema(); |
||
54 | |||
55 | $request = $request->withAttribute( |
||
56 | CommandDispatcher::ATTRIBUTE, |
||
57 | $this->hydrator->dehydrate($data, $schema) |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | return $delegate->process($request); |
||
62 | } |
||
63 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: