Completed
Branch master (928280)
by Alexis
02:27
created

GuestMiddleware::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
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
    /**
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