You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,30 @@ Returns true if `$value` is one of the following:
109
109
110
110
For any other values it returns false.
111
111
112
+
### Coerceable::stringToBool
113
+
114
+
Specifically tests a string if it can be coerced to a boolean. `$value` must be '0' or '1'.
115
+
116
+
### Coerceable::intToBool
117
+
118
+
Specifically tests an integer if it can be coerced to a boolean. `$value` must be 0 or 1.
119
+
120
+
### Coerceable::floatToBool
121
+
122
+
Specifically tests a float if it can be coerced to a boolean. `$value` must be 0 or 1.
123
+
124
+
### Coerceable::floatToInt
125
+
126
+
Specifically tests a float if it can be coerced to an integer. `$value` must not have a fractional part.
127
+
128
+
### Coerceable::stringToInt
129
+
130
+
Specifically tests a string if it can be coerced to an integer. `$value` must be a numeric string and not have a fractional part.
131
+
132
+
### Coerceable::stringToFloat
133
+
134
+
Specifically tests a string if it can be coerced to a float. `$value` must be a numeric string.
135
+
112
136
Coerce a value
113
137
--------------
114
138
@@ -130,6 +154,42 @@ Returns a float if the given value is coerceable, see [Coerceable::toFloat for v
130
154
131
155
Returns a string if the given value is coerceable, see [Coerceable::toString for valid values](#coerceabletoint), or a TypeError if the value is not coerceable.
132
156
157
+
### Coerce::stringToBool
158
+
159
+
Returns a boolean if the given string is coerceable, see [Coerceable::stringToBool for valid values](#coerceablestringtobool), or a TypeError if the value is not coerceable.
160
+
161
+
### Coerce::intToBool
162
+
163
+
Returns a boolean if the given int is coerceable, see [Coerceable::intToBool for valid values](#coerceableinttobool), or a TypeError if the value is not coerceable.
164
+
165
+
### Coerce::floatToBool
166
+
167
+
Returns a boolean if the given float is coerceable, see [Coerceable::floatToBool for valid values](#coerceablefloattobool), or a TypeError if the value is not coerceable.
168
+
169
+
### Coerce::floatToInt
170
+
171
+
Returns an integer if the given float is coerceable, see [Coerceable::floatToInt for valid values](#coerceablefloattoint), or a TypeError if the value is not coerceable.
172
+
173
+
### Coerce::stringToInt
174
+
175
+
Returns an integer if the given string is coerceable, see [Coerceable::stringToInt for valid values](#coerceablestringtoint), or a TypeError if the value is not coerceable.
176
+
177
+
### Coerce::stringToFloat
178
+
179
+
Returns a float if the given string is coerceable, see [Coerceable::stringToFloat for valid values](#coerceablestringtofloat), or a TypeError if the value is not coerceable.
180
+
181
+
### Coerce::boolToString
182
+
183
+
Coerces a boolean to a string, returning either '0' or '1'.
184
+
185
+
### Coerce::intToString
186
+
187
+
Coerces an integer to a string, returning a numeric string.
188
+
189
+
### Coerce::floatToString
190
+
191
+
Coerces a float to a string, returning a numeric string.
thrownewTypeError('Only 0 and 1' . ( $allowEmptyString ? ' and \'\'' : '' ) . ' are alternative coerceable values for a boolean, given value: ' . Debug::sanitizeData($value));
@@ -60,18 +43,16 @@ public static function toInt(mixed $value, bool $allowBool = false): int
thrownewTypeError('Only ' . ( $allowBool ? 'booleans, ' : '' ) . 'numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: ' . Debug::sanitizeData($value));
@@ -83,25 +64,16 @@ public static function toInt(mixed $value, bool $allowBool = false): int
thrownewTypeError('Only ' . ( $allowBool ? 'booleans and ' : '' ) . 'numeric strings are alternative coerceable values for a float, given value: ' . Debug::sanitizeData($value));
@@ -113,33 +85,124 @@ public static function toFloat(mixed $value, bool $allowBool = false): float
if (Coerceable::stringToBool($value, allowEmptyString: $allowEmptyString)) {
114
+
return$value === '1';
115
+
}
116
+
117
+
thrownewTypeError('Only 0 and 1' . ( $allowEmptyString ? ' and \'\'' : '' ) . ' are alternative coerceable values for a boolean, given value: ' . Debug::sanitizeData($value));
0 commit comments