| Total Complexity | 9 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 88.89% |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | final class MiddlewareHandler implements Handler |
||
| 23 | { |
||
| 24 | private $middleware; |
||
| 25 | private $handler; |
||
| 26 | private $connection; |
||
| 27 | private $packer; |
||
| 28 | |||
| 29 | 8 | public function __construct(Middleware $middleware, Handler $handler) |
|
| 30 | { |
||
| 31 | 8 | $this->middleware = $middleware; |
|
| 32 | 8 | $this->handler = $handler; |
|
| 33 | 8 | } |
|
| 34 | |||
| 35 | 232 | public static function create(Handler $handler, array $middlewares) : Handler |
|
| 36 | { |
||
| 37 | 232 | if (!$middlewares) { |
|
|
|
|||
| 38 | 232 | return $handler; |
|
| 39 | } |
||
| 40 | |||
| 41 | 8 | $middleware = \end($middlewares); |
|
| 42 | |||
| 43 | 8 | while ($middleware) { |
|
| 44 | 8 | $handler = new self($middleware, $handler); |
|
| 45 | 8 | $middleware = \prev($middlewares); |
|
| 46 | } |
||
| 47 | |||
| 48 | 8 | return $handler; |
|
| 49 | } |
||
| 50 | |||
| 51 | 2 | public function getConnection() : Connection |
|
| 52 | { |
||
| 53 | 2 | return $this->connection ?: $this->connection = $this->handler->getConnection(); |
|
| 54 | } |
||
| 55 | |||
| 56 | public function getPacker() : Packer |
||
| 59 | } |
||
| 60 | |||
| 61 | 8 | public function handle(Request $request) : Response |
|
| 64 | } |
||
| 65 | } |
||
| 66 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.