Lines 100.00% 7 / 7
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
StaleRowException 100.00% 7 / 7 100.00% 1 / 1 1 100.00% 1 / 1
 __construct 100.00% 7 / 7 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace BlueprintAU\Radiant\Exceptions;
6
7/**
8 * Thrown when an instance write matched no rows because the row was
9 * already removed by another connection.
10 */
11final class StaleRowException extends \RuntimeException
12{
13    /**
14     * The class-string of the model whose row was already gone.
15     *
16     * @var class-string<\BlueprintAU\Radiant\Model>
17     */
18    public readonly string $model;
19
20    /**
21     * The operation that matched no rows (`delete`, `restore`).
22     *
23     * @var string
24     */
25    public readonly string $operation;
26
27    /**
28     * @param  class-string<\BlueprintAU\Radiant\Model>  $modelClass
29     * @param  string  $operation
30     */
31    public function __construct(string $modelClass, string $operation)
32    {
33        parent::__construct(
34            "The {$operation} on model [{$modelClass}] matched no rows — the row was "
35            . 'already removed by another connection (a stale instance). Re-fetch the '
36            . 'model before writing again.'
37        );
38
39        $this->model = $modelClass;
40        $this->operation = $operation;
41    }
42}