-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PHP 8.4] Add bcdivmod
#503
base: 1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,7 @@ function mb_ltrim(string $string, ?string $characters = null, ?string $encoding | |
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Php84::mb_rtrim($string, $characters, $encoding); } | ||
} | ||
} | ||
|
||
if (function_exists('bcdiv')) { | ||
function bcdivmod(string $num1, string $num2, ?int $scale = null): array {return p\Php84::bcdivmod($num1, $num2, $scale); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. such polyfill function should be defined only when the bcmath extension is loaded (similar to how we deal with mbstring new functions just above) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I missed that this was checking and for the detection of bcmath, please use |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,16 @@ public function testMbTrimCharactersEncoding() | |
mb_internal_encoding($old); | ||
} | ||
|
||
/** | ||
* @covers \Symfony\Polyfill\Php84\Php84::bcdivmod | ||
* | ||
* @dataProvider bcDivModProvider | ||
*/ | ||
public function testBcDivMod(string $num1, string $num2, ?int $scale = null, array $expected): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brilliant, thank you. |
||
{ | ||
$this->assertSame($expected, bcdivmod($num1, $num2, $scale)); | ||
} | ||
|
||
public static function mbTrimProvider(): iterable | ||
{ | ||
yield ['ABC', 'ABC']; | ||
|
@@ -319,4 +329,9 @@ public static function mbRTrimProvider(): iterable | |
|
||
yield ["foo\n", "foo\n", 'o']; | ||
} | ||
|
||
public static function bcDivModProvider(): iterable | ||
{ | ||
yield ['10', '10', null, ['1', '0']]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple more tests would be nice. You're only testing the simplest path. Also, beware that by setting the scale to |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two errors are not available on PHP 7. I suggest to emit a
E_USER_WARNING
and returnnull
instead if we're on PHP < 8.