transactions->run(function () use ($expenseId): void { $expense = $this->expenses->findById($expenseId) ?? throw new ExpenseNotFound($expenseId); if ($this->jobs->find($expense->jobId())->isLocked ?? true) { throw new ExpenseLocked; } $this->expenses->delete($expense); }); } }