@@ -92,11 +92,7 @@ public function can($subject, $transitionName)
9292 continue ;
9393 }
9494
95- try {
96- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
97- } catch (NotEnabledTransitionException $ e ) {
98- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
99- }
95+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
10096
10197 if ($ transitionBlockerList ->isEmpty ()) {
10298 return true ;
@@ -120,13 +116,18 @@ public function buildTransitionBlockerList($subject, string $transitionName): Tr
120116 continue ;
121117 }
122118
123- try {
124- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
119+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
120+
121+ if ($ transitionBlockerList ->isEmpty ()) {
122+ return $ transitionBlockerList ;
123+ }
125124
125+ // We prefer to return transitions blocker by something else than
126+ // marking. Because it means the marking was OK. Transitions are
127+ // deterministic: it's not possible to have many transitions enabled
128+ // at the same time that match the same marking with the same name
129+ if (!$ transitionBlockerList ->has (TransitionBlocker::BLOCKED_BY_MARKING )) {
126130 return $ transitionBlockerList ;
127- } catch (NotEnabledTransitionException $ e ) {
128- // a transition with the same name is defined for other places too
129- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
130131 }
131132 }
132133
@@ -153,15 +154,11 @@ public function apply($subject, $transitionName)
153154 continue ;
154155 }
155156
156- try {
157- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
158- } catch (NotEnabledTransitionException $ e ) {
159- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
160- }
161-
162- if ($ transitionBlockerList ->isEmpty ()) {
163- $ approvedTransitionQueue [] = $ transition ;
157+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
158+ if (!$ transitionBlockerList ->isEmpty ()) {
159+ continue ;
164160 }
161+ $ approvedTransitionQueue [] = $ transition ;
165162 }
166163
167164 foreach ($ approvedTransitionQueue as $ transition ) {
@@ -202,12 +199,7 @@ public function getEnabledTransitions($subject)
202199 $ marking = $ this ->getMarking ($ subject );
203200
204201 foreach ($ this ->definition ->getTransitions () as $ transition ) {
205- try {
206- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
207- } catch (NotEnabledTransitionException $ e ) {
208- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
209- }
210-
202+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
211203 if ($ transitionBlockerList ->isEmpty ()) {
212204 $ enabledTransitions [] = $ transition ;
213205 }
@@ -252,7 +244,9 @@ private function buildTransitionBlockerListForTransition($subject, Marking $mark
252244 {
253245 foreach ($ transition ->getFroms () as $ place ) {
254246 if (!$ marking ->has ($ place )) {
255- throw new NotEnabledTransitionException ($ subject , $ transition ->getName (), $ this , new TransitionBlockerList (array (TransitionBlocker::createBlockedByMarking ($ marking ))));
247+ return new TransitionBlockerList (array (
248+ TransitionBlocker::createBlockedByMarking ($ marking ),
249+ ));
256250 }
257251 }
258252
0 commit comments