Skip to content

Commit be66017

Browse files
committedSep 9, 2024
Merge remote-tracking branch 'origin/1.5.x' into 2.0.x
2 parents 039d325 + 0d88669 commit be66017

File tree

6 files changed

+245
-149
lines changed

6 files changed

+245
-149
lines changed
 

‎src/Type/Doctrine/Descriptors/FloatType.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,12 @@ public function getDatabaseInternalTypeForDriver(Connection $connection): Type
5252
{
5353
$driverType = $this->driverDetector->detect($connection);
5454

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

‎src/Type/Doctrine/Query/QueryResultTypeWalker.php

+13-25
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,6 @@ public function walkFunction($function): string
463463
}
464464

465465
if ($this->containsOnlyNumericTypes($exprTypeNoNull)) {
466-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
467-
return $this->marshalType($this->createNumericString($nullable));
468-
}
469-
470466
return $this->marshalType($exprType); // retains underlying type
471467
}
472468

@@ -619,13 +615,7 @@ public function walkFunction($function): string
619615
$type = TypeCombinator::addNull($type);
620616
}
621617

622-
} elseif ($this->driverType === DriverDetector::PDO_PGSQL) {
623-
$type = new IntersectionType([
624-
new StringType(),
625-
new AccessoryNumericStringType(),
626-
]);
627-
628-
} elseif ($this->driverType === DriverDetector::PGSQL) {
618+
} elseif ($this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
629619
$castedExprType = $this->castStringLiteralForNumericExpression($exprTypeNoNull);
630620

631621
if ($castedExprType->isInteger()->yes() || $castedExprType->isFloat()->yes()) {
@@ -1763,12 +1753,6 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17631753
return $this->createInteger($nullable);
17641754
}
17651755

1766-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
1767-
if ($this->containsOnlyNumericTypes($unionWithoutNull)) {
1768-
return $this->createNumericString($nullable);
1769-
}
1770-
}
1771-
17721756
if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
17731757
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
17741758
return new MixedType();
@@ -1783,7 +1767,7 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17831767
return $this->createFloatOrInt($nullable);
17841768
}
17851769

1786-
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
1770+
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
17871771
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
17881772
return $this->createFloat($nullable);
17891773
}
@@ -1849,12 +1833,6 @@ private function inferDivisionType(array $termTypes): Type
18491833
return new MixedType();
18501834
}
18511835

1852-
if ($this->driverType === DriverDetector::PDO_PGSQL) {
1853-
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType(), $this->createNumericString(false)])) {
1854-
return $this->createNumericString($nullable);
1855-
}
1856-
}
1857-
18581836
if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
18591837
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
18601838
return new MixedType();
@@ -1869,7 +1847,7 @@ private function inferDivisionType(array $termTypes): Type
18691847
return $this->createFloatOrInt($nullable);
18701848
}
18711849

1872-
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
1850+
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
18731851
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
18741852
return $this->createFloat($nullable);
18751853
}
@@ -2090,6 +2068,9 @@ private function hasAggregateWithoutGroupBy(): bool
20902068
* - pdo_sqlite: https://github.com/php/php-src/commit/438b025a28cda2935613af412fc13702883dd3a2
20912069
* - pdo_pgsql: https://github.com/php/php-src/commit/737195c3ae6ac53b9501cfc39cc80fd462909c82
20922070
*
2071+
* Notable 8.4 changes:
2072+
* - pdo_pgsql: https://github.com/php/php-src/commit/6d10a6989897e9089d62edf939344437128e93ad
2073+
*
20932074
* @param IntegerType|FloatType|BooleanType $type
20942075
*/
20952076
private function shouldStringifyExpressions(Type $type): TrinaryLogic
@@ -2134,7 +2115,14 @@ private function shouldStringifyExpressions(Type $type): TrinaryLogic
21342115
}
21352116

21362117
return TrinaryLogic::createNo();
2118+
}
21372119

2120+
if ($type->isFloat()->yes()) {
2121+
if ($this->phpVersion->getVersionId() >= 80400) {
2122+
return TrinaryLogic::createFromBoolean($stringifyFetches);
2123+
}
2124+
2125+
return TrinaryLogic::createYes();
21382126
}
21392127

21402128
return TrinaryLogic::createFromBoolean($stringifyFetches);

0 commit comments

Comments
 (0)