Skip to content

Commit

Permalink
Revert "Improve nonexistent class name handling in GenericClassString…
Browse files Browse the repository at this point in the history
…Type"

This reverts commit d738439.
  • Loading branch information
ondrejmirtes committed Dec 20, 2022
1 parent e7b0173 commit 387bde4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build/phpstan.neon
Expand Up @@ -85,7 +85,7 @@ parameters:
message: '#^Variable property access on PHPStan\\Rules\\RuleError\.$#'
path: ../src/Rules/RuleErrorBuilder.php
-
message: "#^Parameter \\#1 (?:\\$argument|\\$objectOrClass) of class ReflectionClass constructor expects class\\-string\\<T of object>\\|T of object, string given\\.$#"
message: "#^Parameter \\#1 (?:\\$argument|\\$objectOrClass) of class ReflectionClass constructor expects class\\-string\\<PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig\\>\\|PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig, string given\\.$#"
count: 1
path: ../src/Command/CommandHelper.php
- '#^Parameter \#1 \$offsetType of class PHPStan\\Type\\Accessory\\HasOffsetType constructor expects PHPStan\\Type\\Constant\\ConstantIntegerType\|PHPStan\\Type\\Constant\\ConstantStringType#'
Expand Down
8 changes: 1 addition & 7 deletions src/Type/Generic/GenericClassStringType.php
Expand Up @@ -53,9 +53,6 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic

if ($type instanceof ConstantStringType) {
if (!$type->isClassStringType()->yes()) {
if ($this->type instanceof TypeWithClassName) {
return TrinaryLogic::createFromBoolean($this->type->getClassName() === $type->getValue());
}
return TrinaryLogic::createNo();
}

Expand Down Expand Up @@ -102,9 +99,6 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
}

if (!$type->isClassStringType()->yes()) {
if ($this->type instanceof TypeWithClassName) {
return $isSuperType->or(TrinaryLogic::createFromBoolean($this->type->getClassName() === $type->getValue()));
}
$isSuperType = $isSuperType->and(TrinaryLogic::createMaybe());
}

Expand Down Expand Up @@ -134,7 +128,7 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
return $receivedType->inferTemplateTypesOn($this);
}

if ($receivedType instanceof ConstantStringType && $receivedType->isClassStringType()->yes()) {
if ($receivedType instanceof ConstantStringType) {
$typeToInfer = new ObjectType($receivedType->getValue());
} elseif ($receivedType instanceof self) {
$typeToInfer = $receivedType->type;
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-6687.php
Expand Up @@ -28,7 +28,7 @@ function bar(string $a): void
function baz(string $a): void
{
if ($a === BAZ || is_subclass_of($a, BAZ)) {
assertType("class-string<BAZ>", $a);
assertType("'BAZ'|class-string<BAZ>", $a);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Expand Up @@ -411,11 +411,11 @@ public function testBug4550(): void
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-4550.php'], [
[
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<mixed>, string given.',
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<Person>, string given.',
34,
],
[
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<mixed>, string given.',
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<Person>, string given.',
44,
],
]);
Expand Down
10 changes: 0 additions & 10 deletions tests/PHPStan/Type/Generic/GenericClassStringTypeTest.php
Expand Up @@ -155,11 +155,6 @@ public function dataIsSuperTypeOf(): array
new ConstantStringType(IntegerType::class),
TrinaryLogic::createMaybe(),
],
[
new GenericClassStringType(new ObjectType('NonexistentClass')),
new ConstantStringType('NonexistentClass'),
TrinaryLogic::createYes(),
],
];
}

Expand Down Expand Up @@ -277,11 +272,6 @@ public function dataAccepts(): array
new BenevolentUnionType([new IntegerType(), new StringType()]),
TrinaryLogic::createMaybe(),
],
[
new GenericClassStringType(new ObjectType('NonexistentClass')),
new ConstantStringType('NonexistentClass'),
TrinaryLogic::createYes(),
],
];
}

Expand Down

0 comments on commit 387bde4

Please sign in to comment.