Completed
Push — master ( 5139b6...b16139 )
by Sebastian
02:13
created

ProtectedController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A protect() 0 6 2
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, 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
    protected $authentication = false;
23
24
    /**
25
     * Allow access to controller only if logged.
26
     *
27
     * @param Authenticate $authenticate
28
     * @param string       $redirect
29
     */
30 2
    protected function protect(Authenticate $authenticate, string $redirect)
31
    {
32 2
        if (($this->authentication = $authenticate->isLogged()) === false) {
33 1
            header('Location: '.$redirect);
34
        }
35 2
    }
36
}
37