ContentLengthMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 10 3
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