diff --git a/spec/SM/StateMachine/StateMachineSpec.php b/spec/SM/StateMachine/StateMachineSpec.php index 451fc2b..20e95a8 100644 --- a/spec/SM/StateMachine/StateMachineSpec.php +++ b/spec/SM/StateMachine/StateMachineSpec.php @@ -159,4 +159,11 @@ function it_returns_possible_transitions($object) $this->getPossibleTransitions()->shouldReturn(array('create', 'confirm')); } + + function it_returns_possible_states($object) + { + $object->getState()->willReturn('checkout'); + + $this->getPossibleStates()->shouldReturn(array('pending', 'confirmed')); + } } diff --git a/src/SM/StateMachine/StateMachine.php b/src/SM/StateMachine/StateMachine.php index 9605d09..b0e3423 100644 --- a/src/SM/StateMachine/StateMachine.php +++ b/src/SM/StateMachine/StateMachine.php @@ -186,6 +186,23 @@ public function getPossibleTransitions() ); } + /** + * Returns the possible states + * + * @return array + */ + public function getPossibleStates() + { + $states = array(); + $transitions = $this->getPossibleTransitions(); + + foreach ($transitions as $transition) { + $states[] = $this->config['transitions'][$transition]['to']; + } + + return $states; + } + /** * Set a new state to the underlying object * diff --git a/src/SM/StateMachine/StateMachineInterface.php b/src/SM/StateMachine/StateMachineInterface.php index b09da5f..429051c 100644 --- a/src/SM/StateMachine/StateMachineInterface.php +++ b/src/SM/StateMachine/StateMachineInterface.php @@ -65,4 +65,11 @@ public function getGraph(); * @return array */ public function getPossibleTransitions(); + + /** + * Returns the possible states + * + * @return array + */ + public function getPossibleStates(); }