Updated Rector to commit a456e4e04c2955b292d490af20f2fada7a1cb087

a456e4e04c [Php80] Mirror comments on assign on ChangeSwitchToMatchRector (#6516)
This commit is contained in:
Tomas Votruba 2024-11-27 07:27:32 +00:00
parent 9e165cccd3
commit 0e60fef0a2
10 changed files with 48 additions and 40 deletions

View File

@ -5,6 +5,7 @@ namespace Rector\Php80\NodeFactory;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\MatchArm;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\ValueObject\CondAndExpr;
final class MatchArmsFactory
{
@ -15,14 +16,13 @@ final class MatchArmsFactory
public function createFromCondAndExprs(array $condAndExprs) : array
{
$matchArms = [];
foreach ($condAndExprs as $condAndExpr) {
foreach ($condAndExprs as $key => $condAndExpr) {
$expr = $condAndExpr->getExpr();
if ($expr instanceof Assign) {
// $this->assignExpr = $expr->var;
$expr = $expr->expr;
}
$condExprs = $condAndExpr->getCondExprs();
$matchArms[] = new MatchArm($condExprs, $expr);
$matchArms[] = new MatchArm($condExprs, $expr, [AttributeKey::COMMENTS => $condAndExprs[$key]->getComments()]);
}
return $matchArms;
}

View File

@ -62,7 +62,7 @@ final class MatchFactory
return null;
}
$shouldRemoteNextStmt = !$expr instanceof Expr;
$condAndExprs[] = new CondAndExpr([], $nextStmt->expr, MatchKind::RETURN);
$condAndExprs[] = new CondAndExpr([], $nextStmt->expr, MatchKind::RETURN, $nextStmt->getComments());
}
}
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);

View File

@ -41,6 +41,7 @@ final class SwitchExprsResolver
continue;
}
$expr = $case->stmts[0];
$comments = $expr->getComments();
if ($expr instanceof Expression) {
$expr = $expr->expr;
}
@ -58,17 +59,17 @@ final class SwitchExprsResolver
$condExprs[] = $case->cond;
}
if ($expr instanceof Throw_) {
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::THROW);
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::THROW, $comments);
} elseif ($expr instanceof Return_) {
$returnedExpr = $expr->expr;
if (!$returnedExpr instanceof Expr) {
return [];
}
$condAndExpr[] = new CondAndExpr($condExprs, $returnedExpr, MatchKind::RETURN);
$condAndExpr[] = new CondAndExpr($condExprs, $returnedExpr, MatchKind::RETURN, $comments);
} elseif ($expr instanceof Assign) {
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::ASSIGN);
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::ASSIGN, $comments);
} elseif ($expr instanceof Expr) {
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::NORMAL);
$condAndExpr[] = new CondAndExpr($condExprs, $expr, MatchKind::NORMAL, $comments);
} else {
return [];
}

View File

@ -109,17 +109,6 @@ CODE_SAMPLE
}
$match = $matchResult->getMatch();
if ($matchResult->shouldRemoveNextStmt() && $isReturn) {
/** @var Return_ $returnStatement */
$returnStatement = $node->stmts[$key + 1];
$returnComment = $returnStatement->getComments();
if ($returnComment !== []) {
foreach ($match->arms as $arm) {
if ($arm->conds === null) {
$this->mirrorComments($arm, $returnStatement);
break;
}
}
}
unset($node->stmts[$key + 1]);
}
$assignVar = $this->resolveAssignVar($condAndExprs);

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Php80\ValueObject;
use PhpParser\Comment;
use PhpParser\Node\Expr;
use Rector\Php80\Enum\MatchKind;
final class CondAndExpr
@ -21,15 +22,22 @@ final class CondAndExpr
* @readonly
*/
private string $matchKind;
/**
* @var Comment[]
* @readonly
*/
private array $comments = [];
/**
* @param Expr[]|null $condExprs
* @param MatchKind::* $matchKind
* @param Comment[] $comments
*/
public function __construct(?array $condExprs, Expr $expr, string $matchKind)
public function __construct(?array $condExprs, Expr $expr, string $matchKind, array $comments = [])
{
$this->condExprs = $condExprs;
$this->expr = $expr;
$this->matchKind = $matchKind;
$this->comments = $comments;
}
public function getExpr() : Expr
{
@ -60,4 +68,11 @@ final class CondAndExpr
{
return $this->matchKind === $matchKind;
}
/**
* @return Comment[]
*/
public function getComments() : array
{
return $this->comments;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'eb3f32daa89b22c32eb57e53f8d6e960ee1f2a7e';
public const PACKAGE_VERSION = 'a456e4e04c2955b292d490af20f2fada7a1cb087';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-11-26 19:01:26';
public const RELEASE_DATE = '2024-11-27 14:25:18';
/**
* @var int
*/

View File

@ -512,17 +512,17 @@
},
{
"name": "illuminate\/container",
"version": "v11.33.2",
"version_normalized": "11.33.2.0",
"version": "v11.34.1",
"version_normalized": "11.34.1.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
"reference": "6e31eb49e9c9e68356a55cd8f18fb8830b8158cd"
"reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/illuminate\/container\/zipball\/6e31eb49e9c9e68356a55cd8f18fb8830b8158cd",
"reference": "6e31eb49e9c9e68356a55cd8f18fb8830b8158cd",
"url": "https:\/\/api.github.com\/repos\/illuminate\/container\/zipball\/b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
"reference": "b057b0bbb38d7c7524df1ca5c38e7318f4c64d26",
"shasum": ""
},
"require": {
@ -533,7 +533,7 @@
"provide": {
"psr\/container-implementation": "1.1|2.0"
},
"time": "2024-11-14T15:31:35+00:00",
"time": "2024-11-21T20:07:31+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -569,17 +569,17 @@
},
{
"name": "illuminate\/contracts",
"version": "v11.33.2",
"version_normalized": "11.33.2.0",
"version": "v11.34.1",
"version_normalized": "11.34.1.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",
"reference": "44c15aec6ea0d997e0885aa5b04876fe8a141433"
"reference": "184317f701ba20ca265e36808ed54b75b115972d"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/illuminate\/contracts\/zipball\/44c15aec6ea0d997e0885aa5b04876fe8a141433",
"reference": "44c15aec6ea0d997e0885aa5b04876fe8a141433",
"url": "https:\/\/api.github.com\/repos\/illuminate\/contracts\/zipball\/184317f701ba20ca265e36808ed54b75b115972d",
"reference": "184317f701ba20ca265e36808ed54b75b115972d",
"shasum": ""
},
"require": {
@ -587,7 +587,7 @@
"psr\/container": "^1.1.1|^2.0.1",
"psr\/simple-cache": "^1.0|^2.0|^3.0"
},
"time": "2024-11-15T15:40:33+00:00",
"time": "2024-11-25T15:33:38+00:00",
"type": "library",
"extra": {
"branch-alias": {

File diff suppressed because one or more lines are too long

View File

@ -550,8 +550,11 @@ class Container implements ArrayAccess, ContainerContract
*/
protected function rebound($abstract)
{
if (!($callbacks = $this->getReboundCallbacks($abstract))) {
return;
}
$instance = $this->make($abstract);
foreach ($this->getReboundCallbacks($abstract) as $callback) {
foreach ($callbacks as $callback) {
$callback($this, $instance);
}
}

View File

@ -7,7 +7,7 @@ class ModelIdentifier
/**
* The class name of the model.
*
* @var string
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
public $class;
/**
@ -33,13 +33,13 @@ class ModelIdentifier
/**
* The class name of the model collection.
*
* @var string|null
* @var class-string<\Illuminate\Database\Eloquent\Collection>|null
*/
public $collectionClass;
/**
* Create a new model identifier.
*
* @param string $class
* @param class-string<\Illuminate\Database\Eloquent\Model> $class
* @param mixed $id
* @param array $relations
* @param mixed $connection
@ -55,7 +55,7 @@ class ModelIdentifier
/**
* Specify the collection class that should be used when serializing / restoring collections.
*
* @param string|null $collectionClass
* @param class-string<\Illuminate\Database\Eloquent\Collection> $collectionClass
* @return $this
*/
public function useCollectionClass(?string $collectionClass)