These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * slince middleware library |
||
4 | * @author Tao <[email protected]> |
||
5 | */ |
||
6 | namespace Slince\Middleware; |
||
7 | |||
8 | use Interop\Http\ServerMiddleware\MiddlewareInterface; |
||
9 | use Psr\Http\Message\ServerRequestInterface; |
||
10 | use Slince\Middleware\Exception\MissingResponseException; |
||
11 | |||
12 | class MiddlewareQueue |
||
13 | { |
||
14 | /** |
||
15 | * @var \SplQueue |
||
16 | */ |
||
17 | public $middlewares; |
||
18 | |||
19 | public function __construct(array $middlewares = []) |
||
20 | { |
||
21 | $this->middlewares = new \SplQueue(); |
||
22 | foreach ($middlewares as $middleware) { |
||
23 | $this->push($middleware); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Add a middleware to the queue |
||
29 | * @param callable|MiddlewareInterface $middleware |
||
30 | */ |
||
31 | public function push($middleware) |
||
32 | { |
||
33 | if (is_callable($middleware)) { |
||
34 | $middleware = static::decorateCallableMiddleware($middleware); |
||
35 | } |
||
36 | $this->middlewares->enqueue($middleware); |
||
37 | } |
||
38 | |||
39 | public function process(ServerRequestInterface $request) |
||
40 | { |
||
41 | if ($this->middlewares->isEmpty()) { |
||
42 | throw new MissingResponseException( 'The queue was exhausted, with no response returned'); |
||
43 | } |
||
44 | return $this->generateDelegate()->process($request); |
||
45 | } |
||
46 | |||
47 | protected function generateDelegate() |
||
48 | { |
||
49 | return new Delegate($this->middlewares->dequeue(), $this->generateDelegate()); |
||
0 ignored issues
–
show
|
|||
50 | } |
||
51 | |||
52 | protected static function decorateCallableMiddleware(callable $middleware) |
||
53 | { |
||
54 | return new CallableMiddleware($middleware); |
||
55 | } |
||
56 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.