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 fb0e78d

Browse files
get rid of couple instanceof *Type checks in TypeCombinator
1 parent bd10157 commit fb0e78d

File tree

3 files changed

+6
-42
lines changed

3 files changed

+6
-42
lines changed

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,30 +1719,12 @@ parameters:
17191719
count: 5
17201720
path: src/Type/TypeCombinator.php
17211721

1722-
-
1723-
message: '#^Doing instanceof PHPStan\\Type\\BooleanType is error\-prone and deprecated\. Use Type\:\:isBoolean\(\) instead\.$#'
1724-
identifier: phpstanApi.instanceofType
1725-
count: 1
1726-
path: src/Type/TypeCombinator.php
1727-
17281722
-
17291723
message: '#^Doing instanceof PHPStan\\Type\\CallableType is error\-prone and deprecated\. Use Type\:\:isCallable\(\) and Type\:\:getCallableParametersAcceptors\(\) instead\.$#'
17301724
identifier: phpstanApi.instanceofType
17311725
count: 1
17321726
path: src/Type/TypeCombinator.php
17331727

1734-
-
1735-
message: '#^Doing instanceof PHPStan\\Type\\ClassStringType is error\-prone and deprecated\. Use Type\:\:isClassStringType\(\) instead\.$#'
1736-
identifier: phpstanApi.instanceofType
1737-
count: 1
1738-
path: src/Type/TypeCombinator.php
1739-
1740-
-
1741-
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
1742-
identifier: phpstanApi.instanceofType
1743-
count: 1
1744-
path: src/Type/TypeCombinator.php
1745-
17461728
-
17471729
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantArrayType is error\-prone and deprecated\. Use Type\:\:getConstantArrays\(\) instead\.$#'
17481730
identifier: phpstanApi.instanceofType
@@ -1755,24 +1737,12 @@ parameters:
17551737
count: 5
17561738
path: src/Type/TypeCombinator.php
17571739

1758-
-
1759-
message: '#^Doing instanceof PHPStan\\Type\\FloatType is error\-prone and deprecated\. Use Type\:\:isFloat\(\) instead\.$#'
1760-
identifier: phpstanApi.instanceofType
1761-
count: 1
1762-
path: src/Type/TypeCombinator.php
1763-
17641740
-
17651741
message: '#^Doing instanceof PHPStan\\Type\\Generic\\GenericClassStringType is error\-prone and deprecated\. Use Type\:\:isClassStringType\(\) and Type\:\:getClassStringObjectType\(\) instead\.$#'
17661742
identifier: phpstanApi.instanceofType
17671743
count: 2
17681744
path: src/Type/TypeCombinator.php
17691745

1770-
-
1771-
message: '#^Doing instanceof PHPStan\\Type\\IntegerType is error\-prone and deprecated\. Use Type\:\:isInteger\(\) instead\.$#'
1772-
identifier: phpstanApi.instanceofType
1773-
count: 1
1774-
path: src/Type/TypeCombinator.php
1775-
17761746
-
17771747
message: '#^Doing instanceof PHPStan\\Type\\IntersectionType is error\-prone and deprecated\.$#'
17781748
identifier: phpstanApi.instanceofType
@@ -1797,12 +1767,6 @@ parameters:
17971767
count: 2
17981768
path: src/Type/TypeCombinator.php
17991769

1800-
-
1801-
message: '#^Doing instanceof PHPStan\\Type\\StringType is error\-prone and deprecated\. Use Type\:\:isString\(\) instead\.$#'
1802-
identifier: phpstanApi.instanceofType
1803-
count: 1
1804-
path: src/Type/TypeCombinator.php
1805-
18061770
-
18071771
message: '#^Instanceof between PHPStan\\Type\\Constant\\ConstantIntegerType and PHPStan\\Type\\Constant\\ConstantIntegerType will always evaluate to true\.$#'
18081772
identifier: instanceof.alwaysTrue

‎src/Type/TypeCombinator.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,22 @@ public static function union(Type ...$types): Type
190190
$enumCaseTypes = [];
191191
$integerRangeTypes = [];
192192
for ($i = 0; $i < $typesCount; $i++) {
193-
if ($types[$i]instanceof ConstantScalarType) {
193+
if ($types[$i]->isConstantScalarValue()->yes()) {
194194
$type = $types[$i];
195195
$scalarTypes[get_class($type)][md5($type->describe(VerbosityLevel::cache()))] = $type;
196196
unset($types[$i]);
197197
continue;
198198
}
199-
if ($types[$i]instanceof BooleanType) {
199+
if ($types[$i]->isBoolean()->yes()) {
200200
$hasGenericScalarTypes[ConstantBooleanType::class] = true;
201201
}
202-
if ($types[$i]instanceof FloatType) {
202+
if ($types[$i]->isFloat()->yes()) {
203203
$hasGenericScalarTypes[ConstantFloatType::class] = true;
204204
}
205-
if ($types[$i]instanceof IntegerType && !$types[$i] instanceof IntegerRangeType) {
205+
if ($types[$i]->isInteger()->yes() && !$types[$i] instanceof IntegerRangeType) {
206206
$hasGenericScalarTypes[ConstantIntegerType::class] = true;
207207
}
208-
if ($types[$i]instanceof StringType && !$types[$i]instanceof ClassStringType) {
208+
if ($types[$i]->isString()->yes() && $types[$i]->isClassString()->no() && TypeUtils::getAccessoryTypes($types[$i]) === []) {
209209
$hasGenericScalarTypes[ConstantStringType::class] = true;
210210
}
211211
$enumCases = $types[$i]->getEnumCases();

‎tests/PHPStan/Analyser/AnalyserIntegrationTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public function testBug7094(): void
827827
$this->assertSame('Return type of call to method Bug7094\Foo::getAttribute() contains unresolvable type.', $errors[4]->getMessage());
828828
$this->assertSame(79, $errors[4]->getLine());
829829

830-
$this->assertSame('Parameter #1 $attr of method Bug7094\Foo::setAttributes() expects array{foo?: string, bar?: 5|6|7, baz?: bool}, non-empty-array<K of string, 5|6|7|bool|string> given.', $errors[5]->getMessage());
830+
$this->assertSame('Parameter #1 $attr of method Bug7094\Foo::setAttributes() expects array{foo?: string, bar?: 5|6|7, baz?: bool}, non-empty-array<\'bar\'|\'baz\'|\'foo\'|K of string, 5|6|7|bool|string> given.', $errors[5]->getMessage());
831831
$this->assertSame(29, $errors[5]->getLine());
832832
}
833833

0 commit comments

Comments
(0)

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