Skip to content

Commit a103cfe

Browse files
janedbalondrejmirtes
authored andcommitted
QueryResultTypeWalker: support pdo_pgsql float fetches on PHP 8.4
1 parent 8badde6 commit a103cfe

File tree

3 files changed

+162
-150
lines changed

3 files changed

+162
-150
lines changed

src/Type/Doctrine/Descriptors/FloatType.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,12 @@ public function getDatabaseInternalTypeForDriver(Connection $connection): Type
5353
{
5454
$driverType = $this->driverDetector->detect($connection);
5555

56-
if ($driverType === DriverDetector::PDO_PGSQL) {
57-
return new IntersectionType([
58-
new StringType(),
59-
new AccessoryNumericStringType(),
60-
]);
61-
}
62-
6356
if (in_array($driverType, [
6457
DriverDetector::SQLITE3,
6558
DriverDetector::PDO_SQLITE,
6659
DriverDetector::MYSQLI,
6760
DriverDetector::PDO_MYSQL,
61+
DriverDetector::PDO_PGSQL,
6862
DriverDetector::PGSQL,
6963
], true)) {
7064
return new \PHPStan\Type\FloatType();

src/Type/Doctrine/Query/QueryResultTypeWalker.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,6 @@ public function walkFunction($function): string
471471
}
472472

473473
if ($this->containsOnlyNumericTypes($exprTypeNoNull)) {
474-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
475-
return $this->marshalType($this->createNumericString($nullable));
476-
}
477-
478474
return $this->marshalType($exprType); // retains underlying type
479475
}
480476

@@ -627,13 +623,7 @@ public function walkFunction($function): string
627623
$type = TypeCombinator::addNull($type);
628624
}
629625

630-
} elseif ($this->driverType === DriverDetector::PDO_PGSQL) {
631-
$type = new IntersectionType([
632-
new StringType(),
633-
new AccessoryNumericStringType(),
634-
]);
635-
636-
} elseif ($this->driverType === DriverDetector::PGSQL) {
626+
} elseif ($this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
637627
$castedExprType = $this->castStringLiteralForNumericExpression($exprTypeNoNull);
638628

639629
if ($castedExprType->isInteger()->yes() || $castedExprType->isFloat()->yes()) {
@@ -1771,12 +1761,6 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17711761
return $this->createInteger($nullable);
17721762
}
17731763

1774-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
1775-
if ($this->containsOnlyNumericTypes($unionWithoutNull)) {
1776-
return $this->createNumericString($nullable);
1777-
}
1778-
}
1779-
17801764
if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
17811765
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
17821766
return new MixedType();
@@ -1791,7 +1775,7 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17911775
return $this->createFloatOrInt($nullable);
17921776
}
17931777

1794-
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
1778+
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
17951779
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
17961780
return $this->createFloat($nullable);
17971781
}
@@ -1857,12 +1841,6 @@ private function inferDivisionType(array $termTypes): Type
18571841
return new MixedType();
18581842
}
18591843

1860-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
1861-
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType(), $this->createNumericString(false)])) {
1862-
return $this->createNumericString($nullable);
1863-
}
1864-
}
1865-
18661844
if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
18671845
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
18681846
return new MixedType();
@@ -1877,7 +1855,7 @@ private function inferDivisionType(array $termTypes): Type
18771855
return $this->createFloatOrInt($nullable);
18781856
}
18791857

1880-
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
1858+
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
18811859
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
18821860
return $this->createFloat($nullable);
18831861
}
@@ -2100,6 +2078,9 @@ private function hasAggregateWithoutGroupBy(): bool
21002078
* - pdo_sqlite: https://github.com/php/php-src/commit/438b025a28cda2935613af412fc13702883dd3a2
21012079
* - pdo_pgsql: https://github.com/php/php-src/commit/737195c3ae6ac53b9501cfc39cc80fd462909c82
21022080
*
2081+
* Notable 8.4 changes:
2082+
* - pdo_pgsql: https://github.com/php/php-src/commit/6d10a6989897e9089d62edf939344437128e93ad
2083+
*
21032084
* @param IntegerType|FloatType|BooleanType $type
21042085
*/
21052086
private function shouldStringifyExpressions(Type $type): TrinaryLogic
@@ -2144,7 +2125,14 @@ private function shouldStringifyExpressions(Type $type): TrinaryLogic
21442125
}
21452126

21462127
return TrinaryLogic::createNo();
2128+
}
21472129

2130+
if ($type->isFloat()->yes()) {
2131+
if ($this->phpVersion->getVersionId() >= 80400) {
2132+
return TrinaryLogic::createFromBoolean($stringifyFetches);
2133+
}
2134+
2135+
return TrinaryLogic::createYes();
21482136
}
21492137

21502138
return TrinaryLogic::createFromBoolean($stringifyFetches);

0 commit comments

Comments
 (0)