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

DbService::connection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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