Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,13 @@ public function getTypeAliases(): array

// prevent circular imports
if (array_key_exists($this->getName(), self::$resolvingTypeAliasImports)) {
// Return only local type aliases to break the cycle.
// Imported aliases are not available yet, but local ones
// don't depend on other classes and can be returned safely.
$localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags);
if ($localAliases !== []) {
return $localAliases;
}
Comment on lines +1382 to +1385
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this assign to $this->typeAliases?

throw new CircularTypeAliasDefinitionException();
}

Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,9 @@ public function testBug9708(): void
$this->analyse([__DIR__ . '/data/bug-9708.php'], []);
}

public function testBug11463(): void
{
$this->analyse([__DIR__ . '/data/bug-11463.php'], []);
}

}
28 changes: 28 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-11463.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types = 1);

namespace Bug11463;

/**
* @phpstan-type Foo 'foo'
*
* @phpstan-import-type Bar from BarType
*/
class FooType
{
/**
* @param Bar $bar
*/
public function foo(string $bar): void {}
}

/**
* @phpstan-import-type Foo from FooType
*
* @phpstan-type Bar 'bar'
*/
class BarType {
/**
* @param Foo $foo
*/
public function bar($foo): string { return $foo; }
}
Loading