Skip to content
Closed
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
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2328,4 +2328,12 @@ public function testReadOnlyPropertyPassedByReference(): void
]);
}

public function testBug5591(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-5591.php'], []);
}

}
43 changes: 43 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-5591.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Bug5591;

class EntityA {}
class EntityB {}

/**
* @template TEntity as object
*/
class TestClass
{
/** @var class-string<TEntity> The fully-qualified (::class) class name of the entity being managed. */
protected string $entityClass;

/** @param TEntity|null $record */
public function outerMethod(?object $record = null): void
{
$record = $this->innerMethod($record);
}

/**
* @param TEntity|null $record
*
* @return TEntity
*/
public function innerMethod(?object $record = null): object
{
return $record ?? new ($this->entityClass)();
}
}

/**
* @template TEntity as EntityA|EntityB
* @extends TestClass<TEntity>
*/
class TestClass2 extends TestClass
{
public function outerMethod(?object $record = null): void
{
$this->innerMethod($record);
}
}