diff --git a/.gitattributes b/.gitattributes index e6608e2..2d22c2b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,6 +16,7 @@ phpstan.neon export-ignore phpunit.xml.dist export-ignore compose.yaml export-ignore Makefile export-ignore +renovate.json export-ignore # Remove directories for archives .docker/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e40c7f8..0cf3aea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: push: branches: - master + - next workflow_dispatch: jobs: diff --git a/README.md b/README.md index d0b1ee3..1d2a9ae 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ var_dump($total->equals('0.3')); // bool(true) composer require php-collective/decimal-object ``` -Requires PHP 8.2+ and the `bcmath` extension. PHP 8.1 is covered by the 1.3 releases. For anything older, use the [legacy library](https://github.com/spryker/decimal-object). +Requires PHP 8.2+ and the `bcmath` extension. The 1.x API is maintained in the 1.4 releases, see [Upgrading](https://php-collective.github.io/decimal-object/reference/upgrading) for the changes. PHP 8.1 is covered by the 1.3 releases. For anything older, use the [legacy library](https://github.com/spryker/decimal-object). ## Usage diff --git a/composer.json b/composer.json index c37719e..767f4fa 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,7 @@ }, "require": { "php": ">=8.2", - "ext-bcmath": "*", - "ext-json": "*" + "ext-bcmath": "*" }, "require-dev": { "php-collective/code-sniffer": "^0.6.8", @@ -54,7 +53,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-master": "1.x-dev", + "dev-next": "2.x-dev" } }, "scripts": { diff --git a/tests/DecimalTest.php b/tests/DecimalTest.php index 93b7a6b..b36b934 100644 --- a/tests/DecimalTest.php +++ b/tests/DecimalTest.php @@ -16,6 +16,7 @@ use PhpCollective\DecimalObject\Decimal; use PhpCollective\DecimalObject\Exception\DecimalException; use PhpCollective\DecimalObject\Exception\DivisionByZeroException; +use PhpCollective\DecimalObject\Exception\InvalidArgumentException as DecimalInvalidArgumentException; use PhpCollective\DecimalObject\Exception\InvalidNumberException; use PhpCollective\DecimalObject\Exception\NegativeNumberException; use PhpCollective\DecimalObject\Exception\OverflowException; @@ -2495,4 +2496,18 @@ public function testNativeRoundingMode(): void $this->assertSame(count($cases), count(constant('RoundingMode::HalfEven')::cases())); } + + /** + * The types list `float` so that PHP does not turn 2.5 into 2 for callers not using strict types. + * + * @return void + */ + public function testFloatOperandsAreRejectedWithoutStrictTypes(): void + { + $result = require __DIR__ . '/data/float_operands.php'; + + $expected = DecimalInvalidArgumentException::class; + + $this->assertSame(['mod' => $expected, 'pow' => $expected], $result); + } } diff --git a/tests/data/float_operands.php b/tests/data/float_operands.php new file mode 100644 index 0000000..d0842bb --- /dev/null +++ b/tests/data/float_operands.php @@ -0,0 +1,26 @@ +mod(2.5); +} catch (Throwable $e) { + $result['mod'] = $e::class; +} + +try { + $result['pow'] = (string)(new Decimal('4'))->pow(2.0); +} catch (Throwable $e) { + $result['pow'] = $e::class; +} + +return $result;