Assertions::assertBoolish()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 9.6111
cc 5
nc 3
nop 1
1
<?php
2
3
namespace RemotelyLiving\PHPEnv;
4
5
use RemotelyLiving\PHPEnv\Exceptions;
6
7
final class Assertions
8
{
9
    public static function assertNotEmptyString($value): void
10
    {
11
        if (!is_string($value) || $value === '') {
12
            throw Exceptions\InvalidArgument::isEmpty();
13
        }
14
    }
15
16
    public static function assertNumeric($value): void
17
    {
18
        if (!is_numeric($value)) {
19
            throw Exceptions\InvalidArgument::invalidNumeric($value);
20
        }
21
    }
22
23
    public static function assertObject($value): void
24
    {
25
        if (!is_object($value)) {
26
            throw Exceptions\InvalidArgument::invalidObject($value);
27
        }
28
    }
29
30
    public static function assertBoolish($value): void
31
    {
32
        $normalizedValue = \mb_strtolower((string) $value);
33
        if ($normalizedValue === 'false' || $normalizedValue === 'true') {
34
            return;
35
        }
36
37
        if ($value === '1' || $value === '0') {
38
            return;
39
        }
40
41
        throw Exceptions\InvalidArgument::invalidBooleanValue($value);
42
    }
43
}
44