Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.5.x' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 9, 2024
2 parents 039d325 + 0d88669 commit be66017
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 149 deletions.
8 changes: 1 addition & 7 deletions src/Type/Doctrine/Descriptors/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@ public function getDatabaseInternalTypeForDriver(Connection $connection): Type
{
$driverType = $this->driverDetector->detect($connection);

if ($driverType === DriverDetector::PDO_PGSQL) {
return new IntersectionType([
new StringType(),
new AccessoryNumericStringType(),
]);
}

if (in_array($driverType, [
DriverDetector::SQLITE3,
DriverDetector::PDO_SQLITE,
DriverDetector::MYSQLI,
DriverDetector::PDO_MYSQL,
DriverDetector::PDO_PGSQL,
DriverDetector::PGSQL,
], true)) {
return new \PHPStan\Type\FloatType();
Expand Down
38 changes: 13 additions & 25 deletions src/Type/Doctrine/Query/QueryResultTypeWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@ public function walkFunction($function): string
}

if ($this->containsOnlyNumericTypes($exprTypeNoNull)) {
if ($this->driverType === DriverDetector::PDO_PGSQL) {
return $this->marshalType($this->createNumericString($nullable));
}

return $this->marshalType($exprType); // retains underlying type
}

Expand Down Expand Up @@ -619,13 +615,7 @@ public function walkFunction($function): string
$type = TypeCombinator::addNull($type);
}

} elseif ($this->driverType === DriverDetector::PDO_PGSQL) {
$type = new IntersectionType([
new StringType(),
new AccessoryNumericStringType(),
]);

} elseif ($this->driverType === DriverDetector::PGSQL) {
} elseif ($this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
$castedExprType = $this->castStringLiteralForNumericExpression($exprTypeNoNull);

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

if ($this->driverType === DriverDetector::PDO_PGSQL) {
if ($this->containsOnlyNumericTypes($unionWithoutNull)) {
return $this->createNumericString($nullable);
}
}

if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
return new MixedType();
Expand All @@ -1783,7 +1767,7 @@ private function inferPlusMinusTimesType(array $termTypes): Type
return $this->createFloatOrInt($nullable);
}

if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
return $this->createFloat($nullable);
}
Expand Down Expand Up @@ -1849,12 +1833,6 @@ private function inferDivisionType(array $termTypes): Type
return new MixedType();
}

if ($this->driverType === DriverDetector::PDO_PGSQL) {
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType(), $this->createNumericString(false)])) {
return $this->createNumericString($nullable);
}
}

if ($this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
if (!$this->containsOnlyNumericTypes(...$typesNoNull)) {
return new MixedType();
Expand All @@ -1869,7 +1847,7 @@ private function inferDivisionType(array $termTypes): Type
return $this->createFloatOrInt($nullable);
}

if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL) {
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType()])) {
return $this->createFloat($nullable);
}
Expand Down Expand Up @@ -2090,6 +2068,9 @@ private function hasAggregateWithoutGroupBy(): bool
* - pdo_sqlite: https://github.com/php/php-src/commit/438b025a28cda2935613af412fc13702883dd3a2
* - pdo_pgsql: https://github.com/php/php-src/commit/737195c3ae6ac53b9501cfc39cc80fd462909c82
*
* Notable 8.4 changes:
* - pdo_pgsql: https://github.com/php/php-src/commit/6d10a6989897e9089d62edf939344437128e93ad
*
* @param IntegerType|FloatType|BooleanType $type
*/
private function shouldStringifyExpressions(Type $type): TrinaryLogic
Expand Down Expand Up @@ -2134,7 +2115,14 @@ private function shouldStringifyExpressions(Type $type): TrinaryLogic
}

return TrinaryLogic::createNo();
}

if ($type->isFloat()->yes()) {
if ($this->phpVersion->getVersionId() >= 80400) {
return TrinaryLogic::createFromBoolean($stringifyFetches);
}

return TrinaryLogic::createYes();
}

return TrinaryLogic::createFromBoolean($stringifyFetches);
Expand Down
Loading

0 comments on commit be66017

Please sign in to comment.