DbService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 37
rs 10
c 1
b 0
f 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 3 1
A raw() 0 3 1
A transaction() 0 7 2
1
<?php
2
3
namespace Bavix\Wallet\Services;
4
5
use Closure;
6
use Illuminate\Database\ConnectionInterface;
7
use Illuminate\Database\Query\Expression;
8
use Illuminate\Support\Facades\DB;
9
10
/**
11
 * Class DbService.
12
 * @codeCoverageIgnore
13
 */
14
class DbService
15
{
16
    /**
17
     * @return ConnectionInterface
18
     */
19
    public function connection(): ConnectionInterface
20
    {
21
        return DB::connection(config('wallet.database.connection'));
22
    }
23
24
    /**
25
     * Execute a Closure within a transaction.
26
     *
27
     * @param Closure $callback
28
     * @param int $attempts
29
     * @return mixed
30
     *
31
     * @throws \Throwable
32
     */
33
    public function transaction(Closure $callback, $attempts = 1)
34
    {
35
        if ($this->connection()->transactionLevel()) {
36
            return $callback($this);
37
        }
38
39
        return $this->connection()->transaction($callback, $attempts);
40
    }
41
42
    /**
43
     * Get a new raw query expression.
44
     *
45
     * @param mixed $value
46
     * @return Expression
47
     */
48
    public function raw($value): Expression
49
    {
50
        return $this->connection()->raw($value);
51
    }
52
}
53