Skip to content

Commit

Permalink
Merge pull request #39 from Trekels/master
Browse files Browse the repository at this point in the history
Readability and code quality improvements
  • Loading branch information
othillo authored Oct 20, 2017
2 parents bf6cafb + 4bd9c0e commit db3eee2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/Qandidate/Toggle/ExpressionCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class ExpressionCondition extends Condition
protected $language;

/**
* @param string $expression The expression to ve evaluated
* @param string $expression The expression to be evaluated
* @param ExpressionLanguage $language The instance of the Expression Language
*/
function __construct($expression, ExpressionLanguage $language)
public function __construct($expression, ExpressionLanguage $language)
{
$this->expression = $expression;
$this->language = $language;
Expand Down
24 changes: 16 additions & 8 deletions lib/Qandidate/Toggle/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,9 @@ public function activeFor(Context $context)
case self::INACTIVE:
return false;
case self::CONDITIONALLY_ACTIVE:
switch ($this->strategy) {
case self::STRATEGY_AFFIRMATIVE:
return $this->atLeastOneConditionHolds($context);
case self::STRATEGY_MAJORITY:
return $this->moreThanHalfConditionsHold($context);
case self::STRATEGY_UNANIMOUS:
return $this->allConditionsHold($context);
}
return $this->executeCondition($context);
}
return false;
}

/**
Expand Down Expand Up @@ -170,6 +164,20 @@ private function assertValidStrategy($strategy)
}
}

private function executeCondition(Context $context)
{
switch ($this->strategy) {
case self::STRATEGY_AFFIRMATIVE:
return $this->atLeastOneConditionHolds($context);
case self::STRATEGY_MAJORITY:
return $this->moreThanHalfConditionsHold($context);
case self::STRATEGY_UNANIMOUS:
return $this->allConditionsHold($context);
default:
return false;
}
}

/**
* @param Context $context
*
Expand Down

0 comments on commit db3eee2

Please sign in to comment.