UseCustomQueryBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 11
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A query() 0 19 3
1
<?php
2
3
namespace Ianrizky\Illuminate\Database\Concerns;
4
5
use Illuminate\Database\Query\Builder;
6
use Illuminate\Support\Facades\Config;
7
use InvalidArgumentException;
8
9
trait UseCustomQueryBuilder
10
{
11
    /**
12
     * Get a new query builder instance.
13
     *
14
     * @return \Illuminate\Database\Query\Builder
15
     *
16
     * @throws \InvalidArgumentException
17
     */
18
    public function query(): Builder
19
    {
20
        $customQueryBuilderClass = Config::get('database.custom_query_builder_class');
21
22
        if (is_null($customQueryBuilderClass)) {
23
            return new Builder(
24
                $this, $this->getQueryGrammar(), $this->getPostProcessor()
0 ignored issues
show
Bug introduced by
It seems like getPostProcessor() 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
                $this, $this->getQueryGrammar(), $this->/** @scrutinizer ignore-call */ getPostProcessor()
Loading history...
Bug introduced by
$this of type Ianrizky\Illuminate\Data...s\UseCustomQueryBuilder is incompatible with the type Illuminate\Database\ConnectionInterface expected by parameter $connection of Illuminate\Database\Query\Builder::__construct(). ( Ignorable by Annotation )

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

24
                /** @scrutinizer ignore-type */ $this, $this->getQueryGrammar(), $this->getPostProcessor()
Loading history...
Bug introduced by
It seems like getQueryGrammar() 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
                $this, $this->/** @scrutinizer ignore-call */ getQueryGrammar(), $this->getPostProcessor()
Loading history...
25
            );
26
        }
27
28
        if (is_subclass_of($customQueryBuilderClass, Builder::class)) {
29
            return new $customQueryBuilderClass(
30
                $this, $this->getQueryGrammar(), $this->getPostProcessor()
31
            );
32
        }
33
34
        throw new InvalidArgumentException(sprintf(
35
            "The custom query builder class of %s must extend the base %s laravel class",
36
            $customQueryBuilderClass, Builder::class
37
        ));
38
    }
39
}
40