BadExpireTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkBadExpire() 0 8 3
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
 * Bad expire trait.
17
 *
18
 * <p>Provide a method to check conditions to throw BadExpireException.</p>
19
 */
20
trait BadExpireTrait
21
{
22
    /**
23
     * Check for a wrog expire time for a token.
24
     *
25
     * @param int $expire Expire time in seconds.
26
     *
27
     * @return void
28
     *
29
     * @throws BadExpireException If $expire is less than <code>ExceptionBoundary::EXPIRE_MIN</code> and greater than
30
     *                            <code>ExceptionBoundary::EXPIRE_MAX</code>.
31
     */
32
    protected function checkBadExpire(int $expire): void
33
    {
34
        if ($expire < ExceptionBoundary::EXPIRE_MIN || $expire > ExceptionBoundary::EXPIRE_MAX) {
35
            throw new BadExpireException(
36
                \sprintf(
37
                    "Expire time must be between %d and %d)",
38
                    ExceptionBoundary::EXPIRE_MIN,
39
                    ExceptionBoundary::EXPIRE_MAX
40
                )
41
            );
42
        }
43
    }
44
}
45