Skip to content

Commit 10042b7

Browse files
committed
Fix CI failures [claude-ci-fix]
Automated fix attempt 1 for CI failures.
1 parent dc1ec91 commit 10042b7

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/Type/FileTypeMapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
542542
&& !($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Include_)
543543
)
544544
)
545+
&& ($lookForTrait === null || $traitFound)
545546
) {
546547
$parentNameScope = array_last($typeMapStack) ?? null;
547548
$typeAliasesMap = array_last($typeAliasStack) ?? [];

tests/PHPStan/Type/FileTypeMapperTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,40 @@ public function testFileWithCyclicPhpDocs(): void
196196
$this->assertSame('CyclicPhpDocs\Foo|iterable<CyclicPhpDocs\Foo>', $returnTag->getType()->describe(VerbosityLevel::precise()));
197197
}
198198

199+
public function testBug12639TraitPropertyPhpDocResolution(): void
200+
{
201+
self::createReflectionProvider();
202+
203+
/** @var FileTypeMapper $fileTypeMapper */
204+
$fileTypeMapper = self::getContainer()->getByType(FileTypeMapper::class);
205+
206+
$classRealpath = realpath(__DIR__ . '/data/bug-12639-class.php');
207+
if ($classRealpath === false) {
208+
throw new ShouldNotHappenException();
209+
}
210+
211+
// Simulate how PhpClassReflectionExtension calls getResolvedPhpDoc for a trait property
212+
// When the trait is in a different file, $fileName is the class file
213+
$resolved = $fileTypeMapper->getResolvedPhpDoc(
214+
$classRealpath,
215+
'Bug12639Separate\OtherPlace\StandardAccount',
216+
'Bug12639Separate\Policy\BaseAccount',
217+
null,
218+
'/**
219+
* @var ObjectRefT<Account>
220+
*/',
221+
);
222+
223+
$varTags = $resolved->getVarTags();
224+
$this->assertArrayHasKey(0, $varTags);
225+
// Account should resolve to Bug12639Separate\Accounts\Account (from the trait's use statement),
226+
// not Bug12639Separate\OtherPlace\Account (class namespace)
227+
$this->assertSame(
228+
'Bug12639Separate\Types\ObjectRefT<Bug12639Separate\Accounts\Account>',
229+
$varTags[0]->getType()->describe(VerbosityLevel::precise()),
230+
);
231+
}
232+
199233
public function testFilesWithIdenticalPhpDocsUsingDifferentAliases(): void
200234
{
201235
/** @var FileTypeMapper $fileTypeMapper */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12639Separate\OtherPlace;
4+
5+
use Bug12639Separate\Policy\BaseAccount;
6+
7+
class StandardAccount
8+
{
9+
use BaseAccount;
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12639Separate\Policy;
4+
5+
if (true) {
6+
// some statement before use declarations
7+
}
8+
9+
use Bug12639Separate\Types\ObjectRefT;
10+
use Bug12639Separate\Accounts\Account;
11+
12+
trait BaseAccount
13+
{
14+
/**
15+
* @var ObjectRefT<Account>
16+
*/
17+
protected ObjectRefT $account;
18+
}

0 commit comments

Comments
 (0)