Skip to content

Commit

Permalink
Fix StrictArrayParamDimFetchRector on is_* calls (#4486)
Browse files Browse the repository at this point in the history
* StrictArrayParamDimFetchRector failing test

* Rename string_array_union.php.inc to skip_string_array_union.php.inc

* more failling tests

* fix

* fix

* Update StrictArrayParamDimFetchRector.php
  • Loading branch information
staabm authored Jul 12, 2023
1 parent d78bfb4 commit d4a432e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class SkipIsBool
{
private function getLabelsForIds($ids)
{
if (is_bool($ids)) {
$ids = explode(',', $ids);
}
if (! isset($ids[0])) {
return '';
}

if ('alle' === $ids[0]) {
return $ids[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class SkipIsFloat
{
private function getLabelsForIds($ids)
{
if (is_float($ids)) {
$ids = explode(',', $ids);
}
if (! isset($ids[0])) {
return '';
}

if ('alle' === $ids[0]) {
return $ids[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class SkipIsInt
{
private function getLabelsForIds($ids)
{
if (is_int($ids)) {
$ids = explode(',', $ids);
}
if (! isset($ids[0])) {
return '';
}

if ('alle' === $ids[0]) {
return $ids[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class SkipIsString
{
private function getLabelsForIds($ids)
{
if (is_string($ids)) {
$ids = explode(',', $ids);
}
if (! isset($ids[0])) {
return '';
}

if ('alle' === $ids[0]) {
return $ids[0];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function isParamAccessedArrayDimFetch(Param $param, ClassMethod|Function
$paramName,
&$isParamAccessedArrayDimFetch
): int|null {
if ($node instanceof FuncCall && $this->isName($node, 'is_array')) {
if ($node instanceof FuncCall && $this->isNames($node, ['is_array', 'is_string', 'is_int', 'is_bool', 'is_float'])) {
$firstArg = $node->getArgs()[0];
if ($this->isName($firstArg->value, $paramName)) {
return NodeTraverser::STOP_TRAVERSAL;
Expand Down

0 comments on commit d4a432e

Please sign in to comment.