InvalidArrayCountException::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
ccs 18
cts 18
cp 1
rs 8.7624
cc 5
eloc 15
nc 5
nop 3
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 InvalidArrayCountException extends ArgumentException
11
{
12
    /**
13
     * @param string $variableName
14
     * @param array  $variableValue
15
     * @param int    $count
16
     * @throws InvalidArrayException
17
     * @throws InvalidIntException
18
     * @throws InvalidNotEmptyException
19
     * @throws InvalidStringException
20
     * @throws NumberNotGreaterException
21
     */
22 5
    public function __construct($variableName, $variableValue, $count)
23
    {
24 5
        if (!is_string($variableName)) {
25 1
            throw new InvalidStringException('variableName', $variableName);
26 4
        } elseif (!is_array($variableValue)) {
27 1
            throw new InvalidArrayException('variableValue', $variableValue);
28 3
        } elseif (!is_int($count)) {
29 1
            throw new InvalidIntException('count', $count);
30 3
        } elseif ($count < 0) {
31 1
            throw new NumberNotGreaterException('count', $count, 0);
32
        }
33
34 2
        parent::__construct(
35 2
            sprintf(
36 2
                'Variable "$%s" must contain: "%d" elements, actual count: "%d"',
37 2
                $variableName,
38 2
                $count,
39 2
                count($variableValue)
40 2
            )
41 2
        );
42 2
    }
43
}
44