Skip to content

Commit

Permalink
[Php71] Skip re-assign as string on AssignArrayToStringRector (#5659)
Browse files Browse the repository at this point in the history
* [Php71] Skip re-assign as string on AssignArrayToStringRector

* fixture

* [ci-review] Rector Rectify

* [Php71] Skip re-assign as string on AssignArrayToStringRector

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Feb 23, 2024
1 parent f5a45a5 commit d754bec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\Php71\Rector\Assign\AssignArrayToStringRector\Fixture;

final class SkipReAssignedAsString
{
public function fun($cdate)
{
if ($cdate) {
$where[] = 'n.sometable <= 1000';
}

if (empty($where)) {
$where = '';
} else {
$where = 'WHERE ' . implode(' AND ', $where);
}

$sql = 'SELECT something, something FROM table1' . $where;
}
}
6 changes: 5 additions & 1 deletion rules/Php71/Rector/Assign/AssignArrayToStringRector.php
Expand Up @@ -237,11 +237,15 @@ private function refactorAssign(
Assign $assign,
Namespace_|FileWithoutNamespace|ClassMethod|Function_|Closure $node
): ?Assign {
if (! $assign->var instanceof Variable) {
return null;
}

if (! $this->isEmptyString($assign->expr)) {
return null;
}

if (! $assign->var instanceof Variable) {
if ($this->nodeTypeResolver->getNativeType($assign->var)->isArray()->yes()) {
return null;
}

Expand Down

0 comments on commit d754bec

Please sign in to comment.