LengthNotBetweenException::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
ccs 19
cts 19
cp 1
rs 8.6737
cc 5
eloc 16
nc 5
nop 4
crap 5
1
<?php
2
/**
3
 * @link      https://github.com/ko-ko-ko/php-assert
4
 * @copyright Copyright (c) 2015 Roman Levishchenko <[email protected]>
5
 * @license   https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE
6
 */
7
8
namespace KoKoKo\assert\exceptions;
9
10
class LengthNotBetweenException extends ArgumentException
11
{
12
    /**
13
     * @param string $variableName
14
     * @param string $variableValue
15
     * @param int    $from
16
     * @param int    $to
17
     * @throws InvalidIntException
18
     * @throws InvalidStringException
19
     */
20 6
    public function __construct($variableName, $variableValue, $from, $to)
21
    {
22 6
        if (!is_string($variableName)) {
23 1
            throw new InvalidStringException('variableName', $variableName);
24 5
        } elseif (!is_string($variableValue)) {
25 1
            throw new InvalidStringException('variableValue', $variableValue);
26 5
        } elseif (!is_int($from)) {
27 1
            throw new InvalidIntException('from', $from);
28 5
        } elseif (!is_int($to)) {
29 1
            throw new InvalidIntException('to', $to);
30
        }
31
32 5
        parent::__construct(
33 5
            sprintf(
34 5
                'Variable "$%s" must have length between "%d" and "%d", actual length: "%d"',
35 5
                $variableName,
36 5
                $from,
37 5
                $to,
38 5
                mb_strlen($variableValue)
39 5
            )
40 5
        );
41
    }
42
}