Passed
Push — master ( bed608...307714 )
by SignpostMarv
06:30
created

NestedTypeParanoia::MaybeFoundInArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
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
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 $maybe
25
    */
26 96
    public static function ForceInt($maybe) : int
27
    {
28 96
        return is_int($maybe) ? $maybe : (int) $maybe;
29
    }
30
31 88
    public static function NotYetAppendedToTree(DaftNestedObject $object) : bool
32
    {
33 88
        $left = $object->GetIntNestedLeft();
34 88
        $right = $object->GetIntNestedRight();
35 88
        $level = $object->GetIntNestedLevel();
36
37 88
        return 0 === $left && 0 === $right && 0 === $level;
38
    }
39
}
40