Skip to content

Commit 27b0933

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

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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)