Quite related to #621 , using the progress bar in the Symfony framework results in the warning "This statement seems to be disconnected from its parent foreach."
(Dummy) Example:
$progressBar = new ProgressBar($output);
$progressBar->start();
foreach ($rows as $row) {
$this->addRowToCSV($row);
$progressBar->advance(); // Inspection warning here
}
$progressBar->finish();
Thank you for reporting @excentrik. Unfortunately, I don't a solution for this case, so a suppression is recommended here.
In cases like that, if you prefer avoid warning supressions, you could refactor your looping and give more meaning to what happen.
public function start() {
$progressBar = new ProgressBar($output);
$progressBar->start();
foreach ($rows as $row) {
$this->advanceWithRow($progressBar, $row);
}
$progressBar->finish();
}
private function advanceWithRow(ProgressBar $progressBar, $row) {
$this->addRowToCSV($row);
$progressBar->advance();
}
Or introducing a link to the loop scope:
foreach ($rows as $index => $row) {
$this->addRowToCSV($row);
$progressBar->setProgress($index);
}
Most helpful comment
Or introducing a link to the loop scope: