A wrapper around webmozart/assert that implements assertions with bcmath functions.
Required PHP 7.3.0 or above.
composer require php-addons/bc-assertuse PhpAddons\BcAssert\Assert;
class Money
{
public function __construct(string $value)
{
Assert::bcGreaterThan($value, '0', 'The money must be a positive number. Got: %s', 2);
}
}If the last parameter ($scale) is not set, the default scale from the system will be used.
The [Assert] class provides the following assertions:
| Method | Description |
|---|---|
bcSame($value, $value2, $message = '', $scale = null) |
Check that a value is identical to another (bccomp($value, $value2, $scale) === 0) |
bcNotSame($value, $value2, $message = '', $scale = null) |
Check that a value is not identical to another (bccomp($value, $value2, $scale) !== 0) |
bcGreaterThan($value, $value2, $message = '', $scale = null) |
Check that a value is greater than another |
bcGreaterThanEq($value, $value2, $message = '', $scale = null) |
Check that a value is greater than or equal to another |
bcLessThan($value, $value2, $message = '', $scale = null) |
Check that a value is less than another |
bcLessThanEq($value, $value2, $message = '', $scale = null) |
Check that a value is less than or equal to another |
bcRange($value, $min, $max, $message = '', $scale = null) |
Check that a value is within a range |