Test Failed
Push — b2.0.0 ( 5c1038...2234e4 )
by Sebastian
07:58
created

SessionNotStartedTrait::checkSessionNotStarted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of the Linna Csrf Guard.
7
 *
8
 * @author Sebastian Rapetti <[email protected]>
9
 * @copyright (c) 2020, Sebastian Rapetti
10
 * @license http://opensource.org/licenses/MIT MIT License
11
 */
12
13
namespace Linna\CsrfGuard\Exception;
14
15
/**
16
 * Session not started trait.
17
 * 
18
 * <p>Provide a method to check conditions to throw SessionNotStartedException.</p>
19
 */
20
trait SessionNotStartedTrait
21
{
22
    /**
23
     * Check if session isn't started.
24
     *
25
     * @return void
26
     *
27
     * @throws SessionNotStartedException If sessions are disabled or not started.
28
     */
29
    protected function checkSessionNotStarted(): void
30
    {
31
        if (session_status() !== PHP_SESSION_ACTIVE) {
32
            throw new SessionNotStartedException('Session not started, enable it and start one before use this token provider.');
33
        }
34
    }
35
}
36