/** * @param string $operation operation * @param Percentage $right right * * @return Result */ protected function computeWithPercent($operation, Percentage $right) { switch ($operation) { case Operation::MAJORATE: $value = $this->round($this->getValue() * (1 + $right->getValue() / 100)); break; case Operation::MINORATE: $value = $this->round($this->getValue() * (1 - $right->getValue() / 100)); break; case Operation::EXONERATE: $value = $this->round($this->getValue() / (1 + $right->getValue() / 100)); break; default: throw new \LogicException(sprintf('Unsupported operator (%s) in operation: "%s %s %s".', $operation, $this, $operation, $right)); break; } return new Result(new Price($value, $this->getCurrency(), $this->getFormatter()), new Price($this->round(abs($this->getValue() - $value)), $this->getCurrency(), $this->getFormatter()), sprintf('%s %s %s', $this, $operation, $right)); }
public function testConstruct($value, $expectedValue) { $this->if($percentage = new TestedPercentage($value))->phpFloat($percentage->getValue())->isIdenticalTo($expectedValue)->if($level = $percentage->getLevel())->integer($level)->isIdenticalTo(0); }