Completed
Push — master ( e82fd4...ad54cf )
by Alexis
01:42
created

GuestMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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