Passed
Push — b2.0.0 ( 59ba4e...bb1327 )
by Sebastian
02:46
created

BadExpireTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 3
c 1
b 0
f 0
dl 0
loc 16
ccs 3
cts 3
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkBadExpire() 0 5 3
1
<?php
2
3
/**
4
 * Linna Cross-site Request Forgery Guard
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2020, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\CsrfGuard\Exception;
13
14
/**
15
 * Bad expire trait.
16
 * Provide a method to check conditions to throw BadExpireException.
17
 */
18
trait BadExpireTrait
19
{
20
    /**
21
     * Check bad expire.
22
     *
23
     * @param int $expire Expire time in seconds
24
     *
25
     * @return void
26
     *
27
     * @throws BadExpireException If $expire is less than 0 and greater than 86400
28
     */
29 15
    protected function checkBadExpire(int $expire): void
30
    {
31
        // expire maximum time is one day
32 15
        if ($expire < 0 || $expire > 86400) {
33 6
            throw new BadExpireException('Expire time must be between 0 and 86400');
34
        }
35 9
    }
36
}
37