| Conditions | 4 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 45 | public function __invoke(ServerRequestInterface $request, Response $response, $next) |
||
| 46 | { |
||
| 47 | $anonymousRoutes = $this->getOption('anonymous_routes', []); |
||
| 48 | if (is_null($request->getAttribute('route'))) { |
||
| 49 | return $response->withRedirect( |
||
| 50 | Router::pathFor($this->getOption('login_route')) |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | if (!in_array($request->getAttribute('route')->getName(), $anonymousRoutes)) { |
||
| 54 | if (!Security::hasLogin()) { |
||
| 55 | return $response->withRedirect( |
||
| 56 | Router::pathFor($this->getOption('login_route')) |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | return $next($request, $response); |
||
| 62 | } |
||
| 64 |