Is it possible to collapse custom code in PhpStorm? Like if you set in settings pattern:
[START]$this->debugOutput(*)[END]
The concept is to hide debug code after developing finished.
In example below all lines with $this->debugOutput
should be hidden
class Foo {
public function bar()
{
$x = 1 + 2;
$this->debugOutput($x);
$y = 3 + 3;
$z = 5 + 5;
$this->debugOutput($y);
$this->debugOutput($z);
}
public function debugOutput($msg, $dump = false)
{
if($this->config->debug !== true){
return;
}
@ob_end_flush();
@ob_flush();
@flush();
@ob_start();
if($dump){
var_dump($msg);
} else {
echo $msg . PHP_EOL;
}
}
}
There is no way to have such code collapsed automatically via settings/matching pattern.
But you can surround such code with custom folding blocks -- the folding state will be remembered when opening next time and if opened first time it also will be collapsed (thanks to
defaultstate="collapsed"
part).Other than that: only by manually folding selection (e.g. make selection and then
Code | Folding | Fold Selection / Remove region
) -- but I'm not sure if it will survive until next session (IDE restart) since there will be no folding comments added.