Skip to content

Commit f19e5b3

Browse files
committed
Adjust exception messages
1 parent 7e9fa17 commit f19e5b3

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Coerce.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function toInt(mixed $value, bool $allowBool = false): int
5555
return self::stringToInt($value);
5656
}
5757

58-
throw new TypeError('Only ' . ( $allowBool ? 'booleans, ' : '' ) . 'numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: ' . Debug::sanitizeData($value));
58+
throw new TypeError('Only ' . ( $allowBool ? 'booleans, ' : '' ) . 'numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: ' . Debug::sanitizeData($value));
5959
}
6060

6161
/**
@@ -150,7 +150,7 @@ public static function intToBool(int $value): bool
150150
return match($value) {
151151
0 => false,
152152
1 => true,
153-
default => throw new TypeError('Only 0 and 1 can be coerced from an int to a boolean, given value: ' . Debug::sanitizeData($value)),
153+
default => throw new TypeError('Only 0 and 1 can be coerced from an integer to a boolean, given value: ' . Debug::sanitizeData($value)),
154154
};
155155
}
156156

@@ -177,7 +177,7 @@ public static function floatToInt(float $value): int
177177
return \intval($value);
178178
}
179179

180-
throw new TypeError('Only numbers with no fractional part can be coerced from a float to an int, given value: ' . Debug::sanitizeData($value));
180+
throw new TypeError('Only numbers with no fractional part can be coerced from a float to an integer, given value: ' . Debug::sanitizeData($value));
181181
}
182182

183183
/**
@@ -190,7 +190,7 @@ public static function stringToInt(string $value): int
190190
return \intval($value);
191191
}
192192

193-
throw new TypeError('Only numbers with no fractional part can be coerced from a string to an int, given value: ' . Debug::sanitizeData($value));
193+
throw new TypeError('Only numbers with no fractional part can be coerced from a string to an integer, given value: ' . Debug::sanitizeData($value));
194194
}
195195

196196
/**

tests/CoerceTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public function testCoerceToInt(): void
2929
],
3030
[
3131
'input' => 'failed',
32-
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an int, given value: \'failed\''),
32+
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an integer, given value: \'failed\''),
3333
'coerceable' => false,
3434
],
3535
[
3636
'input' => '39hello',
37-
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an int, given value: \'39hello\''),
37+
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an integer, given value: \'39hello\''),
3838
'coerceable' => false,
3939
],
4040
[
@@ -44,12 +44,12 @@ public function testCoerceToInt(): void
4444
],
4545
[
4646
'input' => true,
47-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: true'),
47+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: true'),
4848
'coerceable' => false,
4949
],
5050
[
5151
'input' => false,
52-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: false'),
52+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: false'),
5353
'coerceable' => false,
5454
],
5555
[
@@ -70,12 +70,12 @@ public function testCoerceToInt(): void
7070
],
7171
[
7272
'input' => 1.5,
73-
'output' => new TypeError('Only numbers with no fractional part can be coerced from a float to an int, given value: 1.5'),
73+
'output' => new TypeError('Only numbers with no fractional part can be coerced from a float to an integer, given value: 1.5'),
7474
'coerceable' => false,
7575
],
7676
[
7777
'input' => '',
78-
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an int, given value: \'\''),
78+
'output' => new TypeError('Only numbers with no fractional part can be coerced from a string to an integer, given value: \'\''),
7979
'coerceable' => false,
8080
],
8181
[
@@ -85,22 +85,22 @@ public function __toString()
8585
return 'amazing';
8686
}
8787
},
88-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: object(class@anonymous' . '$end$'),
88+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: object(class@anonymous' . '$end$'),
8989
'coerceable' => false,
9090
],
9191
[
9292
'input' => [],
93-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: []'),
93+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: []'),
9494
'coerceable' => false,
9595
],
9696
[
9797
'input' => (object)[],
98-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: object(stdClass)'),
98+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: object(stdClass)'),
9999
'coerceable' => false,
100100
],
101101
[
102102
'input' => null,
103-
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an int, given value: NULL'),
103+
'output' => new TypeError('Only numeric strings and floats with no fractional part are alternative coerceable values for an integer, given value: NULL'),
104104
'coerceable' => false,
105105
],
106106
];

0 commit comments

Comments
 (0)