code: public function onUpdate(ResourceEventInterface $event)
      {
          $stockAdjustment = $this->getStockAdjustmentFromEvent($event);
  
          if (null === $stockUnit = $stockAdjustment->getStockUnit()) {
              throw new RuntimeException("Stock unit must be set at this point.");
          }
  
          $cs = $this->persistenceHelper->getChangeSet($stockAdjustment);
  
          if (isset($cs['reason']) && ($cs['reason'][0] != $cs['reason'][1])) {
              // (Default) From DEBIT to CREDIT
              if (isset($cs['quantity'])) {
                  $delta = $cs['quantity'][0] + $cs['quantity'][1];
              } else {
                  $delta = 2 * $stockAdjustment->getQuantity();
              }
              if (
                  !StockAdjustmentReasons::isDebitReason($cs['reason'][0])
                  && StockAdjustmentReasons::isDebitReason($cs['reason'][1])
              ) {
                  // From CREDIT to DEBIT
                  $delta = - $delta;
              }
          } elseif (isset($cs['quantity'])) {
              // OLD quantity - NEW quantity
              $delta = $cs['quantity'][1] - $cs['quantity'][0];
  
              // Opposite delta if debit
              if (StockAdjustmentReasons::isDebitReason($stockAdjustment->getReason())) {
                  $delta = -$delta;
              }
          } else {
              return;
          }
  
          $this->stockUnitUpdater->updateAdjusted($stockUnit, $delta, true);
      }
docs: Update event handler.
  
  @param ResourceEventInterface $event