Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0e0abb

Browse files
Merge remote-tracking branch 'origin/1.5.x' into 2.0.x
2 parents 90c4275 + f36b6d6 commit f0e0abb

File tree

8 files changed

+268
-225
lines changed

8 files changed

+268
-225
lines changed

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.4 || ^8.0",
10-
"phpstan/phpstan": "^2.0"
10+
"phpstan/phpstan": "^2.0.3"
1111
},
1212
"conflict": {
1313
"doctrine/collections": "<1.0",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use Composer\InstalledVersions;
6-
use PHPStan\Type\Accessory\AccessoryNumericStringType;
76
use PHPStan\Type\IntegerType;
87
use PHPStan\Type\StringType;
98
use PHPStan\Type\Type;
@@ -25,7 +24,7 @@ public function getWritableToPropertyType(): Type
2524
return new IntegerType();
2625
}
2726

28-
return TypeCombinator::intersect(new StringType(), newAccessoryNumericStringType());
27+
return (new IntegerType())->toString();
2928
}
3029

3130
public function getWritableToDatabaseType(): Type

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
use Doctrine\DBAL\Connection;
66
use PHPStan\Doctrine\Driver\DriverDetector;
7-
use PHPStan\Type\Accessory\AccessoryNumericStringType;
87
use PHPStan\Type\FloatType;
98
use PHPStan\Type\IntegerType;
10-
use PHPStan\Type\IntersectionType;
119
use PHPStan\Type\StringType;
1210
use PHPStan\Type\Type;
1311
use PHPStan\Type\TypeCombinator;
@@ -30,7 +28,7 @@ public function getType(): string
3028

3129
public function getWritableToPropertyType(): Type
3230
{
33-
return TypeCombinator::intersect(new StringType(), newAccessoryNumericStringType());
31+
return (new FloatType())->toString();
3432
}
3533

3634
public function getWritableToDatabaseType(): Type
@@ -57,10 +55,7 @@ public function getDatabaseInternalTypeForDriver(Connection $connection): Type
5755
DriverDetector::PGSQL,
5856
DriverDetector::PDO_PGSQL,
5957
], true)) {
60-
return new IntersectionType([
61-
new StringType(),
62-
new AccessoryNumericStringType(),
63-
]);
58+
return (new FloatType())->toString();
6459
}
6560

6661
// not yet supported driver, return the old implementation guess

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use Doctrine\DBAL\Connection;
66
use PHPStan\Doctrine\Driver\DriverDetector;
7-
use PHPStan\Type\Accessory\AccessoryNumericStringType;
87
use PHPStan\Type\IntegerType;
9-
use PHPStan\Type\IntersectionType;
10-
use PHPStan\Type\StringType;
118
use PHPStan\Type\Type;
129
use PHPStan\Type\TypeCombinator;
1310
use function in_array;
@@ -41,10 +38,7 @@ public function getDatabaseInternalType(): Type
4138
{
4239
return TypeCombinator::union(
4340
new \PHPStan\Type\FloatType(),
44-
new IntersectionType([
45-
new StringType(),
46-
new AccessoryNumericStringType(),
47-
]),
41+
(new \PHPStan\Type\FloatType())->toString(),
4842
);
4943
}
5044

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

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
use PHPStan\Php\PhpVersion;
1919
use PHPStan\ShouldNotHappenException;
2020
use PHPStan\TrinaryLogic;
21+
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
2122
use PHPStan\Type\Accessory\AccessoryNumericStringType;
23+
use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
2224
use PHPStan\Type\ArrayType;
2325
use PHPStan\Type\BooleanType;
2426
use PHPStan\Type\Constant\ConstantBooleanType;
@@ -622,10 +624,10 @@ public function walkFunction($function): string
622624
$type = $this->createFloat(false);
623625

624626
} elseif ($castedExprType->isNumericString()->yes()) {
625-
$type = $this->createNumericString(false);
627+
$type = $this->createNumericString(false, $castedExprType->isLowercaseString()->yes(), $castedExprType->isUppercaseString()->yes());
626628

627629
} else {
628-
$type = TypeCombinator::union($this->createFloat(false), $this->createNumericString(false));
630+
$type = TypeCombinator::union($this->createFloat(false), $this->createNumericString(false, false, true));
629631
}
630632

631633
} else {
@@ -738,7 +740,7 @@ private function inferAvgFunction(AST\Functions\AvgFunction $function): Type
738740

739741
if ($this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::MYSQLI) {
740742
if ($exprTypeNoNull->isInteger()->yes()) {
741-
return $this->createNumericString($nullable);
743+
return $this->createNumericString($nullable, true, true);
742744
}
743745

744746
if ($exprTypeNoNull->isString()->yes() && !$exprTypeNoNull->isNumericString()->yes()) {
@@ -750,7 +752,7 @@ private function inferAvgFunction(AST\Functions\AvgFunction $function): Type
750752

751753
if ($this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::PDO_PGSQL) {
752754
if ($exprTypeNoNull->isInteger()->yes()) {
753-
return $this->createNumericString($nullable);
755+
return $this->createNumericString($nullable, true, true);
754756
}
755757

756758
return $this->generalizeConstantType($exprType, $nullable);
@@ -786,7 +788,7 @@ private function inferSumFunction(AST\Functions\SumFunction $function): Type
786788

787789
if ($this->driverType === DriverDetector::PDO_MYSQL || $this->driverType === DriverDetector::MYSQLI) {
788790
if ($exprTypeNoNull->isInteger()->yes()) {
789-
return $this->createNumericString($nullable);
791+
return $this->createNumericString($nullable, true, true);
790792
}
791793

792794
if ($exprTypeNoNull->isString()->yes() && !$exprTypeNoNull->isNumericString()->yes()) {
@@ -800,7 +802,7 @@ private function inferSumFunction(AST\Functions\SumFunction $function): Type
800802
if ($exprTypeNoNull->isInteger()->yes()) {
801803
return TypeCombinator::union(
802804
$this->createInteger($nullable),
803-
$this->createNumericString($nullable),
805+
$this->createNumericString($nullable, true, true),
804806
);
805807
}
806808

@@ -837,19 +839,41 @@ private function createNonNegativeInteger(bool $nullable): Type
837839
return $nullable ? TypeCombinator::addNull($integer) : $integer;
838840
}
839841

840-
private function createNumericString(bool $nullable): Type
842+
private function createNumericString(bool $nullable, bool$lowercase = false, bool$uppercase = false): Type
841843
{
842-
$numericString = TypeCombinator::intersect(
844+
$types = [
843845
new StringType(),
844846
new AccessoryNumericStringType(),
845-
);
847+
];
848+
if ($lowercase) {
849+
$types[] = new AccessoryLowercaseStringType();
850+
}
851+
if ($uppercase) {
852+
$types[] = new AccessoryUppercaseStringType();
853+
}
854+
855+
$numericString = new IntersectionType($types);
846856

847857
return $nullable ? TypeCombinator::addNull($numericString) : $numericString;
848858
}
849859

850-
private function createString(bool $nullable): Type
860+
private function createString(bool $nullable, bool$lowercase = false, bool$uppercase = false): Type
851861
{
852-
$string = new StringType();
862+
if ($lowercase || $uppercase) {
863+
$types = [
864+
new StringType(),
865+
];
866+
if ($lowercase) {
867+
$types[] = new AccessoryLowercaseStringType();
868+
}
869+
if ($uppercase) {
870+
$types[] = new AccessoryUppercaseStringType();
871+
}
872+
$string = new IntersectionType($types);
873+
} else {
874+
$string = new StringType();
875+
}
876+
853877
return $nullable ? TypeCombinator::addNull($string) : $string;
854878
}
855879

@@ -895,10 +919,18 @@ private function generalizeConstantType(Type $type, bool $makeNullable): Type
895919
$result = $this->createFloat($containsNull);
896920

897921
} elseif ($typeNoNull->isNumericString()->yes()) {
898-
$result = $this->createNumericString($containsNull);
922+
$result = $this->createNumericString(
923+
$containsNull,
924+
$typeNoNull->isLowercaseString()->yes(),
925+
$typeNoNull->isUppercaseString()->yes(),
926+
);
899927

900928
} elseif ($typeNoNull->isString()->yes()) {
901-
$result = $this->createString($containsNull);
929+
$result = $this->createString(
930+
$containsNull,
931+
$typeNoNull->isLowercaseString()->yes(),
932+
$typeNoNull->isUppercaseString()->yes(),
933+
);
902934

903935
} else {
904936
$result = $type;
@@ -1241,7 +1273,7 @@ public function walkSelectExpression($selectExpression): string
12411273

12421274
// e.g. 1.0 on sqlite results to '1' with pdo_stringify on PHP 8.1, but '1.0' on PHP 8.0 with no setup
12431275
// so we relax constant types and return just numeric-string to avoid those issues
1244-
$stringifiedFloat = $this->createNumericString(false);
1276+
$stringifiedFloat = $this->createNumericString(false, false, true);
12451277

12461278
if ($stringify->yes()) {
12471279
return $stringifiedFloat;
@@ -1773,7 +1805,11 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17731805
}
17741806

17751807
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), $this->createNumericString(false)])) {
1776-
return $this->createNumericString($nullable);
1808+
return $this->createNumericString(
1809+
$nullable,
1810+
$unionWithoutNull->toString()->isLowercaseString()->yes(),
1811+
$unionWithoutNull->toString()->isUppercaseString()->yes(),
1812+
);
17771813
}
17781814

17791815
if ($this->containsOnlyNumericTypes($unionWithoutNull)) {
@@ -1825,7 +1861,7 @@ private function inferDivisionType(array $termTypes): Type
18251861

18261862
if ($unionWithoutNull->isInteger()->yes()) {
18271863
if ($this->driverType === DriverDetector::MYSQLI || $this->driverType === DriverDetector::PDO_MYSQL) {
1828-
return $this->createNumericString($nullable);
1864+
return $this->createNumericString($nullable, true, true);
18291865
} elseif ($this->driverType === DriverDetector::PDO_PGSQL || $this->driverType === DriverDetector::PGSQL || $this->driverType === DriverDetector::SQLITE3 || $this->driverType === DriverDetector::PDO_SQLITE) {
18301866
return $this->createInteger($nullable);
18311867
}
@@ -1853,7 +1889,11 @@ private function inferDivisionType(array $termTypes): Type
18531889
}
18541890

18551891
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), $this->createNumericString(false)])) {
1856-
return $this->createNumericString($nullable);
1892+
return $this->createNumericString(
1893+
$nullable,
1894+
$unionWithoutNull->toString()->isLowercaseString()->yes(),
1895+
$unionWithoutNull->toString()->isUppercaseString()->yes(),
1896+
);
18571897
}
18581898

18591899
if ($this->containsOnlyTypes($unionWithoutNull, [new FloatType(), $this->createNumericString(false)])) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /