Skip to content

Commit

Permalink
helper?
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Apr 6, 2018
1 parent 4d3ddf9 commit 1550c19
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/CLImate.php
Expand Up @@ -272,6 +272,34 @@ public function description($description)
return $this;
}

/**
* they pass in a total, set the total
*
* @param iterable $data Array or any other iterable object
* @param callable $callback
*/
public function each($data, callable $callback = null)
{
if ($data instanceof \Countable || is_array($data)) {
$total = count($data);
if (!$total) {
return;
}

$progress = $this->progress($total);
} else {
$progress = $this->spinner();
}

foreach ($data as $key => $item) {
if ($callback) {
$callback($item, $key);
}

$progress->advance();
}
}

/**
* Check if we have valid output
*
Expand Down

0 comments on commit 1550c19

Please sign in to comment.