From 7d31250816c5ab4271deb117b10be29e871a709d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 3 Mar 2015 11:05:28 +0100 Subject: [PATCH] BpNode: unique operator validation --- library/Businessprocess/BpNode.php | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index 0aeb0de..ccb3b19 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -29,7 +29,7 @@ class BpNode extends Node ) { $this->bp = $bp; $this->name = $object->name; - $this->operator = $object->operator; + $this->setOperator($object->operator); $this->setChildNames($object->child_names); } @@ -72,6 +72,31 @@ class BpNode extends Node return $this->operator; } + public function setOperator($operator) + { + $this->assertValidOperator($operator); + $this->operator = $operator; + return $this; + } + + protected function assertValidOperator($operator) + { + switch ($operator) { + case self::OP_AND: + case self::OP_OR: + return; + default: + if (is_numeric($operator)) { + return; + } + } + + throw new ConfigurationError( + 'Got invalid operator: %s', + $operator + ); + } + public function setInfoUrl($url) { $this->url = $url; @@ -142,12 +167,6 @@ class BpNode extends Node break; default: // MIN: - if (! is_numeric($this->operator)) { - throw new ConfigurationError( - 'Got invalid operator: %s', - $this->operator - ); - } sort($sort_states); // default -> unknown