Completed
Push — master ( 9b44fb...735dd1 )
by Paweł
12s
created

println()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace {
6
    require_once __DIR__.'/Conversion/implicit_conversion.php';
7
    require_once __DIR__.'/Type/restrictions.php';
8
}
9
10
namespace Scalp {
11
    use function Scalp\Conversion\AnyToString;
12
13
    function println($x): void
14
    {
15
        echo AnyToString($x)."\n";
16
    }
17
18
    function None(): None
19
    {
20
        return new None();
21
    }
22
23
    function Some($x): Some
24
    {
25
        return new Some($x);
26
    }
27
28
    function Option($x): Option
29
    {
30
        return ($x === null) ? None() : Some($x);
31
    }
32
}
33
34
namespace Scalp\Conversion {
35
    const AnyToString = __NAMESPACE__.'\AnyToString';
36
37
    function AnyToString($any): string
38
    {
39
        static $anyToString = null;
40
41
        if ($anyToString === null) {
42
            $anyToString = new AnyToString();
43
        }
44
45
        return $anyToString($any);
46
    }
47
}
48
49
namespace Scalp\Utils {
50
    function Delayed(callable $functionOrCodeBlock, ...$args): Delayed
51
    {
52
        return new Delayed($functionOrCodeBlock, ...$args);
53
    }
54
55
    function Failure(\Throwable $error): Failure
56
    {
57
        return new Failure($error);
58
    }
59
60
    function Success($value): Success
61
    {
62
        return new Success($value);
63
    }
64
65
    function TryCatch(callable $delayed): TryCatch
66
    {
67
        try {
68
            return new Success($delayed());
69
        } catch (\Throwable $e) {
70
            return new Failure($e);
71
        }
72
    }
73
74
    function type($x): string
75
    {
76
        return is_object($x)
77
                ? get_class($x)
78
                : gettype($x)
79
            ;
80
    }
81
82
    function checkType(string $actual, string $expected): bool
83
    {
84
        return $actual === $expected
85
                || is_subclass_of($actual, $expected, true)
86
            ;
87
    }
88
}
89