Skip to content

Commit

Permalink
rewrite match to switch for compatibility's sake
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripudil committed Jun 20, 2023
1 parent ab27d4a commit b82cc17
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,17 @@ private function resolveGenericTypeNode(GenericTypeNode $typeNode, NameScope $na
$mainTypeName = strtolower($typeNode->type->name);
$genericTypes = $this->resolveMultiple($typeNode->genericTypes, $nameScope);
$variances = array_map(
static fn (string $variance): TemplateTypeVariance => match ($variance) {
GenericTypeNode::VARIANCE_INVARIANT => TemplateTypeVariance::createInvariant(),
GenericTypeNode::VARIANCE_COVARIANT => TemplateTypeVariance::createCovariant(),
GenericTypeNode::VARIANCE_CONTRAVARIANT => TemplateTypeVariance::createContravariant(),
GenericTypeNode::VARIANCE_BIVARIANT => TemplateTypeVariance::createBivariant(),
static function (string $variance): TemplateTypeVariance {
switch ($variance) {
case GenericTypeNode::VARIANCE_INVARIANT:
return TemplateTypeVariance::createInvariant();
case GenericTypeNode::VARIANCE_COVARIANT:
return TemplateTypeVariance::createCovariant();
case GenericTypeNode::VARIANCE_CONTRAVARIANT:
return TemplateTypeVariance::createContravariant();
case GenericTypeNode::VARIANCE_BIVARIANT:
return TemplateTypeVariance::createBivariant();
}
},
$typeNode->variances,
);
Expand Down

0 comments on commit b82cc17

Please sign in to comment.