Completed
Branch master (69a8ae)
by Roman
02:48
created

InvalidNullOrStringException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
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 InvalidNullOrStringException extends ArgumentException
11
{
12
    /**
13
     * @param string                        $variableName
14
     * @param int|float|bool|resource|array $variableValue
15
     * @throws InvalidNotEmptyException
16
     * @throws InvalidNotNullAndNotStringException
17
     * @throws InvalidStringException
18
     */
19 3
    public function __construct($variableName, $variableValue)
20
    {
21 3
        if (!is_string($variableName)) {
22 1
            throw new InvalidStringException('variableName', $variableName);
23 2
        } elseif (is_null($variableValue) || is_string($variableValue)) {
24 1
            throw new InvalidNotNullAndNotStringException($variableName);
25
        }
26
27 2
        parent::__construct(
28 2
            sprintf(
29 2
                'Variable "$%s" must be: "null" or "string", actual type: "%s"',
30 2
                $variableName,
31 2
                gettype($variableValue)
32 2
            )
33 2
        );
34 2
    }
35
}
36