Skip to content

Commit

Permalink
Change BigIntType Casting
Browse files Browse the repository at this point in the history
- Cast to int within safe range, else to string.
  • Loading branch information
cizordj committed Sep 3, 2023
1 parent 9128251 commit 5661051
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* Type that maps a database BIGINT to a PHP string.
* Type that maps a database BIGINT to a PHP int.
*/
class BigIntType extends Type implements PhpIntegerMappingType
{
Expand All @@ -22,18 +22,27 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st

public function getBindingType(): ParameterType
{
return ParameterType::STRING;
return ParameterType::INTEGER;
}

/**
* @param T $value
*
* @return (T is null ? null : string)
* @return (T is null ? null : int|string)
*
* @template T
*/
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): int|string|null

Check warning on line 35 in src/Types/BigIntType.php

View check run for this annotation

Codecov / codecov/patch

src/Types/BigIntType.php#L35

Added line #L35 was not covered by tests
{
return $value === null ? null : (string) $value;
if (null === $value) {

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Yoda comparisons are disallowed.
return null;

Check warning on line 38 in src/Types/BigIntType.php

View check run for this annotation

Codecov / codecov/patch

src/Types/BigIntType.php#L37-L38

Added lines #L37 - L38 were not covered by tests
} elseif (

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Use "if" instead of "elseif".
$value <= PHP_INT_MAX &&

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Constant PHP_INT_MAX should not be referenced via a fallback global name, but via a use statement.
$value >= PHP_INT_MIN

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Constant PHP_INT_MIN should not be referenced via a fallback global name, but via a use statement.

Check warning on line 41 in src/Types/BigIntType.php

View check run for this annotation

Codecov / codecov/patch

src/Types/BigIntType.php#L40-L41

Added lines #L40 - L41 were not covered by tests
) {
return (int) $value;

Check warning on line 43 in src/Types/BigIntType.php

View check run for this annotation

Codecov / codecov/patch

src/Types/BigIntType.php#L43

Added line #L43 was not covered by tests
} else {

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

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Remove useless "else" to reduce code nesting.
return (string) $value;

Check warning on line 45 in src/Types/BigIntType.php

View check run for this annotation

Codecov / codecov/patch

src/Types/BigIntType.php#L45

Added line #L45 was not covered by tests
}
}
}

0 comments on commit 5661051

Please sign in to comment.