private function getTransitionDestinationById(string
$stateMachineName, string
$fromStateId, string
$transitionName, Context
$context): StateMachineStateEntity
{ $stateMachine =
$this->
getStateMachine($stateMachineName,
$context);
/** @var StateMachineTransitionCollection $stateMachineTransitions */
$stateMachineTransitions =
$stateMachine->
getTransitions();
foreach ($stateMachineTransitions as $transition) { /** @var StateMachineStateEntity $toState */
$toState =
$transition->
getToStateMachineState();
// Always allow to cancel a payment whether its a valid transition or not
if ($transition->
getActionName() === 'cancel' &&
$transitionName === 'cancel'
) { return $toState;
} // Not the transition that was requested step over
if ($transition->
getActionName() !==
$transitionName) { continue;
} // Already transitioned, this exception is handled by StateMachineRegistry::transition