Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 13 additions & 25 deletions
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);

‎tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 186 additions & 114 deletions
Large diffs are not rendered by default.

‎tests/Platform/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ Set current working directory to project root.
88
- `printf "UID=$(id -u)\nGID=$(id -g)" > .env`
99
- `docker-compose -f tests/Platform/docker/docker-compose.yml up -d`
1010

11-
# Test behaviour with old stringification
11+
# Test behaviour for PHP 8.0 (old stringification)
1212
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php80 composer update`
1313
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php80 php -d memory_limit=1G vendor/bin/phpunit --group=platform`
1414

15-
# Test behaviour with new stringification
15+
# Test behaviour for PHP 8.1 (adjusted stringification)
1616
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 composer update`
1717
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 php -d memory_limit=1G vendor/bin/phpunit --group=platform`
18+
19+
# Test behaviour for PHP 8.4 (pdo_pgsql float stringification fix)
20+
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 composer update`
21+
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 php -d memory_limit=1G vendor/bin/phpunit --group=platform`
1822
```
1923

2024
You can also run utilize those containers for PHPStorm PHPUnit configuration.
2125

2226
Since the dataset is huge and takes few minutes to run, you can filter only functions you are interested in:
2327
```sh
24-
docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 php -d memory_limit=1G vendor/bin/phpunit --group=platform --filter "AVG"
28+
docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 php -d memory_limit=1G vendor/bin/phpunit --group=platform --filter "AVG"
2529
```

‎tests/Platform/docker/Dockerfile84

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM php:8.4.0beta4-cli
2+
3+
# MSSQL
4+
RUN apt update \
5+
&& apt install -y gnupg2 \
6+
&& apt install -y unixodbc-dev unixodbc \
7+
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
8+
&& curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/mssql-tools.list \
9+
&& apt update \
10+
&& ACCEPT_EULA=Y apt install -y msodbcsql17 \
11+
&& pecl install sqlsrv \
12+
&& pecl install pdo_sqlsrv \
13+
&& docker-php-ext-enable sqlsrv pdo_sqlsrv
14+
15+
RUN set -ex \
16+
&& apt update \
17+
&& apt install -y bash zip libpq-dev libsqlite3-dev \
18+
&& pecl install xdebug-3.4 mongodb \
19+
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
20+
&& docker-php-ext-install pdo mysqli pgsql pdo_mysql pdo_pgsql pdo_sqlite \
21+
&& docker-php-ext-enable mongodb # TODO xdebug not yet supported here
22+
23+
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
24+

‎tests/Platform/docker/docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ services:
6363
user: ${UID:-1000}:${GID:-1000}
6464
volumes:
6565
- ../../../:/app
66+
67+
php84:
68+
depends_on: [mysql, pgsql]
69+
build:
70+
context: .
71+
dockerfile: ./Dockerfile84
72+
environment:
73+
MYSQL_HOST: mysql
74+
PGSQL_HOST: pgsql
75+
MSSQL_HOST: mssql
76+
working_dir: /app
77+
user: ${UID:-1000}:${GID:-1000}
78+
volumes:
79+
- ../../../:/app

0 commit comments

Comments
 (0)
Please sign in to comment.