Skip to content

Commit e2e95af

Browse files
committed
Enhance TemplateManager with improved variance handling and add type annotations for clarity
1 parent 549f5e9 commit e2e95af

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/Resolver/TemplateManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ private static function bindSingleTemplateArgument(
360360
$usageVariance = $typeNode->variances[$index] ?? GenericTypeNode::VARIANCE_INVARIANT;
361361
$declaredVariance = $classVariances[$templateTag->name] ?? GenericTypeNode::VARIANCE_INVARIANT;
362362

363+
// Return values are naturally in a covariant position under Liskov Substitution Principle
363364
$isReturnContext = str_contains($context, 'Return value');
364365

365366
$variance = ($usageVariance !== GenericTypeNode::VARIANCE_INVARIANT)
@@ -799,7 +800,9 @@ private static function resolveTypeNodeAst(TypeNode $n, \ReflectionClass $ref):
799800
*/
800801
private static function getPhpDocParserComponents(): array
801802
{
803+
/** @var PhpDocParser|null $phpDocParser */
802804
static $phpDocParser = null;
805+
/** @var Lexer|null $lexer */
803806
static $lexer = null;
804807

805808
if ($phpDocParser === null || $lexer === null) {
@@ -820,7 +823,9 @@ private static function getPhpDocParserComponents(): array
820823
*/
821824
private static function getTypeParserComponents(): array
822825
{
826+
/** @var TypeParser|null $typeParser */
823827
static $typeParser = null;
828+
/** @var Lexer|null $lexer */
824829
static $lexer = null;
825830

826831
if ($typeParser === null || $lexer === null) {
@@ -832,4 +837,4 @@ private static function getTypeParserComponents(): array
832837

833838
return [$typeParser, $lexer];
834839
}
835-
}
840+
}

0 commit comments

Comments
 (0)