Skip to content

Commit

Permalink
Add method getPossibleStates
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Lazarecki committed Dec 23, 2015
1 parent f302ac9 commit 97f8f74
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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();
}

0 comments on commit 97f8f74

Please sign in to comment.