Lines 100.00% 6 / 6
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 lockStatement 100.00% 1 / 1 100.00% 1 / 1 1
 unlockStatement 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Database\Locks\SqlLock] withLock 100.00% 3 / 3 100.00% 1 / 1 1
19final class PostgresLock extends SqlLock
20{
21    /**
22     * @param  PostgresConnection  $connection
23     */
24    public function __construct(PostgresConnection $connection)
25    {
26        parent::__construct($connection);
27    }
28
29    /**
30     * The lock acquisition statement — blocks until acquired.
31     *
32     * @return string
33     */
34    #[\Override]
35    protected function lockStatement(): string
36    {
37        return 'SELECT pg_advisory_lock(hashtext(?))';
38    }
39
40    /**
41     * The lock release statement.
42     *
43     * @return string
44     */
45    #[\Override]
46    protected function unlockStatement(): string
47    {
48        return 'SELECT pg_advisory_unlock(hashtext(?))';
49    }
50}

Inherited from BlueprintAU\Radiant\Database\Locks\SqlLock

53    final public function withLock(callable $callback, string $name): mixed
54    {
55        // The lock statement runs with the name bound (no interpolation); a
56        // failure to acquire must surface as an exception, not a silent
57        // no-lock run.
58        $this->connection->statement($this->lockStatement(), [$name]);
59        try {
60            return $callback();
61        } finally {
62            $this->connection->statement($this->unlockStatement(), [$name]);
63        }
64    }