Completed
Push — master ( d60e48...964e97 )
by Elf
05:34 queued 04:21
created

DataTablesServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 4
dl 0
loc 71
ccs 25
cts 25
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A registerOriginalDataTables() 0 7 1
A replaceDataTablesBindings() 0 9 1
A configureDataTables() 0 21 3
1
<?php
2
3
namespace ElfSundae\Laravel\DataTables;
4
5
use Illuminate\Foundation\AliasLoader;
6
use Illuminate\Support\ServiceProvider;
7
8
class DataTablesServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Register the service provider.
12
     *
13
     * @return void
14
     */
15 6
    public function register()
16
    {
17 6
        $this->registerOriginalDataTables();
18
19 6
        $this->replaceDataTablesBindings();
20
21 6
        $this->configureDataTables();
22 6
    }
23
24
    /**
25
     * Register the original DataTables service providers.
26
     *
27
     * @return void
28
     */
29 6
    protected function registerOriginalDataTables()
30
    {
31 6
        $this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class);
32 6
        AliasLoader::getInstance()->alias('DataTables', \Yajra\DataTables\Facades\DataTables::class);
33
34 6
        $this->app->register(\Yajra\DataTables\ButtonsServiceProvider::class);
35 6
    }
36
37
    /**
38
     * Replace the original DataTables bindings.
39
     *
40
     * @return void
41
     */
42 6
    protected function replaceDataTablesBindings()
43
    {
44 6
        $this->app->alias('datatables', DataTables::class);
45 6
        $this->app->singleton('datatables', function () {
46 4
            return new DataTables;
47 6
        });
48
49
        // $this->app->bind('datatables.html', Html\Builder::class);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50 6
    }
51
52
    /**
53
     * Configure DataTables.
54
     *
55
     * @return void
56
     */
57 6
    protected function configureDataTables()
58
    {
59
        // Restore the default "builders" configuration.
60
        // See https://github.com/yajra/laravel-datatables/pull/1462/commits/afdbe6bce9ade9b19d66034ace3d8a2c24da8a56
61 6
        if (! $this->app['config']->get('datatables.builders')) {
62 6
            $this->app['config']->set('datatables.builders', [
63 6
                \Illuminate\Database\Eloquent\Builder::class => 'eloquent',
64
                \Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent',
65
                \Illuminate\Database\Query\Builder::class => 'query',
66
                \Illuminate\Support\Collection::class => 'collection',
67
            ]);
68
        }
69
70
        // Configure our custom DataTable service stub for "make" command
71 6
        if (! $this->app['config']->get('datatables-buttons.stub')) {
72 5
            $this->app['config']->set(
73 5
                'datatables-buttons.stub',
74 5
                '/vendor/elfsundae/laravel-datatables/src/stubs'
75
            );
76
        }
77 6
    }
78
}
79