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

GuestMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

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