From 7725d48ce2289e8efa5b05244a8f43bd99ddf1c1 Mon Sep 17 00:00:00 2001 From: izzyp Date: Mon, 27 Feb 2017 15:36:29 +0000 Subject: [PATCH 1/4] refactor Workflow.php getEnabledTransitions() method only requires 1 parameter "$subject". Removed instances where a second $this->getMarking($subject) is being passed to getEnabledTransitions(). --- src/Symfony/Component/Workflow/Workflow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 2f98203470183..111d80ebaf5e9 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -92,7 +92,7 @@ public function getMarking($subject) */ public function can($subject, $transitionName) { - $transitions = $this->getEnabledTransitions($subject, $this->getMarking($subject)); + $transitions = $this->getEnabledTransitions($subject); foreach ($transitions as $transition) { if ($transitionName === $transition->getName()) { @@ -116,7 +116,7 @@ public function can($subject, $transitionName) */ public function apply($subject, $transitionName) { - $transitions = $this->getEnabledTransitions($subject, $this->getMarking($subject)); + $transitions = $this->getEnabledTransitions($subject); // We can shortcut the getMarking method in order to boost performance, // since the "getEnabledTransitions" method already checks the Marking From f10fe023f1f93906eb04a9bf285293f325e40f15 Mon Sep 17 00:00:00 2001 From: izzyp Date: Mon, 27 Feb 2017 18:31:46 +0000 Subject: [PATCH 2/4] refactor setMarking() inside getMarking() MarkingStore->setMarking() is being called on every call to getMarking() in the Workflow class. This is only required if a new Marking is initialised and set as per line 63: `$marking->mark($this->definition->getInitialPlace());` If the Marking is not new, the subject either already has a marking and we don't need to call setMarking(), or it is new && theres no `initial place`. In that case an Exception is thrown on line 61. --- src/Symfony/Component/Workflow/Workflow.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 111d80ebaf5e9..700ad36c81917 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -61,6 +61,9 @@ public function getMarking($subject) throw new LogicException(sprintf('The Marking is empty and there is no initial place for workflow "%s".', $this->name)); } $marking->mark($this->definition->getInitialPlace()); + + // Because the marking could have been initialized, we update the subject + $this->markingStore->setMarking($subject, $marking); } // check that the subject has a known place @@ -76,9 +79,6 @@ public function getMarking($subject) } } - // Because the marking could have been initialized, we update the subject - $this->markingStore->setMarking($subject, $marking); - return $marking; } From 3ae6840073154a43ccd1e30743019599863aa120 Mon Sep 17 00:00:00 2001 From: izzyp Date: Mon, 27 Feb 2017 20:57:57 +0000 Subject: [PATCH 3/4] Apply coding standards. Comply with Coding Standard. --- src/Symfony/Component/Workflow/Workflow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 700ad36c81917..abb70b5f73f7f 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -61,7 +61,7 @@ public function getMarking($subject) throw new LogicException(sprintf('The Marking is empty and there is no initial place for workflow "%s".', $this->name)); } $marking->mark($this->definition->getInitialPlace()); - + // Because the marking could have been initialized, we update the subject $this->markingStore->setMarking($subject, $marking); } From 7edad793c0343873063913abc9286341a6289c49 Mon Sep 17 00:00:00 2001 From: izzyp Date: Mon, 27 Feb 2017 22:18:48 +0000 Subject: [PATCH 4/4] Update comment to reflect the changes in context --- src/Symfony/Component/Workflow/Workflow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index abb70b5f73f7f..cadd610ba480a 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -62,7 +62,7 @@ public function getMarking($subject) } $marking->mark($this->definition->getInitialPlace()); - // Because the marking could have been initialized, we update the subject + // update the subject with the new marking $this->markingStore->setMarking($subject, $marking); }