Completed
Branch master (928280)
by Alexis
02:27
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
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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
    /**
23
     * Constructor.
24
     *
25
     * @param RouterInterface $router
26
     * @param Sentinel        $sentinel
27
     */
28
    public function __construct(RouterInterface $router, Sentinel $sentinel)
29
    {
30
        $this->router = $router;
31
        $this->sentinel = $sentinel;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function __invoke(Request $request, Response $response, callable $next)
38
    {
39
        if ($this->sentinel->check()) {
40
            return $response->withRedirect($this->router->pathFor('home'));
41
        }
42
43
        return $next($request, $response);
44
    }
45
}
46