Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- next
workflow_dispatch:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"require": {
"php": ">=8.2",
"ext-bcmath": "*",
"ext-json": "*"
"ext-bcmath": "*"
},
"require-dev": {
"php-collective/code-sniffer": "^0.6.8",
Expand All @@ -54,7 +53,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "1.x-dev",
"dev-next": "2.x-dev"
}
},
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions tests/DecimalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
26 changes: 26 additions & 0 deletions tests/data/float_operands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

// No strict_types on purpose: this is how a caller without it reaches the methods.

use PhpCollective\DecimalObject\Decimal;

$result = [];

try {
$result['mod'] = (string)(new Decimal('7.0'))->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;
Loading