Completed
Push — master ( 379576...3184a2 )
by Roman
02:29
created

InvalidIntOrFloatOrStringException::__construct()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 13
cts 13
cp 1
rs 8.8571
cc 5
eloc 10
nc 3
nop 2
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 InvalidIntOrFloatOrStringException extends ArgumentException
11
{
12
    /**
13
     * @param string                          $variableName
14
     * @param array|bool|null|resource|string $variableValue
15
     * @throws InvalidNotIntAndNotFloatAndNotStringException
16
     * @throws InvalidStringException
17
     */
18 5
    public function __construct($variableName, $variableValue)
19
    {
20 5
        if (!is_string($variableName)) {
21 1
            throw new InvalidStringException('variableName', $variableName);
22 4
        } elseif (is_int($variableValue) || is_float($variableValue) || is_string($variableValue)) {
23 1
            throw new InvalidNotIntAndNotFloatAndNotStringException('variableValue');
24
        }
25
26 4
        parent::__construct(
27 4
            sprintf(
28 4
                'Variable "$%s" must be "int" or "float" or "string", actual type: "%s"',
29 4
                $variableName,
30 4
                gettype($variableValue)
31 4
            )
32 4
        );
33
    }
34
}