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

GuestMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 36
wmc 3
lcom 0
cbo 3
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 8 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