Example #1
0
 /**
  * Calculate the condition applied
  *
  * @param  \Illuminate\Support\Fluent $expression
  * @param  \Elepunk\Evaluator\Collection $collection
  * @return integer
  */
 protected function calculate(Fluent $expression, Collection $collection)
 {
     $target = $collection->get($expression->target);
     $collection->setOriginalValue($target);
     $action = $expression->action;
     $operator = $this->getArithmeticOperator($action);
     $target = $this->isMutiplying($expression, $collection);
     $value = $this->getCalculationValue($expression->action);
     if ($this->isPercentage($action)) {
         $value = $this->evaluate('(value/100)*target', ['target' => $target, 'value' => $this->getCalculationValue($expression->action)]);
     }
     $calculated = $this->evaluate("first {$operator} second", ['first' => $target, 'second' => $value]);
     return $calculated;
 }