Guard   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 30
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A againstNull() 0 6 2
A againstNullAndEmpty() 0 6 3
A againstNullAndNonInt() 0 6 3
A againstNonObject() 0 6 2
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