GuestMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
namespace App\Middleware;
4
5
use Cartalyst\Sentinel\Sentinel;
6
use Slim\Http\Request;
7
use Slim\Http\Response;
8
use Slim\Interfaces\RouterInterface;
9
10
class GuestMiddleware implements MiddlewareInterface
11
{
12
    /**
13
     * @var RouterInterface
14
     */
15
    protected $router;
16
17
    /**
18
     * @var Sentinel
19
     */
20
    protected $sentinel;
21
22
    public function __construct(RouterInterface $router, Sentinel $sentinel)
23
    {
24
        $this->router = $router;
25
        $this->sentinel = $sentinel;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __invoke(Request $request, Response $response, callable $next)
32
    {
33
        if ($this->sentinel->check()) {
34
            return $response->withRedirect($this->router->pathFor('home'));
35
        }
36
37
        return $next($request, $response);
38
    }
39
}
40