/** * Increases the debt to the profile with given uniqueness, the given * amount. It also logs the operation using given description. * * @param string $uniqueness * @param int $amount * @param string $description * * @throws NonExistentUniquenessInternalException */ public function increase($uniqueness, $amount, $description) { $result = $this->connectToStorageInternalWorker->connect()->update(['uniqueness' => $uniqueness], ['$inc' => ['debt' => $amount]]); if ($result['n'] == 0) { throw new NonExistentUniquenessInternalException($uniqueness); } $this->logOperationInternalWorker->log($uniqueness, $amount, LogOperationInternalWorker::IMPACT_POSITIVE, $description); }
/** * Decreases the debt to the profile with given uniqueness, the given amount. * * @param string $uniqueness * @param int $amount * @param string $description * * @throws NonExistentUniquenessInternalException * @throws LowerDebtInternalException */ public function decrease($uniqueness, $amount, $description) { $item = $this->connectToStorageInternalWorker->connect()->findOne(['uniqueness' => $uniqueness], ['debt']); if (!$item) { throw new NonExistentUniquenessInternalException($uniqueness); } if ($amount > $item['debt']) { throw new LowerDebtInternalException(); } $this->connectToStorageInternalWorker->connect()->update(['uniqueness' => $uniqueness], ['$inc' => ['debt' => -1 * $amount]]); $this->logOperationInternalWorker->log($uniqueness, $amount, LogOperationInternalWorker::IMPACT_NEGATIVE, $description); }
/** * Logs an operation. * * @param string $uniqueness * @param int $amount * @param string $impact * @param string $description */ public function log($uniqueness, $amount, $impact, $description) { $this->logOperationInternalWorker->log($uniqueness, $amount, $impact, $description); }