TypeUtils::isFatalThrowable()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace mpyw\Co\Internal;
4
5
class TypeUtils
6
{
7
    /**
8
     * Check if value is a valid cURL handle.
9
     * @param  mixed $value
10
     * @return bool
11
     */
12 33
    public static function isCurl($value)
13 33
    {
14 2
        return is_resource($value) && get_resource_type($value) === 'curl';
15
    }
16
17
    /**
18
     * Check if value is a valid Generator.
19
     * @param  mixed $value
20
     * @return bool
21
     */
22 30
    public static function isGeneratorContainer($value)
23 30
    {
24 30
        return $value instanceof GeneratorContainer;
25
    }
26
27
    /**
28
     * Check if value is a valid Generator closure.
29
     * @param  mixed $value
30
     * @return bool
31
     */
32 34
    public static function isGeneratorClosure($value)
33 34
    {
34 34
        return $value instanceof \Closure
35 34
            && (new \ReflectionFunction($value))->isGenerator();
36
    }
37
38
    /**
39
     * Check if value is Throwable, excluding RuntimeException.
40
     * @param  mixed $value
41
     * @return bool
42
     */
43 9
    public static function isFatalThrowable($value)
44 9
    {
45 9
        return !$value instanceof \RuntimeException
46 9
            && ($value instanceof \Throwable || $value instanceof \Exception);
47
    }
48
}
49