Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method getPossibleStates #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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();
}