-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
152 lines (123 loc) · 3.45 KB
/
functions.php
File metadata and controls
152 lines (123 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
declare(strict_types=1);
namespace Plook\TypeGuard;
use DateTimeImmutable;
use DateTimeZone;
use function function_exists;
// phpcs:disable Squiz.Functions.GlobalFunction.Found
if (!function_exists('\Plook\TypeGuard\asBool')) { // @codeCoverageIgnore
/** @return ($value is null ? null : bool) */
function asBool(mixed $value): bool|null
{
return TypeGuard::instance()->asBool($value);
}
}
if (!function_exists('\Plook\TypeGuard\asFloat')) { // @codeCoverageIgnore
/** @return ($value is null ? null : float) */
function asFloat(mixed $value): float|null
{
return TypeGuard::instance()->asFloat($value);
}
}
if (!function_exists('\Plook\TypeGuard\asInt')) { // @codeCoverageIgnore
/** @return ($value is null ? null : int) */
function asInt(mixed $value): int|null
{
return TypeGuard::instance()->asInt($value);
}
}
if (!function_exists('\Plook\TypeGuard\asString')) { // @codeCoverageIgnore
/** @return ($value is null ? null : string) */
function asString(mixed $value): string|null
{
return TypeGuard::instance()->asString($value);
}
}
if (!function_exists('\Plook\TypeGuard\asDateTimeImmutable')) { // @codeCoverageIgnore
/** @return ($value is null ? null : DateTimeImmutable) */
function asDateTimeImmutable(
mixed $value,
DateTimeZone|string|null $timeZone = null,
): DateTimeImmutable|null {
return TypeGuard::instance()->asDateTimeImmutable($value, $timeZone);
}
}
if (!function_exists('\Plook\TypeGuard\asDateTimeZone')) { // @codeCoverageIgnore
/** @return ($value is null ? null : DateTimeZone) */
function asDateTimeZone(mixed $value): DateTimeZone|null
{
return TypeGuard::instance()->asDateTimeZone($value);
}
}
if (!function_exists('\Plook\TypeGuard\asDateTimeString')) { // @codeCoverageIgnore
/** @return ($value is null ? null : string) */
function asDateTimeString(mixed $value): string|null
{
return TypeGuard::instance()->asDateTimeString($value);
}
}
if (!function_exists('\Plook\TypeGuard\blankAsNull')) { // @codeCoverageIgnore
/**
* @param T $value
*
* @return T|null
*
* @template T
*/
function blankAsNull(mixed $value): mixed
{
return TypeGuard::instance()->blankAsNull($value);
}
}
if (!function_exists('\Plook\TypeGuard\falseAsNull')) { // @codeCoverageIgnore
/**
* @param T $value
*
* @return T|null
*
* @template T
*/
function falseAsNull(mixed $value): mixed
{
return TypeGuard::instance()->falseAsNull($value);
}
}
if (!function_exists('\Plook\TypeGuard\zeroAsNull')) { // @codeCoverageIgnore
/**
* @param T $value
*
* @return T|null
*
* @template T
*/
function zeroAsNull(mixed $value): mixed
{
return TypeGuard::instance()->zeroAsNull($value);
}
}
if (!function_exists('\Plook\TypeGuard\falsyAsNull')) { // @codeCoverageIgnore
/**
* @param T $value
*
* @return T|null
*
* @template T
*/
function falsyAsNull(mixed $value): mixed
{
return TypeGuard::instance()->falsyAsNull($value);
}
}
if (!function_exists('\Plook\TypeGuard\notNull')) { // @codeCoverageIgnore
/**
* @param ?T $value
*
* @return T
*
* @template T
*/
function notNull(mixed $value): mixed
{
return TypeGuard::instance()->notNull($value);
}
}