BpNode: unique operator validation

This commit is contained in:
Thomas Gelf 2015-03-03 11:05:28 +01:00
parent 19ab1a28cc
commit 7d31250816

View file

@ -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