UnsetConstructsCanBeMerged
info on by default quick-fixGroup: Code style · PhpStorm name: UnsetConstructsCanBeMergedInspection
unset() accepts several arguments, so consecutive unset(...) statements can be collapsed into one call.
Example
php
<?php
function release(array $cache, $tmp, $lock) {
unset($cache['k1']);
unset($tmp);
// the lock goes too
/** trailing note */
unset ( $lock );
$tmp = 1;
unset($tmp, $cache);
unset($lock);
if ($tmp) {
unset($cache);
}
unset($tmp);
}php
<?php
function release(array $cache, $tmp, $lock) {
unset($cache['k1'], $tmp, $lock);
// the lock goes too
/** trailing note */
$tmp = 1;
unset($tmp, $cache, $lock);
if ($tmp) {
unset($cache);
}
unset($tmp);
}Reported:
- line 4: Consecutive unset() calls; merge them into one.
- line 7: Consecutive unset() calls; merge them into one.
- line 11: Consecutive unset() calls; merge them into one.
Configure
In custos.json:
json
{
"rules": {
"UnsetConstructsCanBeMerged": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore UnsetConstructsCanBeMerged
/**
* @noinspection UnsetConstructsCanBeMergedInspection
*/