Skip step
Closed this issue · 3 comments
ycs77 commented
Skip step
veganista commented
I have a similar library to yours and implemented step skipping by introducing a skip() method on the step that would return true or false depending on whether the step should be skipped.
I've added a skip() method to your abstract Step class and updated your prev() and get() methods in StepRepository to:
public function prev()
{
$index = $this
->steps
->reject
->skip()
->search(function($step, $index) {
return $index < $this->currentIndex;
});
if ($index === false) {
return $this->get($this->currentIndex - 1);
}
return $this->get($index);
// return $this->get($this->currentIndex - 1);
}
public function next()
{
$index = $this
->steps
->reject
->skip()
->search(function($step, $index) {
return $index > $this->currentIndex;
});
if ($index === false) {
return $this->get($this->currentIndex + 1);
}
return $this->get($index);
// return $this->currentIndex + 1;
}
This seems to work with skipping steps. I'll try and put some more time into this if you would like to test and tidy it up.
Just thought I'd share what I'd done previously.
ycs77 commented
@veganista Thank you for your suggestions, I will use as a reference.