SessionNotStartedTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 13
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkSessionNotStarted() 0 4 2
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