{
  "filename": "app/Actions/ConfirmOrder.php",
  "rule": "- name: job-after-commit\n  where: \"app/Actions/ConfirmOrder.php\"\n  ensure: >-\n    The order-confirmation job is explicitly deferred until the surrounding database transaction commits: SendOrderConfirmation::dispatch($order->id) is chained with ->afterCommit(). Plain dispatch inside the transaction does not meet this requirement.",
  "corrected": "<?php\nnamespace App\\Actions;\nuse App\\Jobs\\SendOrderConfirmation;\nuse App\\Models\\Order;\nuse Illuminate\\Support\\Facades\\DB;\n\nclass ConfirmOrder {\n    public function handle(int $tenantId, int $orderId): void {\n        DB::transaction(function () use ($tenantId, $orderId) {\n            $order = Order::where('tenant_id', $tenantId)\n                ->whereKey($orderId)->lockForUpdate()->firstOrFail();\n            if ($order->status !== 'pending') throw new \\RuntimeException('Not pending');\n            $order->status = 'confirmed';\n            $order->saveOrFail();\n            SendOrderConfirmation::dispatch($order->id)->afterCommit();\n        });\n    }\n}\n",
  "broken": "<?php\nnamespace App\\Actions;\nuse App\\Jobs\\SendOrderConfirmation;\nuse App\\Models\\Order;\nuse Illuminate\\Support\\Facades\\DB;\n\nclass ConfirmOrder {\n    public function handle(int $tenantId, int $orderId): void {\n        DB::transaction(function () use ($tenantId, $orderId) {\n            $order = Order::where('tenant_id', $tenantId)\n                ->whereKey($orderId)->lockForUpdate()->firstOrFail();\n            if ($order->status !== 'pending') throw new \\RuntimeException('Not pending');\n            $order->status = 'confirmed';\n            $order->saveOrFail();\n            SendOrderConfirmation::dispatch($order->id);\n        });\n    }\n}\n",
  "regression": [
    "->afterCommit()",
    ""
  ],
  "test_scenarios": [
    [
      "Successful confirmation",
      "Job becomes eligible after commit"
    ],
    [
      "Exception inside transaction",
      "No confirmation job dispatched"
    ],
    [
      "Worker is fast",
      "Cannot read the uncommitted new state"
    ],
    [
      "Queue unavailable after commit",
      "Record failure and retry delivery through a durable design"
    ]
  ],
  "test_source": null,
  "test_command": "php artisan test --filter=ConfirmOrderTest"
}