Skip to content

Commit 17239c1

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
2 parents 68d01a5 + ca2c937 commit 17239c1

File tree

79 files changed

+1300
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1300
-67
lines changed

conf/config.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,11 @@ services:
14711471
tags:
14721472
- phpstan.dynamicFunctionThrowTypeExtension
14731473

1474+
-
1475+
class: PHPStan\Type\Php\ParseStrParameterOutTypeExtension
1476+
tags:
1477+
- phpstan.functionParameterOutTypeExtension
1478+
14741479
-
14751480
class: PHPStan\Type\Php\PregMatchTypeSpecifyingExtension
14761481
tags:
@@ -1681,6 +1686,11 @@ services:
16811686
tags:
16821687
- phpstan.broker.dynamicFunctionReturnTypeExtension
16831688

1689+
-
1690+
class: PHPStan\Type\Php\TrimFunctionDynamicReturnTypeExtension
1691+
tags:
1692+
- phpstan.broker.dynamicFunctionReturnTypeExtension
1693+
16841694
-
16851695
class: PHPStan\Type\Php\VersionCompareFunctionDynamicReturnTypeExtension
16861696
arguments:

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ parameters:
781781
message: '#^Doing instanceof PHPStan\\Type\\IntersectionType is error\-prone and deprecated\.$#'
782782
identifier: phpstanApi.instanceofType
783783
count: 1
784+
path: src/Type/Accessory/AccessoryUppercaseStringType.php
785+
786+
-
787+
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
788+
count: 1
784789
path: src/Type/Accessory/HasMethodType.php
785790

786791
-

resources/functionMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6362,7 +6362,7 @@
63626362
'mb_strrpos' => ['0|positive-int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'],
63636363
'mb_strstr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'],
63646364
'mb_strtolower' => ['lowercase-string', 'str'=>'string', 'encoding='=>'string'],
6365-
'mb_strtoupper' => ['string', 'str'=>'string', 'encoding='=>'string'],
6365+
'mb_strtoupper' => ['uppercase-string', 'str'=>'string', 'encoding='=>'string'],
63666366
'mb_strwidth' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
63676367
'mb_substitute_character' => ['mixed', 'substchar='=>'mixed'],
63686368
'mb_substr' => ['string', 'str'=>'string', 'start'=>'int', 'length='=>'?int', 'encoding='=>'string'],
@@ -12087,7 +12087,7 @@
1208712087
'strtok\'1' => ['non-empty-string|false', 'token'=>'string'],
1208812088
'strtolower' => ['lowercase-string', 'str'=>'string'],
1208912089
'strtotime' => ['int|false', 'time'=>'string', 'now='=>'int'],
12090-
'strtoupper' => ['string', 'str'=>'string'],
12090+
'strtoupper' => ['uppercase-string', 'str'=>'string'],
1209112091
'strtr' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],
1209212092
'strtr\'1' => ['string', 'str'=>'string', 'replace_pairs'=>'array'],
1209312093
'strval' => ['string', 'var'=>'__stringAndStringable|int|float|bool|resource|null'],

src/PhpDoc/TypeNodeResolver.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
5151
use PHPStan\Type\Accessory\AccessoryNonFalsyStringType;
5252
use PHPStan\Type\Accessory\AccessoryNumericStringType;
53+
use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
5354
use PHPStan\Type\Accessory\NonEmptyArrayType;
5455
use PHPStan\Type\ArrayType;
5556
use PHPStan\Type\BenevolentUnionType;
@@ -224,6 +225,9 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
224225
case 'lowercase-string':
225226
return new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]);
226227

228+
case 'uppercase-string':
229+
return new IntersectionType([new StringType(), new AccessoryUppercaseStringType()]);
230+
227231
case 'literal-string':
228232
return new IntersectionType([new StringType(), new AccessoryLiteralStringType()]);
229233

@@ -304,6 +308,13 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
304308
new AccessoryLowercaseStringType(),
305309
]);
306310

311+
case 'non-empty-uppercase-string':
312+
return new IntersectionType([
313+
new StringType(),
314+
new AccessoryNonEmptyStringType(),
315+
new AccessoryUppercaseStringType(),
316+
]);
317+
307318
case 'truthy-string':
308319
case 'non-falsy-string':
309320
return new IntersectionType([

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
3232
use PHPStan\Type\Accessory\AccessoryNonFalsyStringType;
3333
use PHPStan\Type\Accessory\AccessoryNumericStringType;
34+
use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
3435
use PHPStan\Type\Accessory\NonEmptyArrayType;
3536
use PHPStan\Type\ArrayType;
3637
use PHPStan\Type\BenevolentUnionType;
@@ -480,10 +481,15 @@ public function resolveConcatType(Type $left, Type $right): Type
480481
if ($leftStringType->isLiteralString()->and($rightStringType->isLiteralString())->yes()) {
481482
$accessoryTypes[] = new AccessoryLiteralStringType();
482483
}
484+
483485
if ($leftStringType->isLowercaseString()->and($rightStringType->isLowercaseString())->yes()) {
484486
$accessoryTypes[] = new AccessoryLowercaseStringType();
485487
}
486488

489+
if ($leftStringType->isUppercaseString()->and($rightStringType->isUppercaseString())->yes()) {
490+
$accessoryTypes[] = new AccessoryUppercaseStringType();
491+
}
492+
487493
$leftNumericStringNonEmpty = TypeCombinator::remove($leftStringType, new ConstantStringType(''));
488494
if ($leftNumericStringNonEmpty->isNumericString()->yes()) {
489495
$allRightConstantsZeroOrMore = false;

src/Rules/Api/ApiInstanceofTypeRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Type\Accessory\AccessoryNonFalsyStringType;
1717
use PHPStan\Type\Accessory\AccessoryNumericStringType;
1818
use PHPStan\Type\Accessory\AccessoryType;
19+
use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
1920
use PHPStan\Type\Accessory\HasMethodType;
2021
use PHPStan\Type\Accessory\HasOffsetType;
2122
use PHPStan\Type\Accessory\HasPropertyType;
@@ -84,6 +85,7 @@ final class ApiInstanceofTypeRule implements Rule
8485
AccessoryNumericStringType::class => 'Type::isNumericString()',
8586
AccessoryLiteralStringType::class => 'Type::isLiteralString()',
8687
AccessoryLowercaseStringType::class => 'Type::isLowercaseString()',
88+
AccessoryUppercaseStringType::class => 'Type::isUppercaseString()',
8789
AccessoryNonEmptyStringType::class => 'Type::isNonEmptyString()',
8890
AccessoryNonFalsyStringType::class => 'Type::isNonFalsyString()',
8991
HasMethodType::class => 'Type::hasMethod()',

src/Rules/Comparison/StrictComparisonOfDifferentTypesRule.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,26 @@ public function processNode(Node $node, Scope $scope): array
8080
};
8181

8282
$verbosity = VerbosityLevel::value();
83+
8384
if (
8485
(
8586
$leftType->isConstantScalarValue()->yes()
8687
&& !$leftType->isString()->no()
8788
&& !$rightType->isConstantScalarValue()->yes()
8889
&& !$rightType->isString()->no()
89-
&& TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
90+
&& (
91+
TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
92+
|| TrinaryLogic::extremeIdentity($leftType->isUppercaseString(), $rightType->isUppercaseString())->maybe()
93+
)
9094
) || (
9195
$rightType->isConstantScalarValue()->yes()
9296
&& !$rightType->isString()->no()
9397
&& !$leftType->isConstantScalarValue()->yes()
9498
&& !$leftType->isString()->no()
95-
&& TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
99+
&& (
100+
TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
101+
|| TrinaryLogic::extremeIdentity($leftType->isUppercaseString(), $rightType->isUppercaseString())->maybe()
102+
)
96103
)
97104
) {
98105
$verbosity = VerbosityLevel::precise();

src/Type/Accessory/AccessoryArrayListType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ public function isClassString(): TrinaryLogic
398398
return TrinaryLogic::createNo();
399399
}
400400

401+
public function isUppercaseString(): TrinaryLogic
402+
{
403+
return TrinaryLogic::createNo();
404+
}
405+
401406
public function getClassStringObjectType(): Type
402407
{
403408
return new ErrorType();

src/Type/Accessory/AccessoryLiteralStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ public function isClassString(): TrinaryLogic
298298
return TrinaryLogic::createMaybe();
299299
}
300300

301+
public function isUppercaseString(): TrinaryLogic
302+
{
303+
return TrinaryLogic::createMaybe();
304+
}
305+
301306
public function getClassStringObjectType(): Type
302307
{
303308
return new ObjectWithoutClassType();

src/Type/Accessory/AccessoryLowercaseStringType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ public function isClassString(): TrinaryLogic
294294
return TrinaryLogic::createMaybe();
295295
}
296296

297+
public function isUppercaseString(): TrinaryLogic
298+
{
299+
return TrinaryLogic::createMaybe();
300+
}
301+
297302
public function getClassStringObjectType(): Type
298303
{
299304
return new ObjectWithoutClassType();

0 commit comments

Comments
 (0)