newBaseQueryBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Staudenmeir\EloquentEagerLimitXLaravelCte\Eloquent;
4
5
use Illuminate\Database\Connection;
6
use RuntimeException;
7
use Staudenmeir\EloquentEagerLimit\Traits\HasEagerLimitRelationships;
8
use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Builder;
9
use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\MySqlGrammar;
10
use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\PostgresGrammar;
11
use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\SQLiteGrammar;
12
use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\SqlServerGrammar;
13
14
trait HasEagerLimitAndQueriesExpressions
15
{
16
    use HasEagerLimitRelationships;
17
18
    /**
19
     * Get a new query builder instance for the connection.
20
     *
21
     * @return \Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Builder
22
     */
23 229
    protected function newBaseQueryBuilder()
24
    {
25 229
        $connection = $this->getConnection();
0 ignored issues
show
Bug introduced by
It seems like getConnection() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $connection = $this->getConnection();
Loading history...
26
27 229
        $grammar = $connection->withTablePrefix(
28 229
            $this->getQueryGrammar($connection)
29 229
        );
30
31 229
        return new Builder($connection, $grammar);
32
    }
33
34
    /**
35
     * Get the query grammar.
36
     *
37
     * @param \Illuminate\Database\Connection $connection
38
     * @return \Illuminate\Database\Query\Grammars\Grammar
39
     */
40 229
    protected function getQueryGrammar(Connection $connection)
41
    {
42 229
        $driver = $connection->getDriverName();
43
44
        switch ($driver) {
45 229
            case 'mysql':
46 89
                return new MySqlGrammar();
47 140
            case 'pgsql':
48 48
                return new PostgresGrammar();
49 92
            case 'sqlite':
50 47
                return new SQLiteGrammar();
51 45
            case 'sqlsrv':
52 45
                return new SqlServerGrammar();
53
        }
54
55
        throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
56
    }
57
}
58