Test Failed
Push — master ( ad6bc5...67eecb )
by SignpostMarv
06:24
created

NestedTypeParanoia::ThrowIfNotNestedType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 5
dl 0
loc 14
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
* Base daft objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject;
10
11
class NestedTypeParanoia extends TypeParanoia
12
{
13
    /**
14
    * @param mixed $needle
15
    */
16 60
    public static function MaybeFoundInArray($needle, array $haystack) : ? int
17
    {
18 60
        $out = array_search($needle, $haystack, true);
19
20 60
        return is_int($out) ? $out : null;
21
    }
22
23
    /**
24
    * @param mixed $object
25
    */
26
    public static function ThrowIfNotNestedType(
27
        $object,
28
        int $argument,
29
        string $class,
30
        string $function,
31
        string ...$types
32
    ) : void {
33
        static::ThrowIfNotType(
34
            $object,
35
            $argument,
36
            $class,
37
            $function,
38
            DaftNestedObject::class,
39
            ...$types
40
        );
41
    }
42
43
    /**
44
    * @param mixed $object
45
    */
46
    public static function ThrowIfNotWriteableNestedType(
47
        $object,
48
        int $argument,
49
        string $class,
50
        string $function,
51
        string ...$types
52
    ) : void {
53
        static::ThrowIfNotType(
54
            $object,
55
            $argument,
56
            $class,
57
            $function,
58
            DaftNestedWriteableObject::class,
59
            ...$types
60
        );
61
    }
62
63
    public static function ForceInt($maybe) : int
64
    {
65
        return is_int($maybe) ? $maybe : (int) $maybe;
66
    }
67
}
68