• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mpyw / laravel-database-advisory-lock / 13646006723

04 Mar 2025 04:06AM UTC coverage: 100.0% (+0.6%) from 99.401%
13646006723

push

github

mpyw
refactor: 💡 Remove useless branch

1 of 1 new or added line in 1 file covered. (100.0%)

164 of 164 relevant lines covered (100.0%)

95.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/AdvisoryLocks.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Mpyw\LaravelDatabaseAdvisoryLock;
6

7
use Closure;
8
use Illuminate\Database\Connection;
9
use Illuminate\Database\QueryException;
10
use Mpyw\LaravelDatabaseAdvisoryLock\Contracts\LockerFactory as FactoryContract;
11

12
/**
13
 * trait AdvisoryLocks
14
 *
15
 * Designed to be mixed in with the Connection classes.
16
 */
17
trait AdvisoryLocks
18
{
19
    public ?FactoryContract $advisoryLocker = null;
20

21
    /**
22
     * Create LockerFactory or return existing one.
23
     */
24
    public function advisoryLocker(): FactoryContract
25
    {
26
        assert($this instanceof Connection);
27

28
        return $this->advisoryLocker ??= new LockerFactory($this);
384✔
29
    }
30

31
    /**
32
     * Overrides the original implementation.
33
     *
34
     * @param  string         $query
35
     * @param  array          $bindings
36
     * @throws QueryException
37
     */
38
    protected function handleQueryException(QueryException $e, $query, $bindings, Closure $callback)
39
    {
40
        assert($this instanceof Connection);
41

42
        // Don't try again if there are session-level locks.
43
        if ($this->transactionLevel() > 0 || $this->advisoryLocker()->forSession()->hasAny()) {
64✔
44
            throw $e;
56✔
45
        }
46

47
        return $this->tryAgainIfCausedByLostConnection(
8✔
48
            $e,
8✔
49
            $query,
8✔
50
            $bindings,
8✔
51
            $callback,
8✔
52
        );
8✔
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc