mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 07:52:01 +02:00
[Solid] Skip ChangeReadOnlyVariableWithDefaultValueToConstantRector on byRef parameter (#4964)
* [Solid] Fixes #4959 skip ChangeReadOnlyVariableWithDefaultValueToConstantRector on byRef parameter * better check * [ci-review] Rector Rectify Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
parent
c11a506b2b
commit
2b001a542e
@ -137,10 +137,13 @@ CODE_SAMPLE
|
||||
$readOnlyVariables = [];
|
||||
|
||||
foreach ($class->getMethods() as $classMethod) {
|
||||
if ($this->isFoundByRefParam($classMethod)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$readOnlyVariableAssignScalarVariables = $this->classMethodAssignManipulator->collectReadyOnlyAssignScalarVariables(
|
||||
$classMethod
|
||||
);
|
||||
|
||||
$readOnlyVariables = array_merge($readOnlyVariables, $readOnlyVariableAssignScalarVariables);
|
||||
}
|
||||
|
||||
@ -202,6 +205,18 @@ CODE_SAMPLE
|
||||
}
|
||||
}
|
||||
|
||||
private function isFoundByRefParam(ClassMethod $classMethod): bool
|
||||
{
|
||||
$params = $classMethod->getParams();
|
||||
foreach ($params as $param) {
|
||||
if ($param->byRef) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function createPrivateClassConst(Variable $variable, Expr $expr): ClassConst
|
||||
{
|
||||
$constantName = $this->createConstantNameFromVariable($variable);
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector\Fixture;
|
||||
|
||||
class SkipByRefParam
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$toInsert = [];
|
||||
$this->byRef($toInsert);
|
||||
}
|
||||
|
||||
public function byRef(array & $data)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user