GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 910b0e...f3e0da )
by SignpostMarv
04:20
created

TypeCertainty::EnsureArgumentIsObjectOrString()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 3
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftObject;
8
9
use InvalidArgumentException;
10
11
class TypeCertainty
12
{
13
    const INDEX_FIRST_ARG = 1;
14
15
    const BOOL_VAR_EXPORT_RETURN = true;
16
17
    /**
18
    * @param mixed $maybe
19
    */
20 364
    public static function EnsureArgumentIsArray($maybe, int $argument = null, string $method = __METHOD__) : array
21
    {
22 364
        if ( ! is_array($maybe)) {
23 2
            throw new InvalidArgumentException(
24
                'Argument ' .
25 2
                (is_int($argument) ? $argument : self::INDEX_FIRST_ARG) .
26 2
                ' passed to ' .
27 2
                $method .
28 2
                ' must be an array, ' .
29 2
                (is_object($maybe) ? get_class($maybe) : gettype($maybe)) .
30 2
                ' given!'
31
            );
32
        }
33
34 362
        return $maybe;
35
    }
36
37
    /**
38
    * @param mixed $maybe
39
    */
40 24
    public static function ForceArgumentAsArray($maybe) : array
41
    {
42 24
        return is_array($maybe) ? $maybe : [$maybe];
43
    }
44
45
    /**
46
    * @param mixed $maybe
47
    */
48 8
    public static function VarExportNonScalars($maybe) : string
49
    {
50 8
        if (is_string($maybe)) {
51 4
            return $maybe;
52
        }
53
54
        return
55 8
            is_scalar($maybe)
56 8
                ? (string) $maybe
57 8
                : var_export($maybe, self::BOOL_VAR_EXPORT_RETURN);
58
    }
59
60
    /**
61
    * @param mixed $maybe
62
    */
63 18
    public static function EnsureArgumentIsString($maybe) : string
64
    {
65 18
        if ( ! is_string($maybe)) {
66 4
            throw new InvalidArgumentException(
67
                'Argument 1 passed to ' .
68
                __METHOD__ .
69
                ' must be a string, ' .
70 4
                (is_object($maybe) ? get_class($maybe) : gettype($maybe)) .
71 4
                ' given!'
72
            );
73
        }
74
75 14
        return $maybe;
76
    }
77
78
    /**
79
    * @param mixed $maybe
80
    *
81
    * @return object|string
82
    */
83 24
    public static function EnsureArgumentIsObjectOrString($maybe, int $argument, string $method)
84
    {
85 24
        if ( ! is_object($maybe) && ! is_string($maybe)) {
86 2
            throw new InvalidArgumentException(
87
                'Argument ' .
88 2
                $argument .
89 2
                ' passed to ' .
90 2
                $method .
91 2
                ' must be an object or a string!'
92
            );
93
        }
94
95 22
        return $maybe;
96
    }
97
}
98