Skip to content

Commit 97067d8

Browse files
author
Michael Zapf
committed
add method to get first step from flow
1 parent 5b3a745 commit 97067d8

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

spec/Model/MultiStepFlowSpec.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,14 @@ function it_can_not_get_step_after_last(
123123

124124
$this->getStepAfter($stepCurrent)->shouldReturn(null);
125125
}
126+
127+
function it_can_get_first_step(
128+
MultiStepInterface $firstStep
129+
) {
130+
$firstStep->getId()->willReturn('first-step');
131+
$firstStep->getSlug()->willReturn('first-step');
132+
$this->addStep($firstStep);
133+
134+
$this->getFirstStep()->shouldReturn($firstStep);
135+
}
126136
}

src/Model/MultiStepFlow.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ public function addStep(MultiStepInterface $step): void
104104
$this->steps[$step->getId()] = $step;
105105
$this->stepsBySlug[$step->getSlug()] = $step;
106106
}
107+
108+
public function getFirstStep(): MultiStepInterface
109+
{
110+
if (empty($this->steps)) {
111+
throw new StepNotFoundException();
112+
}
113+
reset($this->steps);
114+
return current($this->steps);
115+
}
107116
}

src/Model/MultiStepFlowInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public function getStepAfter(MultiStepInterface $currentStep): ?MultiStepInterfa
3232
public function getStepBefore(MultiStepInterface $currentStep): ?MultiStepInterface;
3333

3434
public function addStep(MultiStepInterface $step): void;
35+
36+
public function getFirstStep(): MultiStepInterface;
3537
}

0 commit comments

Comments
 (0)