Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions spec/SM/StateMachine/StateMachineSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
17 changes: 17 additions & 0 deletions src/SM/StateMachine/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions src/SM/StateMachine/StateMachineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ public function getGraph();
* @return array
*/
public function getPossibleTransitions();

/**
* Returns the possible states
*
* @return array
*/
public function getPossibleStates();
}