Skip to content

Commit

Permalink
[TypeDeclaration] Skip mixing native + docblock union assign on Typed…
Browse files Browse the repository at this point in the history
…PropertyFromAssignsRector (#4905)

* [TypeDeclaration] Skip mixing native + docblock union assign on TypedPropertyFromAssignsRector

* Fixed 🎉

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Sep 4, 2023
1 parent fcf0bc4 commit 824bb97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture;

use DateTime;
use stdClass;

final class SkipNativeWithDocblockUnion
{
private $property;

public function run1()
{
$this->property = new stdClass;
}

/**
* @param stdClass|DateTime $property
*/
public function run2($property)
{
$this->property = $property;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ private function getAssignedExprTypes(ClassLike $classLike, string $propertyName
}

if ($this->exprAnalyzer->isNonTypedFromParam($node->expr)) {
return null;
$assignedExprTypes = [];
return NodeTraverser::STOP_TRAVERSAL;
}

$assignedExprTypes[] = $this->resolveExprStaticTypeIncludingDimFetch($node);
Expand Down

0 comments on commit 824bb97

Please sign in to comment.