TypeCheckerFactory::customTypeChecker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oxidmod\TypedCollections;
6
7
class TypeCheckerFactory
8
{
9
    private static array $checkers = [];
10
11
    public static function arrayChecker(): \Closure
12
    {
13
        return self::$checkers['array'] = self::$checkers['array'] ?? \Closure::fromCallable(
14
            fn($value) => is_array($value)
15
        );
16
    }
17
18
    public static function booleanChecker(): \Closure
19
    {
20
        return self::$checkers['boolean'] = self::$checkers['boolean'] ?? \Closure::fromCallable(
21
            fn($value) => is_bool($value)
22
        );
23
    }
24
25
    public static function floatChecker(): \Closure
26
    {
27
        return self::$checkers['float'] = self::$checkers['float'] ?? \Closure::fromCallable(
28
            fn($value) => is_float($value)
29
        );
30
    }
31
32
    public static function integerChecker(): \Closure
33
    {
34
        return self::$checkers['integer'] = self::$checkers['integer'] ?? \Closure::fromCallable(
35
            fn($value) => is_int($value)
36
        );
37
    }
38
39
    public static function objectChecker(): \Closure
40
    {
41
        return self::$checkers['object'] = self::$checkers['object'] ?? \Closure::fromCallable(
42
            fn($value) => is_object($value)
43
        );
44
    }
45
46
    public static function stringChecker(): \Closure
47
    {
48
        return self::$checkers['string'] = self::$checkers['string'] ?? \Closure::fromCallable(
49
            fn($value) => is_string($value)
50
        );
51
    }
52
53
    public static function customTypeChecker(string $type): \Closure
54
    {
55
        return self::$checkers[$type] = self::$checkers[$type] ?? \Closure::fromCallable(
56
            fn($value) => $value instanceof $type
57
        );
58
    }
59
}
60