Passed
Push — master ( 0d1e3a...a8104a )
by Jonas
11:45
created

HasEagerLimit::newMorphOne()   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 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 5
crap 1
1
<?php
2
3
namespace Staudenmeir\EloquentEagerLimit;
4
5
use Illuminate\Database\Connection;
6
use RuntimeException;
7
use Staudenmeir\EloquentEagerLimit\Grammars\MySqlGrammar;
8
use Staudenmeir\EloquentEagerLimit\Grammars\PostgresGrammar;
9
use Staudenmeir\EloquentEagerLimit\Grammars\SQLiteGrammar;
10
use Staudenmeir\EloquentEagerLimit\Grammars\SqlServerGrammar;
11
use Staudenmeir\EloquentEagerLimit\Traits\HasEagerLimitRelationships;
12
13
trait HasEagerLimit
14
{
15
    use HasEagerLimitRelationships;
16
17
    /**
18
     * Get a new query builder instance for the connection.
19
     *
20
     * @return \Illuminate\Database\Query\Builder
21
     */
22 148
    protected function newBaseQueryBuilder()
23
    {
24 148
        $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

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