Skip to content
Commits on Source (19)
......@@ -7,14 +7,16 @@
* Time: 13:51
* @author Thomas Joußen <tjoussen@databay.de>
*/
class CompositeBuilderTest extends PHPUnit_Framework_TestCase {
class CompositeBuilderTest extends PHPUnit_Framework_TestCase
{
/**
* @var CompositeBuilder
*/
protected $builder;
public function setUp(){
public function setUp()
{
include_once __DIR__ . '/../classes/CompositeBuilder.php';
$this->builder = new CompositeBuilder;
}
......
......@@ -9,8 +9,8 @@ include_once __DIR__ . '/../classes/ConditionParser.php';
* Time: 11:05
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ConditionParserProxy extends ConditionParser{
class ConditionParserProxy extends ConditionParser
{
public function fetchExpressions()
{
parent::fetchExpressions(); // TODO: Change the autogenerated stub
......@@ -59,5 +59,4 @@ class ConditionParserProxy extends ConditionParser{
{
return $this->operators;
}
}
......@@ -8,8 +8,8 @@
* Time: 16:08
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ConditionParserTest extends \PHPUnit_Framework_TestCase {
class ConditionParserTest extends \PHPUnit_Framework_TestCase
{
protected $key_constraint;
protected $type_constraint;
protected $array_constraint;
......@@ -24,7 +24,8 @@ class ConditionParserTest extends \PHPUnit_Framework_TestCase {
protected static $EXPECTED_OPERATORS = array("=","&","<=","|",">=");
protected static $CANNONICALIZED_CONDITION = "n o n o (n o n o n o n)";
public function setUp(){
public function setUp()
{
include_once 'ConditionParserProxy.php';
include_once __DIR__ . '/../classes/AbstractComposite.php';
$this->parser = new ConditionParserProxy();
......@@ -138,19 +139,15 @@ class ConditionParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals("n o n o !(n o n) o !(n o n)", $this->parser->getCondition());
}
private function recursiveNodeTest($nodes){
foreach($nodes as $key => $node)
{
if(!is_array($node))
private function recursiveNodeTest($nodes)
{
foreach ($nodes as $key => $node) {
if (!is_array($node)) {
$this->assertThat($key, $this->key_constraint);
if($key == "type")
{
if ($key == "type") {
$this->assertThat($node, $this->type_constraint);
}
}
else
{
} else {
$this->assertThat($key, $this->array_constraint);
$this->recursiveNodeTest($node);
}
......
......@@ -7,9 +7,8 @@
* Time: 15:51
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ExpressionTest extends PHPUnit_Framework_TestCase {
class ExpressionTest extends PHPUnit_Framework_TestCase
{
public function test_AnswerOfQuestionExpression()
{
include_once __DIR__ . '/../../classes/Expressions/AnswerOfQuestionExpression.php';
......
......@@ -7,7 +7,8 @@
* Time: 12:30
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase {
class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase
{
/**
* @var ReflectionClass
......@@ -24,7 +25,8 @@ class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase {
*/
protected $expected_pattern = '/%[0-9\.]+%|#-?[0-9\.]+#|\+[0-9]+\+|(Q\d+)(?=\=|<|>|\s|$)|Q[0-9]+\[[0-9]+\]|~.*?~|;[0-9]+:[0-9]+;|\$[0-9]+(?:,[0-9]+)*\$|\*[0-9]+(?:,[0-9]+)*\*/';
public function setUp(){
public function setUp()
{
include_once __DIR__ . '/../../classes/Factory/ExpressionManufacturer.php';
$this->reflection = new ReflectionClass("ExpressionManufacturer");
......@@ -61,8 +63,7 @@ class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase {
$subject = 'Q5 Q66 Q52[92] ~Hallo_Welt~ #5# +32+ %098% $3,4,5$ ;2:6;';
$matches = $this->manufacturer->match($subject);
$tokens = \explode(" ", $subject);
foreach($tokens as $token)
{
foreach ($tokens as $token) {
$this->assertContains($token, $matches);
}
}
......@@ -80,8 +81,7 @@ class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase {
"$2,3,4,5$" => "OrderingResultExpression"
);
foreach($expressions as $key => $expression)
{
foreach ($expressions as $key => $expression) {
include_once __DIR__ . "/../../classes/Expressions/" . $expression . ".php";
$expression_object = $this->manufacturer->manufacture($key);
$this->assertInstanceOf($expression, $expression_object);
......
......@@ -7,7 +7,8 @@
* Time: 12:30
* @author Thomas Joußen <tjoussen@databay.de>
*/
class OperationManufacturerTest extends PHPUnit_Framework_TestCase {
class OperationManufacturerTest extends PHPUnit_Framework_TestCase
{
/**
* @var ReflectionClass
......@@ -24,7 +25,8 @@ class OperationManufacturerTest extends PHPUnit_Framework_TestCase {
*/
protected $expected_pattern = '/[&\|<>=]+/';
public function setUp(){
public function setUp()
{
include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php';
$this->reflection = new ReflectionClass("OperationManufacturer");
......@@ -61,8 +63,7 @@ class OperationManufacturerTest extends PHPUnit_Framework_TestCase {
$subject = '< = > & | <> <= >=';
$matches = $this->manufacturer->match($subject);
$tokens = \explode(" ", $subject);
foreach($tokens as $token)
{
foreach ($tokens as $token) {
$this->assertContains($token, $matches);
}
}
......@@ -80,8 +81,7 @@ class OperationManufacturerTest extends PHPUnit_Framework_TestCase {
"|" => "OrOperation"
);
foreach($operations as $key => $operation)
{
foreach ($operations as $key => $operation) {
include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php";
$operation_object = $this->manufacturer->manufacture($key);
$this->assertInstanceOf($operation, $operation_object);
......
......@@ -9,7 +9,8 @@ include_once 'CompositeInterface.php';
* Time: 10:05
* @author Thomas Joußen <tjoussen@databay.de>
*/
abstract class AbstractComposite implements CompositeInterface {
abstract class AbstractComposite implements CompositeInterface
{
/**
* @var AbstractComposite[]
......@@ -33,11 +34,14 @@ abstract class AbstractComposite implements CompositeInterface {
public function describe()
{
$description = "";
if(is_array($this->nodes))
{
if(\count($this->nodes) > 0) $description .= "(" . $this->nodes[0]->describe();
if (is_array($this->nodes)) {
if (\count($this->nodes) > 0) {
$description .= "(" . $this->nodes[0]->describe();
}
$description .= $this->getDescription();
if(\count($this->nodes) > 0) $description .= $this->nodes[1]->describe() . ") ";
if (\count($this->nodes) > 0) {
$description .= $this->nodes[1]->describe() . ") ";
}
}
return $description;
}
......
......@@ -7,7 +7,8 @@
* Time: 12:18
* @author Thomas Joußen <tjoussen@databay.de>
*/
class CompositeBuilder {
class CompositeBuilder
{
/**
* This array defines the weights and direction of operators.<br />
......@@ -33,33 +34,26 @@ class CompositeBuilder {
*/
public function create($nodes)
{
if($nodes['type'] == 'group')
{
foreach($nodes['nodes'] as $key => $child)
{
if ($nodes['type'] == 'group') {
foreach ($nodes['nodes'] as $key => $child) {
$nodes['nodes'][$key] = $this->create($child);
}
$counted_nodes = 0;
if(is_array($nodes['nodes']))
{
if (is_array($nodes['nodes'])) {
$counted_nodes = count($nodes['nodes']);
}
foreach($this->operators as $next_operator)
{
foreach ($this->operators as $next_operator) {
do {
$index = -1;
for($i = 0; $i < $counted_nodes; $i++)
{
if(!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator)
{
for ($i = 0; $i < $counted_nodes; $i++) {
if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) {
$index = $i;
break;
}
}
if($index >= 0)
{
if ($index >= 0) {
$operation_manufacture = OperationManufacturer::_getInstance();
$operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
......@@ -92,8 +86,7 @@ class CompositeBuilder {
$manufacturer = ExpressionManufacturer::_getInstance();
$expression = $node['nodes'][$index];
if(!($expression instanceof AbstractComposite))
{
if (!($expression instanceof AbstractComposite)) {
$expression = $manufacturer->manufacture($node['nodes'][$index]['value']);
}
return $expression;
......
......@@ -7,7 +7,8 @@
* Time: 13:27
* @author Thomas Joußen <tjoussen@databay.de>
*/
class CompositeEvaluator {
class CompositeEvaluator
{
/**
* @var ilParserQuestionProvider
......@@ -36,8 +37,7 @@ class CompositeEvaluator {
*/
public function evaluate(AbstractComposite $composite)
{
if(is_array($composite->nodes) && count($composite->nodes) > 0)
{
if (is_array($composite->nodes) && count($composite->nodes) > 0) {
$composite->nodes[0] = $this->evaluate($composite->nodes[0]);
$composite->nodes[1] = $this->evaluate($composite->nodes[1]);
$composite = $this->evaluateSubTree($composite);
......@@ -63,8 +63,7 @@ class CompositeEvaluator {
$solutions = $question->getUserQuestionResult($this->session->getActiveId(), $this->session->getPass());
if($question instanceof assClozeTest)
{
if ($question instanceof assClozeTest) {
// @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
/**
* @var $gap assClozeGap
......@@ -73,29 +72,22 @@ class CompositeEvaluator {
$result = $solutions->getSolutionForKey($index);
$gap = $question->getAvailableAnswerOptions($index - 1);
if($rightNode instanceof StringResultExpression)
{
if($gap->getType() == 1)
{
if ($rightNode instanceof StringResultExpression) {
if ($gap->getType() == 1) {
$answer = $gap->getItem($result['value'] - 1);
$solutions->removeByKey($index);
$solutions->addKeyValue($index, $answer->getAnswertext());
}
}
else if(
} elseif (
$rightNode instanceof PercentageResultExpression &&
$composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression)
{
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php';
$composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression) {
/**
* @var $answers assAnswerCloze[]
*/
$answers = $gap->getItems(new ilArrayElementShuffler());
$max_points = 0;
foreach($answers as $answer)
{
if($max_points < $answer->getPoints())
{
foreach ($answers as $answer) {
if ($max_points < $answer->getPoints()) {
$max_points = $answer->getPoints();
}
}
......@@ -103,29 +95,29 @@ class CompositeEvaluator {
$item = null;
$reached_points = null;
// @todo for Thomas J.: Maybe handle identical scoring for every type
switch($gap->getType())
{
switch ($gap->getType()) {
case CLOZE_TEXT:
for($order = 0; $order < $gap->getItemCount(); $order++)
{
for ($order = 0; $order < $gap->getItemCount(); $order++) {
$answer = $gap->getItem($order);
$item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
if($item_points > $reached_points) $reached_points = $item_points;
if ($item_points > $reached_points) {
$reached_points = $item_points;
}
}
break;
case CLOZE_NUMERIC:
for($order = 0; $order < $gap->getItemCount(); $order++)
{
for ($order = 0; $order < $gap->getItemCount(); $order++) {
$answer = $gap->getItem($order);
$item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
if($item_points > $reached_points) $reached_points = $item_points;
if ($item_points > $reached_points) {
$reached_points = $item_points;
}
}
break;
case CLOZE_SELECT:
if($result['value'] != null)
{
if ($result['value'] != null) {
$answer = $gap->getItem($result['value'] - 1);
$reached_points = $answer->getPoints();
}
......@@ -133,8 +125,7 @@ class CompositeEvaluator {
}
$percentage = 0;
if($max_points != 0 && $reached_points !== null)
{
if ($max_points != 0 && $reached_points !== null) {
$percentage = (int) (($reached_points / $max_points) * 100);
}
$solutions->setReachedPercentage($percentage);
......@@ -145,16 +136,14 @@ class CompositeEvaluator {
$question instanceof assFormulaQuestion &&
$rightNode instanceof PercentageResultExpression &&
$composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression
)
{
) {
// @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
$result = $solutions->getSolutionForKey($index);
$answer = $question->getAvailableAnswerOptions($index - 1);
$unit = $solutions->getSolutionForKey($index . "_unit");
$key = null;
if(is_array($unit))
{
if (is_array($unit)) {
$key = $unit['value'];
}
......@@ -162,19 +151,15 @@ class CompositeEvaluator {
$points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
$percentage = 0;
if($max_points != 0)
{
if ($max_points != 0) {
$percentage = (int) (($points / $max_points) * 100);
}
$solutions->setReachedPercentage($percentage);
}
$result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
}
else
{
switch($composite->getPattern())
{
} else {
switch ($composite->getPattern()) {
case "&":
$result = $composite->nodes[0] && $composite->nodes[1];
break;
......@@ -186,11 +171,9 @@ class CompositeEvaluator {
}
}
if($composite->isNegated())
{
if ($composite->isNegated()) {
return !$result;
}
return $result;
}
}
......@@ -7,7 +7,8 @@
* @author Thomas Joußen <tjoussen@databay.de>
*/
interface CompositeInterface {
interface CompositeInterface
{
/**
* Adds an CompositeInterface object to the node array which represents the condition tree structure
......
......@@ -53,8 +53,7 @@ class CompositeValidator
public function validate(AbstractComposite $composite)
{
if(is_array($composite->nodes) && count($composite->nodes) > 0)
{
if (is_array($composite->nodes) && count($composite->nodes) > 0) {
$this->validate($composite->nodes[0]);
$this->validate($composite->nodes[1]);
$this->validateSubTree($composite);
......@@ -77,13 +76,11 @@ class CompositeValidator
$this->checkQuestionExists($question, $question_index);
$this->checkQuestionIsReachable($question, $question_index);
if($this->isResultOfAnswerExpression($question_expression))
{
if ($this->isResultOfAnswerExpression($question_expression)) {
$answer_index = $question_expression->getAnswerIndex() - 1;
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index);
}
if($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest))
{
if ($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest)) {
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue() - 1);
}
......@@ -92,47 +89,37 @@ class CompositeValidator
if ($answer_expression instanceof OrderingResultExpression &&
($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion)
)
{
foreach($answer_expression->getOrdering() as $order)
{
) {
foreach ($answer_expression->getOrdering() as $order) {
$count = 0;
foreach($answer_expression->getOrdering() as $element)
{
if($element == $order)
{
foreach ($answer_expression->getOrdering() as $element) {
if ($element == $order) {
$count++;
}
}
if($count > 1)
{
if ($count > 1) {
throw new DuplicateElement($order);
}
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order - 1);
}
}
if($question instanceof assClozeTest)
{
if ($question instanceof assClozeTest) {
$this->validateClozeTest($answer_index, $question, $answer_expression, $question_index);
}
elseif(
} elseif (
$answer_expression instanceof PercentageResultExpression &&
$this->isResultOfAnswerExpression($question_expression) &&
!($question instanceof assFormulaQuestion)
)
{
) {
throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[" . ($answer_index + 1) . "]");
}
}
elseif(
} elseif (
($composite->nodes[0] instanceof AbstractOperation &&
$composite->nodes[1] instanceof ExpressionInterface) ||
($composite->nodes[0] instanceof ExpressionInterface &&
$composite->nodes[1] instanceof AbstractOperation) ||
($composite->nodes[0] instanceof SolutionExpressionInterface)
)
{
) {
throw new UnableToParseCondition("");
}
}
......@@ -147,63 +134,47 @@ class CompositeValidator
*/
private function validateClozeTest($answer_index, $question, $answer_expression, $question_index)
{
if($answer_index !== null)
{
if ($answer_index !== null) {
$options = $question->getAvailableAnswerOptions($answer_index);
$found = false;
switch($options->getType())
{
switch ($options->getType()) {
case 0: // text
if (
$answer_expression instanceof StringResultExpression
)
{
) {
$found = true;
}
break;
case 1: // select
if($answer_expression instanceof StringResultExpression)
{
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php';
foreach($options->getItems(new ilArrayElementShuffler()) as $item)
{
if($item->getAnswertext() == $answer_expression->getText())
{
if ($answer_expression instanceof StringResultExpression) {
foreach ($options->getItems(new ilArrayElementShuffler()) as $item) {
if ($item->getAnswertext() == $answer_expression->getText()) {
$found = true;
}
}
}
elseif($answer_expression instanceof NumberOfResultExpression)
{
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php';
foreach($options->getItems(new ilArrayElementShuffler()) as $item)
{
if($item->getOrder() == $answer_expression->getNumericValue()-1)
{
} elseif ($answer_expression instanceof NumberOfResultExpression) {
foreach ($options->getItems(new ilArrayElementShuffler()) as $item) {
if ($item->getOrder() == $answer_expression->getNumericValue() - 1) {
$found = true;
}
}
}
break;
case 2: // numeric
if($answer_expression instanceof NumericResultExpression)
{
if ($answer_expression instanceof NumericResultExpression) {
$found = true;
}
break;
}
if($answer_expression instanceof EmptyAnswerExpression)
{
if ($answer_expression instanceof EmptyAnswerExpression) {
$found = true;
}
if(!$found && !($answer_expression instanceof PercentageResultExpression))
{
if (!$found && !($answer_expression instanceof PercentageResultExpression)) {
throw new AnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index + 1);
}
}
}
......@@ -217,8 +188,7 @@ class CompositeValidator
private function checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index)
{
$answer_options = $question->getAvailableAnswerOptions($answer_index);
if($answer_options == null)
{
if ($answer_options == null) {
throw new AnswerIndexNotExist($question_index, $answer_index + 1);
}
}
......@@ -231,8 +201,7 @@ class CompositeValidator
*/
private function checkQuestionExists($question, $index)
{
if($question == null)
{
if ($question == null) {
throw new QuestionNotExist($index);
}
}
......@@ -256,8 +225,7 @@ class CompositeValidator
*/
private function checkAnswerExpressionExist($expressions, $answer_expression, $question_index)
{
if(!in_array($answer_expression::$identifier, $expressions))
{
if (!in_array($answer_expression::$identifier, $expressions)) {
throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index);
}
}
......@@ -271,8 +239,7 @@ class CompositeValidator
*/
private function checkOperatorExistForExpression($operators, $answer_expression, $pattern)
{
if(!in_array($pattern, $operators))
{
if (!in_array($pattern, $operators)) {
throw new OperatorNotSupportedByExpression($answer_expression->getValue(), $pattern);
}
}
......@@ -286,24 +253,19 @@ class CompositeValidator
private function checkQuestionIsReachable($question, $index)
{
$reachable = false;
foreach($this->data as $node)
{
if($node["node_index"] > $this->node->getIndex())
{
foreach ($this->data as $node) {
if ($node["node_index"] > $this->node->getIndex()) {
break;
}
if($node["question_fi"] == $question->getId())
{
if ($node["question_fi"] == $question->getId()) {
$reachable = true;
break;
}
}
if(!$reachable)
{
if (!$reachable) {
throw new QuestionNotReachable($index);
}
}
}
\ No newline at end of file
......@@ -11,7 +11,8 @@ require_once "Exception/ConditionParserException.php";
* Time: 13:54
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ConditionParser {
class ConditionParser
{
/**
* The condition which should be parsed into a ParserComposite to match a branch condition
......@@ -53,7 +54,8 @@ class ConditionParser {
/**
* Construct requirements
*/
public function __construct(){
public function __construct()
{
include_once __DIR__ . '/Factory/ExpressionManufacturer.php';
include_once __DIR__ . '/Factory/OperationManufacturer.php';
include_once "CompositeBuilder.php";
......@@ -67,7 +69,8 @@ class ConditionParser {
* @see CompositeBuilder::create()
* @return array
*/
public function parse($condition){
public function parse($condition)
{
$this->condition = $condition;
// $this->checkBrackets();
$this->fetchExpressions();
......@@ -86,7 +89,8 @@ class ConditionParser {
* @see ExpressionManufacturer::getPattern()
* @see Parser::$expressions
*/
protected function fetchExpressions(){
protected function fetchExpressions()
{
$manufacturer = ExpressionManufacturer::_getInstance();
$this->expressions = $manufacturer->match($this->condition);
}
......@@ -98,7 +102,8 @@ class ConditionParser {
* @see OperationManufacturer::getPattern()
* @see Parser::$operators
*/
protected function fetchOperators(){
protected function fetchOperators()
{
$manufacturer = OperationManufacturer::_getInstance();
$this->operators = $manufacturer->match($this->condition);
}
......@@ -110,7 +115,8 @@ class ConditionParser {
* <br />
* (n o n) o (n o n) o n
*/
protected function cannonicalizeCondition(){
protected function cannonicalizeCondition()
{
$manufacturer = ExpressionManufacturer::_getInstance();
$this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
$manufacturer = OperationManufacturer::_getInstance();
......@@ -118,10 +124,8 @@ class ConditionParser {
$this->condition = preg_replace("/no/", "n o", $this->condition);
$this->condition = preg_replace("/on/", "o n", $this->condition);
for($i = 0; $i < strlen($this->condition); $i++)
{
if($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i))
{
for ($i = 0; $i < strlen($this->condition); $i++) {
if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
$this->surroundNegationExpression($i);
}
}
......@@ -132,12 +136,10 @@ class ConditionParser {
$num_brackets_open = substr_count($this->condition, "(");
$num_brackets_close = substr_count($this->condition, ")");
if($num_brackets_open > $num_brackets_close)
{
if ($num_brackets_open > $num_brackets_close) {
throw new MissingBracket(")");
}
if($num_brackets_open < $num_brackets_close)
{
if ($num_brackets_open < $num_brackets_close) {
throw new MissingBracket("(");
}
}
......@@ -170,44 +172,29 @@ class ConditionParser {
$group = array();
$negation = false;
while($this->index < strlen($this->condition))
{
while ($this->index < strlen($this->condition)) {
$a = $this->condition[$this->index];
if(trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected))
{
if ($this->condition[$this->index] == ')')
{
if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) {
if ($this->condition[$this->index] == ')') {
return $group;
}
else if ($this->condition[$this->index] == 'n')
{
} elseif ($this->condition[$this->index] == 'n') {
$group[] = array('type' => 'expression', 'value' => array_shift($this->expressions));
$expected = array("o", ")");
}
else if ($this->condition[$this->index] == 'o')
{
} elseif ($this->condition[$this->index] == 'o') {
$group[] = array('type' => 'operator', 'value' => array_shift($this->operators));
$expected = array("n", "(", "!");
}
else if ($this->condition[$this->index] == '(')
{
} elseif ($this->condition[$this->index] == '(') {
$this->index++;
$elements = $this->createNodeArray();
$group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements);
$negation = false;
$expected = array("o",")");
}
else if($this->condition[$this->index] == "!")
{
} elseif ($this->condition[$this->index] == "!") {
$negation = true;
}
}
elseif(trim($this->condition[$this->index]) != "")
{
} elseif (trim($this->condition[$this->index]) != "") {
throw new ConditionParserException($this->index - $this->spaces + 1);
}
else
{
} else {
$this->spaces++;
}
......@@ -232,13 +219,11 @@ class ConditionParser {
$start = strpos($this->condition, "n", $index + 1);
$end = false;
if($start !== false)
{
if ($start !== false) {
$end = strpos($this->condition, "n", $start + 1);
}
if($start !== false && $end !== false)
{
if ($start !== false && $end !== false) {
$this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1);
}
}
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class AnswerIndexNotExist extends \RuntimeException{
class AnswerIndexNotExist extends \RuntimeException
{
/**
* @var int
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class AnswerValueNotExist extends \RuntimeException{
class AnswerValueNotExist extends \RuntimeException
{
/**
* @var int
......@@ -37,8 +38,7 @@ class AnswerValueNotExist extends \RuntimeException{
$this->value = $value;
$message = 'The value "%s" does not exist for the question Q%s[%s]';
if($this->answer_index === null)
{
if ($this->answer_index === null) {
$message = 'The value "%s" does not exist for the question Q%s';
}
......
......@@ -35,4 +35,3 @@ class ConditionParserException extends \RuntimeException
return $this->column;
}
}
\ No newline at end of file
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class DuplicateElement extends \RuntimeException{
class DuplicateElement extends \RuntimeException
{
/**
* @var string
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ExpressionNotSupportedByQuestion extends \RuntimeException{
class ExpressionNotSupportedByQuestion extends \RuntimeException
{
/**
* @var string
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class MissingBracket extends \RuntimeException{
class MissingBracket extends \RuntimeException
{
/**
* @var string
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class OperatorNotSupportedByExpression extends \RuntimeException{
class OperatorNotSupportedByExpression extends \RuntimeException
{
/**
* @var string
......
......@@ -8,7 +8,8 @@
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class QuestionNotExist extends \RuntimeException{
class QuestionNotExist extends \RuntimeException
{
/**
* @var int
......