Passed
Push — master ( 9218d1...27873b )
by Alexander
02:19
created

src/Middleware/TagRequest.php (1 issue)

1
<?php
2
namespace Yiisoft\Yii\Web\Middleware;
3
4
use Psr\Http\Message\ResponseInterface;
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr\Http\Server\MiddlewareInterface;
7
use Psr\Http\Server\RequestHandlerInterface;
8
9
/**
10
 * Tags request with a random value that could be later used for identifying it.
11
 */
12
class TagRequest implements MiddlewareInterface
13
{
14
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
15
    {
16
        $handler->handle($request->withAttribute('requestTag', $this->getRequestTag()));
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Psr\Http\Message\ResponseInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
17
    }
18
19
    protected function getRequestTag(): string
20
    {
21
        return dechex(microtime(true) * 1000000);
22
    }
23
}
24