Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,13 @@ public function getTypeAliases(): array

$typeAliasImportTags = $resolvedPhpDoc->getTypeAliasImportTags();
$typeAliasTags = $resolvedPhpDoc->getTypeAliasTags();
$localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags);

// prevent circular imports
if (array_key_exists($this->getName(), self::$resolvingTypeAliasImports)) {
if ($localAliases !== []) {
return $this->typeAliases = $localAliases;
}
throw new CircularTypeAliasDefinitionException();
}

Expand Down Expand Up @@ -1406,8 +1410,6 @@ public function getTypeAliases(): array

unset(self::$resolvingTypeAliasImports[$this->getName()]);

$localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags);

$this->typeAliases = array_filter(
array_merge($importedAliases, $localAliases),
static fn (?TypeAlias $typeAlias): bool => $typeAlias !== null,
Expand Down
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3900,4 +3900,21 @@ public function testBug6120(): void
$this->analyse([__DIR__ . '/data/bug-6120.php'], []);
}

public function testBug11463(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/../PhpDoc/data/bug-11463.php'], [
[
"Parameter #1 \$bar of method Bug11463\FooType::foo() expects 'bar', 'bla' given.",
32,
],
[
"Parameter #1 \$foo of method Bug11463\BarType::bar() expects 'foo', 'bla' given.",
35,
],
]);
}

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

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

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

}
36 changes: 36 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-11463.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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; }
}

function doFoo(FooType $foo, BarType $bar): void {
$foo->foo('bar');
$foo->foo('bla');

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

namespace Bug11463b;

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

/**
* @param Baz $bar
*/
public function baz(string $bar): void {}
}

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

/**
* @param Baz $bar
*/
public function baz(string $bar): void {}
}

/**
* @phpstan-type Baz 'baz'
*/
class BazType {
}
Loading