public function elapse(Time $time) { foreach ($this->actions as $key => $action) { /** @var Time $timeLeft */ $timeLeft = $action['time']; $method = $action['action']; $argument = $action['argument']; $timeLeft->toNative(); $time->toNative(); $timeLeft->subtract($time); if (BCProvider::compare($timeLeft->getValue(), 0) <= 0) { unset($this->actions[$key]); $executeTime = clone $timeLeft->add($time); } else { $executeTime = $time; } $reflectMethod = new \ReflectionMethod($this, $method); $params = $reflectMethod->getParameters(); if (count($params) != 2) { throw new \Exception('Cannot invoke action because a parameter count mismatch.'); } $args = []; foreach ($params as $pKey => $param) { if (strpos($param->getClass()->name, 'Time') !== false) { $args[$pKey] = $executeTime; } else { $args[$pKey] = $argument; } } $reflectMethod->invokeArgs($this, $args); } return $this; }
/** * @param NumberInterface|int|float|string $value * @return int */ public function compare($value) { $value = Numbers::makeOrDont($this, $value, $this->getPrecision()); if ($this->getBase() != 10) { $thisValue = $this->convertToBase(10)->getValue(); } else { $thisValue = $this->getValue(); } if ($value->getBase() != 10) { $thatValue = $value->convertToBase(10)->getValue(); } else { $thatValue = $value->getValue(); } $scale = $this->getPrecision() < $value->getPrecision() ? $this->getPrecision() : $value->getPrecision(); return BCProvider::compare($thisValue, $thatValue, $scale); }