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
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
Expand Down
12 changes: 7 additions & 5 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,24 @@

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;
}

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");

Check warning on line 192 in src/Serializer.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Line exceeds 120 characters; contains 135 characters
}

// 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';
Expand Down
Loading