Completed
Push — b0.25.0 ( 47a5e1...be320f )
by Sebastian
03:27
created

ProtectedController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 18
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A protect() 0 5 2
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Authentication;
13
14
/**
15
 * Help protect a controller with login.
16
 */
17
trait ProtectedController
18
{
19
    /**
20
     * @var bool Contain login status
21
     */
22
    private $authentication = false;
23
24
    /**
25
     * Allow access to controller only if logged.
26
     *
27
     * @param Authentication $authentication
28
     * @param string         $redirect
29
     */
30 1
    private function protect(Authentication $authentication, string $redirect): void
31
    {
32 1
        if (($this->authentication = $authentication->isLogged()) === false) {
33
            header('Location: '.$redirect);
34
            exit;
35
        }
36 1
    }
37
}
38