Skip to content

Commit

Permalink
[TypeDeclaration] Skip array key with null coalescing return mixed on…
Browse files Browse the repository at this point in the history
… ReturnAnnotationIncorrectNullableRector (#2224)

* Add failing test fixture for ReturnAnnotationIncorrectNullableRector

# Failing Test for ReturnAnnotationIncorrectNullableRector

Based on https://getrector.org/demo/4bef38e5-2250-4e0e-8e50-9646d1d776d2

* Closes #2222

* [TypeDeclaration] Skip array key with null coalescing return mixed on ReturnAnnotationIncorrectNullableRector

* [ci-review] Rector Rectify

* clean up

Co-authored-by: Alies Lapatsin <lptn@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people committed May 4, 2022
1 parent 0491402 commit e978256
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnAnnotationIncorrectNullableRector\Fixture;

final class SkipArraykeyWithNullCoalescingReturnMixed
{
/** @param array<string, string|int|null> $information */
public function __construct(private readonly array $information)
{
}

/** @return bool|float|int|string|null */
public function getValue(string $key): mixed
{
return $this->information[$key] ?? null;
}
}

?>
4 changes: 4 additions & 0 deletions rules/TypeDeclaration/Helper/PhpDocNullableTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function resolveUpdatedPhpDocTypeFromPhpDocTypeAndPhpParserType(
Type $phpDocType,
Type $phpParserType
): ?Type {
if ($phpParserType instanceof MixedType) {
return null;
}

return $this->resolveUpdatedPhpDocTypeFromPhpDocTypeAndPhpParserTypeNullInfo(
$phpDocType,
$this->isParserTypeContainingNullType($phpParserType)
Expand Down

0 comments on commit e978256

Please sign in to comment.