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

ProtectedController::protect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
crap 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