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

BadTokenLenghtTrait::checkBadTokenLenght()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 3
nc 2
nop 1
crap 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 token lenght trait.
16
 * Provide a method to check conditions to throw BadTokenLenghtException.
17
 */
18
trait BadTokenLenghtTrait
19
{
20
    /**
21
     * Check bad token lenght.
22
     *
23
     * @param int $tokenLenght Token lenght in bytes
24
     *
25
     * @return void
26
     *
27
     * @throws BadTokenLenghtException If $tokenLenght is less than 16 and greater than 128
28
     */
29 3
    protected function checkBadTokenLenght(int $tokenLenght): void
30
    {
31 3
        if ($tokenLenght < 16 || $tokenLenght > 128) {
32 2
            throw new BadTokenLenghtException('Token lenght must be between 16 and 128');
33
        }
34 1
    }
35
}
36