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

Datatables   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
ccs 0
cts 28
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createEngineForType() 0 6 2
A getConfiguredEngineClass() 0 4 1
A queryBuilder() 0 5 2
A eloquent() 0 5 2
A collection() 0 9 3
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