Passed
Push — php7.0 ( 973540...f56c39 )
by SignpostMarv
06:05
created

NestedTypeParanoia::ThrowIfNotNestedType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 5
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 1
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
    * @return int|null
17
    */
18 30
    public static function MaybeFoundInArray($needle, array $haystack)
19
    {
20
        /**
21
        * @var int|false
22
        */
23 30
        $out = array_search($needle, $haystack, true);
24
25 30
        return is_int($out) ? $out : null;
26
    }
27
28
    /**
29
    * @param mixed $object
30
    */
31 78
    public static function ThrowIfNotNestedType(
32
        $object,
33
        int $argument,
34
        string $class,
35
        string $function,
36
        string ...$types
37
    ) {
38 78
        static::ThrowIfNotType(
39 78
            $object,
40 78
            $argument,
41 78
            $class,
42 78
            $function,
43 78
            DaftNestedObject::class,
44 78
            ...$types
45
        );
46 77
    }
47
48
    /**
49
    * @param mixed $object
50
    */
51 58
    public static function ThrowIfNotWriteableNestedType(
52
        $object,
53
        int $argument,
54
        string $class,
55
        string $function,
56
        string ...$types
57
    ) {
58 58
        static::ThrowIfNotType(
59 58
            $object,
60 58
            $argument,
61 58
            $class,
62 58
            $function,
63 58
            DaftNestedWriteableObject::class,
64 58
            ...$types
65
        );
66 56
    }
67
68
    /**
69
    * @param mixed $maybe
70
    */
71 60
    public static function ForceInt($maybe) : int
72
    {
73 60
        return is_int($maybe) ? $maybe : (int) $maybe;
74
    }
75
}
76