Support unused variables on list() + explode() or big array

Product: * Community Edition * Version 9.4 (build 54424), + SonarLint in PHPStorm
Rule: “Remove this unused “$unused” local variable” php:S1481 Sonar Way

A common pattern is to assign the result of explode() to variables directly by using list() (it’s even on the php doc examples for explode)

But sometimes we don’t need one of the beginning parts, so currently in the code I have this line

list($unused, $table, $shard, $disk) = explode('__', $filename);

SonarQube is complaining that I should remove the $unused variable.
To remove it I’d need to replace a clear line with this repetitive block just to ignore the fixed header (and there’s also some example with 9 parts)

$parts = explode('__', $filename);
$table = $parts[1];
$shard = $parts[2];
$disk = $parts[3];
unset($parts);

Hey there.

I’ve moved your post to the category on reporting false-positives.

Can you tell us what product(s) you’re using (SonarCloud, SonarQube, SonarLint), and what version (if relevant)? It’s also helpful if you provide the ID of the rule.

updated