Guard::againstNullAndNonInt()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 12
1
<?php
2
namespace PSB\Core\Util;
3
4
5
use PSB\Core\Exception\InvalidArgumentException;
6
7
class Guard
8
{
9 98
    public static function againstNull($name, $value)
10
    {
11 98
        if ($value === null) {
12 12
            throw new InvalidArgumentException(ucfirst($name) . ' cannot be null.');
13
        }
14 92
    }
15
16 201
    public static function againstNullAndEmpty($name, $value)
17
    {
18 201
        if ($value === null || empty($value)) {
19 16
            throw new InvalidArgumentException(ucfirst($name) . ' cannot be null.');
20
        }
21 191
    }
22
23
    public static function againstNullAndNonInt($name, $value)
24
    {
25
        if ($value === null || !is_int($value)) {
26
            throw new InvalidArgumentException(ucfirst($name) . ' must be a non null integer.');
27
        }
28
    }
29
30 24
    public static function againstNonObject($name, $value)
31
    {
32 24
        if (!is_object($value)) {
33 4
            throw new InvalidArgumentException(ucfirst($name) . ' must be an object.');
34
        }
35 22
    }
36
}
37