ArgumentUnpackingCanBeUsed
warning on by default quick-fix PHP ≥ 5.6Group: Language level migration · PhpStorm name: ArgumentUnpackingCanBeUsedInspection
Since PHP 5.6, call_user_func_array('fn', $args) with a literal function name can be written as a direct call with argument unpacking, fn(...$args), which is faster and easier to read and analyse.
Example
php
<?php
class Report {
public function build(array $cols) {
$a = call_user_func_array('sprintf', $cols);
$b = \call_user_func_array("max", $this->totals);
$c = call_user_func_array('min', [3, 9]);
$d = call_user_func_array('\\Lib\\fmt', self::defaults());
$e = call_user_func_array([$this, 'render'], $cols);
$f = call_user_func_array("{$this->kind}_fmt", $cols);
$g = call_user_func_array('sprintf', $cols['main']);
$h = call_user_func_array('sprintf');
}
}php
<?php
class Report {
public function build(array $cols) {
$a = sprintf(...$cols);
$b = max(...$this->totals);
$c = min(...[3, 9]);
$d = \Lib\fmt(...self::defaults());
$e = call_user_func_array([$this, 'render'], $cols);
$f = call_user_func_array("{$this->kind}_fmt", $cols);
$g = call_user_func_array('sprintf', $cols['main']);
$h = call_user_func_array('sprintf');
}
}Reported:
- line 4: Call 'sprintf(...$cols)' directly using argument unpacking (wrap with array_values() when keys are not sequential).
- line 5: Call 'max(...$this->totals)' directly using argument unpacking (wrap with array_values() when keys are not sequential).
- line 6: Call 'min(...[3, 9])' directly using argument unpacking (wrap with array_values() when keys are not sequential).
- line 7: Call '\Lib\fmt(...self::defaults())' directly using argument unpacking (wrap with array_values() when keys are not sequential).
Configure
In custos.json:
json
{
"rules": {
"ArgumentUnpackingCanBeUsed": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore ArgumentUnpackingCanBeUsed
/**
* @noinspection ArgumentUnpackingCanBeUsedInspection
*/