Ejemplo n.º 1
0
 /**
  * Increases the balance 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 NonExistentUniquenessSharedException
  */
 public function increase($uniqueness, $amount, $description)
 {
     $result = $this->connectToStorageInternalWorker->connect()->update(['uniqueness' => $uniqueness], ['$inc' => ['balance' => $amount]]);
     if ($result['n'] == 0) {
         throw new NonExistentUniquenessSharedException($uniqueness);
     }
     $this->logOperationInternalWorker->log($uniqueness, $amount, LogOperationInternalWorker::IMPACT_POSITIVE, $description);
 }
Ejemplo n.º 2
0
 /**
  * Decreases the balance 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 NonExistentUniquenessSharedException
  * @throws InsufficientBalanceSharedException
  */
 public function decrease($uniqueness, $amount, $description)
 {
     $item = $this->connectToStorageInternalWorker->connect()->findOne(['uniqueness' => $uniqueness], ['balance']);
     if (!$item) {
         throw new NonExistentUniquenessSharedException($uniqueness);
     }
     if ($amount > $item['balance']) {
         throw new InsufficientBalanceSharedException();
     }
     $this->connectToStorageInternalWorker->connect()->update(['uniqueness' => $uniqueness], ['$inc' => ['balance' => -1 * $amount]]);
     $this->logOperationInternalWorker->log($uniqueness, $amount, LogOperationInternalWorker::IMPACT_NEGATIVE, $description);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }