Skip to content

Commit 74058c2

Browse files
[DowngradePhp80] Do not change correct union array docblock on DowngradeUnionTypeDeclarationRector (#191)
* [DowngradePhp80] Do not change correct union array docblock on DowngradeUnionTypeDeclarationRector * [ci-review] Rector Rectify * Fixed * Fix --------- Co-authored-by: GitHub Action <[email protected]>
1 parent fa41cc7 commit 74058c2

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
4+
5+
use PhpParser\Node;
6+
7+
final class DoNotChangeCorrectUnionArrayDocblockOnParam2
8+
{
9+
/**
10+
* @param Node|Node[] $node
11+
*/
12+
function execute(Node | array $node): void
13+
{
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Tests\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
22+
23+
use PhpParser\Node;
24+
25+
final class DoNotChangeCorrectUnionArrayDocblockOnParam2
26+
{
27+
/**
28+
* @param Node|Node[] $node
29+
*/
30+
function execute($node): void
31+
{
32+
}
33+
}
34+
35+
?>

rules/DowngradePhp73/Tokenizer/FollowedByNewlineOnlyMaybeWithSemicolonAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public function isFollowed(File $file, Node $node): bool
2121

2222
return ! isset($oldTokens[$nextTokenPosition]) ||
2323
isset($oldTokens[$nextTokenPosition][1]) &&
24-
\str_starts_with((string) $oldTokens[$nextTokenPosition][1], "\n");
24+
\str_starts_with($oldTokens[$nextTokenPosition][1], "\n");
2525
}
2626
}

src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PhpParser\Node\Stmt\Function_;
1515
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
1616
use PHPStan\Reflection\ClassReflection;
17+
use PHPStan\Type\MixedType;
1718
use PHPStan\Type\ObjectType;
1819
use PHPStan\Type\ThisType;
1920
use PHPStan\Type\Type;
@@ -223,11 +224,17 @@ private function moveParamTypeToParamDoc(
223224
Param $param,
224225
Type $type
225226
): void {
227+
$param->type = null;
228+
226229
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
227230
$paramName = $this->nodeNameResolver->getName($param);
228-
$this->phpDocTypeChanger->changeParamType($functionLike, $phpDocInfo, $type, $param, $paramName);
229231

230-
$param->type = null;
232+
$phpDocParamType = $phpDocInfo->getParamType($paramName);
233+
if (! $type instanceof MixedType && $type::class === $phpDocParamType::class) {
234+
return;
235+
}
236+
237+
$this->phpDocTypeChanger->changeParamType($functionLike, $phpDocInfo, $type, $param, $paramName);
231238
}
232239

233240
/**

0 commit comments

Comments
 (0)