BadStorageSizeTrait   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 checkBadStorageSize() 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 storage size trait.
17
 *
18
 * <p>Provide a method to check conditions to throw BadStorageSizeException.</p>
19
 */
20
trait BadStorageSizeTrait
21
{
22
    /**
23
     * Check for a wrong storage size.
24
     *
25
     * @param int $size Size expressed in number of tokens will be stored.
26
     *
27
     * @return void
28
     *
29
     * @throws BadStorageSizeException If $size is less than <code>ExceptionBoundary::STORAGE_SIZE_MIN</code> and
30
     *                                 greater than <code>ExceptionBoundary::STORAGE_SIZE_MAX</code>.
31
     */
32
    protected function checkBadStorageSize(int $size): void
33
    {
34
        if ($size < ExceptionBoundary::STORAGE_SIZE_MIN || $size > ExceptionBoundary::STORAGE_SIZE_MAX) {
35
            throw new BadStorageSizeException(
36
                \sprintf(
37
                    "Storage size must be between %d and %d)",
38
                    ExceptionBoundary::STORAGE_SIZE_MIN,
39
                    ExceptionBoundary::STORAGE_SIZE_MAX
40
                )
41
            );
42
        }
43
    }
44
}
45