GuestMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 30
rs 10
c 0
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
    public function __construct(RouterInterface $router, Sentinel $sentinel)
23
    {
24
        $this->router = $router;
25
        $this->sentinel = $sentinel;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __invoke(Request $request, Response $response, callable $next)
32
    {
33
        if ($this->sentinel->check()) {
34
            return $response->withRedirect($this->router->pathFor('home'));
35
        }
36
37
        return $next($request, $response);
38
    }
39
}
40