Completed
Push — master ( 9a3771...84f8db )
by Ryosuke
05:40
created

TypeUtils::isFatalThrowable()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 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 32
    public static function isCurl($value)
13 32
    {
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 29
    public static function isGeneratorContainer($value)
23 29
    {
24 29
        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 33
    public static function isGeneratorClosure($value)
33 33
    {
34 33
        return $value instanceof \Closure
35 33
            && (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