mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 05:03:31 +00:00
[Strict] Skip ArrayDimFetch on DisallowedEmptyRuleFixerRector (#2023)
* [ISSUE-7100] Added failing test cases for when accessing array key might lead to PHP Notice: Undefined Index * [Strict] Skip ArrayDimFetch on DisallowedEmptyRuleFixerRector Co-authored-by: Jiří Bok <jiri.bok@protonmail.com>
This commit is contained in:
parent
ab8d35ab44
commit
d17990345c
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\Fixture;
|
||||||
|
|
||||||
|
class SkipArgArrayDimFetchFromPropertyFetch {
|
||||||
|
/**
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
protected array $labels = [];
|
||||||
|
|
||||||
|
public function getLabel(string $value): string
|
||||||
|
{
|
||||||
|
if (empty($this->labels[$value])) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('%s is missing label for value "%s"', static::class, $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->labels[$value];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\Fixture;
|
||||||
|
|
||||||
|
class SkipArgArrayDimFetchFromStaticPropertyFetch {
|
||||||
|
/**
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
protected static array $labels = [];
|
||||||
|
|
||||||
|
public static function getLabel(string $value): string
|
||||||
|
{
|
||||||
|
if (empty(static::$labels[$value])) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('%s is missing label for value "%s"', static::class, $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::$labels[$value];
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ namespace Rector\Strict\Rector\Empty_;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
|
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||||
use PhpParser\Node\Expr\BooleanNot;
|
use PhpParser\Node\Expr\BooleanNot;
|
||||||
use PhpParser\Node\Expr\Empty_;
|
use PhpParser\Node\Expr\Empty_;
|
||||||
use PHPStan\Analyser\Scope;
|
use PHPStan\Analyser\Scope;
|
||||||
|
@ -82,6 +83,10 @@ CODE_SAMPLE
|
||||||
return $this->refactorBooleanNot($node, $scope);
|
return $this->refactorBooleanNot($node, $scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($node->expr instanceof ArrayDimFetch) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->refactorEmpty($node, $scope, $this->treatAsNonEmpty);
|
return $this->refactorEmpty($node, $scope, $this->treatAsNonEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user