diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2538c6a..75a8581 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -87,7 +87,7 @@ jobs: - name: Check code style if: matrix.php-versions == env.code-coverage-version - run: composer run-script phpcs -- --report=checkstyle | cs2pr + run: composer run-script phpcs -- --report=checkstyle | cs2pr --graceful-warnings - name: Run PHPUnit tests if: matrix.php-versions != env.code-coverage-version diff --git a/phpcs.xml.dist b/phpcs.xml.dist index cad2f55..931fd08 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -25,7 +25,6 @@ - diff --git a/src/Serializer.php b/src/Serializer.php index de7d9d5..4fe9b6b 100644 --- a/src/Serializer.php +++ b/src/Serializer.php @@ -178,7 +178,7 @@ private static function serializeBoolean(bool $value): string private static function serializeInteger(int $value): string { - if ($value > 999999999999999 || $value < -999999999999999) { + if ($value > 999_999_999_999_999 || $value < -999_999_999_999_999) { throw new SerializeException("Integers are limited to 15 digits"); } return (string) $value; @@ -186,14 +186,16 @@ private static function serializeInteger(int $value): string private static function serializeDecimal(float $value): string { - if (abs(floor($value)) > 999999999999) { - throw new SerializeException("Integer portion of decimals is limited to 12 digits"); + $value = round($value, 3, PHP_ROUND_HALF_EVEN); + + if (abs(floor($value)) > 999_999_999_999) { + throw new SerializeException("Integer portion of decimals is limited to 12 digits after rounding to three decimal places"); } // Casting to a string loses a digit on long numbers, but is preserved - // by json_encode (e.g. 111111111111.111). + // by json_encode (e.g. 111_111_111_111.111). /** @var non-empty-string $result */ - $result = json_encode(round($value, 3, PHP_ROUND_HALF_EVEN)); + $result = json_encode($value); if (!str_contains($result, '.')) { $result .= '.0';