TypeCheckerFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 50
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A arrayChecker() 0 4 1
A objectChecker() 0 4 1
A booleanChecker() 0 4 1
A floatChecker() 0 4 1
A customTypeChecker() 0 4 1
A integerChecker() 0 4 1
A stringChecker() 0 4 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