Add assertArrayHasKey() call for array access with string key, that was not validated before
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
$data = $this->getData();
+ $this->assertArrayHasKey('key', $data);
$this->assertSame('result', $data['key']);
}
private function getData(): array
{
// return various data
return [];
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\AddKeysExistsAssertForKeyUseRector;
return RectorConfig::configure()
->withRules([
AddKeysExistsAssertForKeyUseRector::class,
]);