Completed
Push — master ( 22c53b...8b3116 )
by Elf
02:37
created

Datatables::queryBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
namespace ElfSundae\Laravel\Datatables;
4
5
use Exception;
6
use Illuminate\Support\Collection;
7
use Yajra\Datatables\Datatables as BaseDatatables;
8
9
class Datatables extends BaseDatatables
10
{
11
    /**
12
     * Create an engine instance with configured class.
13
     *
14
     * @param  string  $type
15
     * @param  mixed  $source
16
     * @return \Yajra\Datatables\Engines\BaseEngine|null
17
     */
18
    protected function createEngineForType($type, $source)
19
    {
20
        if ($class = $this->getConfiguredEngineClass($type)) {
21
            return new $class($source, $this->request);
22
        }
23
    }
24
25
    /**
26
     * Get the configured engine class.
27
     *
28
     * @param  string  $type
29
     * @return string
30
     */
31
    protected function getConfiguredEngineClass($type)
32
    {
33
        return app('config')->get('datatables.engines.'.$type);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function queryBuilder($builder)
40
    {
41
        return $this->createEngineForType('query', $builder) ?:
42
            parent::queryBuilder($builder);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function eloquent($builder)
49
    {
50
        return $this->createEngineForType('eloquent', $builder) ?:
51
            parent::eloquent($builder);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function collection($collection)
58
    {
59
        if (is_array($collection)) {
60
            $collection = new Collection($collection);
61
        }
62
63
        return $this->createEngineForType('collection', $collection) ?:
64
            parent::collection($builder);
0 ignored issues
show
Bug introduced by
The variable $builder does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
65
    }
66
}
67