Skip to content

Commit

Permalink
Remove "allow leading zeros" code
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 17, 2024
1 parent fc86908 commit 2cc0fae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
16 changes: 2 additions & 14 deletions src/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;

use function assert;
use function ctype_digit;
use function is_int;
use function is_string;
use function rtrim;
Expand Down Expand Up @@ -54,24 +53,13 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): int
'DBAL assumes values outside of the integer range to be returned as string by the database driver.',
);

if (str_starts_with($value, '-') || str_starts_with($value, '+')) {
$hasNegativeSign = str_starts_with($value, '-');
$value = substr($value, 1);
} else {
$hasNegativeSign = false;
}

while (substr($value, 0, 1) === '0' && ctype_digit(substr($value, 1, 1))) {
$value = substr($value, 1);
}

$dotPos = strpos($value, '.');
if ($dotPos !== false && rtrim(substr($value, $dotPos + 1), '0') === '') {

Check failure on line 57 in src/Types/BigIntType.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (8.3)

NoValue

src/Types/BigIntType.php:57:47: NoValue: All possible types for this argument were invalidated - This may be dead code (see https://psalm.dev/179)
$value = substr($value, 0, $dotPos);

Check failure on line 58 in src/Types/BigIntType.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (8.3)

NoValue

src/Types/BigIntType.php:58:29: NoValue: All possible types for this argument were invalidated - This may be dead code (see https://psalm.dev/179)
}

if ($hasNegativeSign && $value !== '0') {
$value = '-' . $value;
if (str_starts_with($value, '+') || $value === '-0') {
$value = substr($value, 1);
}

if ($value === (string) (int) $value) {
Expand Down
15 changes: 0 additions & 15 deletions tests/Functional/Types/BigIntTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;

use function str_starts_with;
use function substr;

use const PHP_INT_MAX;
use const PHP_INT_MIN;
use const PHP_INT_SIZE;
Expand Down Expand Up @@ -53,18 +50,6 @@ public function testSelectBigInt(string $sqlLiteral, int|string|null $expectedVa
Types::BIGINT,
),
);

$startsWithSign = str_starts_with($sqlLiteral, '-') || str_starts_with($sqlLiteral, '+');

self::assertSame(
$expectedValue,
$this->connection->convertToPHPValue(
($startsWithSign ? substr($sqlLiteral, 0, 1) : '')
. '00'
. ($startsWithSign ? substr($sqlLiteral, 1) : $sqlLiteral),
Types::BIGINT,
),
);
}

/** @return Generator<string, array{string, int|string|null}> */
Expand Down

0 comments on commit 2cc0fae

Please sign in to comment.