Issues (1)

src/Middleware/ContentLengthMiddleware.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace HttpSoft\Basis\Middleware;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
12
final class ContentLengthMiddleware implements MiddlewareInterface
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17 45
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
18
    {
19 45
        $response = $handler->handle($request);
20 37
        $size = $response->getBody()->getSize();
21
22 37
        if ($size !== null && !$response->hasHeader('content-length')) {
23 37
            $response = $response->withHeader('content-length', (string) $size);
24
        }
25
26 37
        return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response could return the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
27
    }
28
}
29