IssetConstructsCanBeMerged
info on by default quick-fixGroup: Control flow · PhpStorm name: IssetConstructsCanBeMergedInspection
isset() accepts several arguments and is true only when all of them are set. A chain such as isset($p) && isset($q) is therefore the same as isset($p, $q), and !isset($p) || !isset($q) the same as !isset($p, $q). Merging keeps conditions short.
Example
php
<?php
function probe(array $cfg, $row, $extra) {
$r1 = isset($cfg['host']) && isset($cfg['port']);
$r2 = isset($row->id, $row->name) && isset($extra);
$r3 = $extra > 2 && isset($cfg['a']) && (isset($cfg['b']) && isset($cfg['c']));
$r4 = isset($cfg['x']) && isset($cfg['y']) && ($extra || $row);
$r5 = !isset($row->id) || !isset($row->name) || $extra;
$n1 = isset($cfg['host']) && !isset($cfg['port']);
$n2 = isset($cfg['host']) || isset($cfg['port']);
$n3 = !isset($cfg['host']) && !isset($cfg['port']);
$n4 = isset($cfg['host']) and isset($cfg['port']);
return [$r1, $r2, $r3, $r4, $r5, $n1, $n2, $n3, $n4];
}php
<?php
function probe(array $cfg, $row, $extra) {
$r1 = isset($cfg['host'], $cfg['port']);
$r2 = isset($row->id, $row->name, $extra);
$r3 = $extra > 2 && isset($cfg['a'], $cfg['b']) && isset($cfg['c']);
$r4 = isset($cfg['x'], $cfg['y']) && ($extra || $row);
$r5 = !isset($row->id, $row->name) || $extra;
$n1 = isset($cfg['host']) && !isset($cfg['port']);
$n2 = isset($cfg['host']) || isset($cfg['port']);
$n3 = !isset($cfg['host']) && !isset($cfg['port']);
$n4 = isset($cfg['host']) and isset($cfg['port']);
return [$r1, $r2, $r3, $r4, $r5, $n1, $n2, $n3, $n4];
}Reported:
- line 3: Merge this check into the preceding isset() call.
- line 4: Merge this check into the preceding isset() call.
- line 5: Merge this check into the preceding isset() call.
- line 6: Merge this check into the preceding isset() call.
- line 7: Merge this check into the preceding !isset() call.
Configure
In custos.json:
json
{
"rules": {
"IssetConstructsCanBeMerged": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore IssetConstructsCanBeMerged
/**
* @noinspection IssetConstructsCanBeMergedInspection
*/