Completed
Pull Request — master (#118)
by Бабичев
12:47 queued 02:46
created

DbService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 34
ccs 4
cts 6
cp 0.6667
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A raw() 0 3 1
A transaction() 0 3 1
A connection() 0 3 1
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
class DbService
11
{
12
13
    /**
14
     * @return ConnectionInterface
15
     */
16 73
    public function connection(): ConnectionInterface
17
    {
18 73
        return DB::connection(config('wallet.database.connection'));
19
    }
20
21
    /**
22
     * Execute a Closure within a transaction.
23
     *
24
     * @param Closure $callback
25
     * @param int $attempts
26
     * @return mixed
27
     *
28
     * @throws \Throwable
29
     */
30 73
    public function transaction(Closure $callback, $attempts = 1)
31
    {
32 73
        return $this->connection()->transaction($callback, $attempts);
33
    }
34
35
    /**
36
     * Get a new raw query expression.
37
     *
38
     * @param mixed $value
39
     * @return Expression
40
     */
41
    public function raw($value): Expression
42
    {
43
        return $this->connection()->raw($value);
44
    }
45
46
}
47