Skip to content

Commit

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

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

* fix

* [ci-review] Rector Rectify

---------

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

// not inside function with direct check on purpose

if ($cdate) {
$where[] = 'n.sometable <= 1000';
}

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

$sql = 'SELECT something, something FROM table1' . $where;
8 changes: 7 additions & 1 deletion rules/Php71/Rector/Assign/AssignArrayToStringRector.php
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Php71\Rector\Assign;

use PHPStan\Type\UnionType;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
Expand Down Expand Up @@ -245,7 +246,12 @@ private function refactorAssign(
return null;
}

if ($this->nodeTypeResolver->getNativeType($assign->var)->isArray()->yes()) {
$type = $this->nodeTypeResolver->getNativeType($assign->var);
if ($type->isArray()->yes()) {
return null;
}

if ($type instanceof UnionType) {
return null;
}

Expand Down

0 comments on commit 3ef3e35

Please sign in to comment.