Skip to content

Commit 74e2989

Browse files
[PHP8] add type hints
1 parent ee5c293 commit 74e2989

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

Php80.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
*/
2020
final class Php80
2121
{
22-
public static function fdiv($dividend, $divisor)
22+
public static function fdiv(float $dividend, float $divisor): float
2323
{
24-
$dividend = self::floatArg($dividend, __FUNCTION__, 1);
25-
$divisor = self::floatArg($divisor, __FUNCTION__, 2);
26-
27-
return (float) @($dividend / $divisor);
24+
return @($dividend / $divisor);
2825
}
2926

30-
public static function preg_last_error_msg()
27+
public static function preg_last_error_msg(): string
3128
{
3229
switch (preg_last_error()) {
3330
case PREG_INTERNAL_ERROR:
@@ -48,17 +45,4 @@ public static function preg_last_error_msg()
4845
return 'Unknown error';
4946
}
5047
}
51-
52-
private static function floatArg($value, $caller, $pos)
53-
{
54-
if (\is_float($value)) {
55-
return $value;
56-
}
57-
58-
if (!\is_numeric($value)) {
59-
throw new \TypeError(sprintf('%s() expects parameter %d to be float, %s given', $caller, $pos, \gettype($value)));
60-
}
61-
62-
return (float) $value;
63-
}
6448
}

bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
use Symfony\Polyfill\Php80 as p;
1313

14-
if (PHP_VERSION_ID < 80000 && PHP_VERSION_ID >= 70000) {
14+
if (PHP_VERSION_ID < 80000) {
1515
if (!function_exists('fdiv')) {
16-
function fdiv($dividend, $divisor) { return p\Php80::fdiv($dividend, $divisor); }
16+
function fdiv(float $dividend, float $divisor): float { return p\Php80::fdiv($dividend, $divisor); }
1717
}
1818

1919
if (!function_exists('preg_last_error_msg')) {

0 commit comments

Comments
 (0)