Completed
Push — master ( 1246df...7ae60e )
by Elf
04:06
created

AppServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ElfSundae\Laravel\Support\Providers;
4
5
use Carbon\Carbon;
6
use Illuminate\Http\Request;
7
use ElfSundae\Laravel\Support\Helper;
8
use Illuminate\Support\ServiceProvider;
9
10
class AppServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        $this->setLocaleForCarbon();
20
    }
21
22
    /**
23
     * Set locale for Carbon.
24
     *
25
     * @return bool
26
     */
27
    protected function setLocaleForCarbon()
28
    {
29
        return Carbon::setLocale($this->app['config']->get('support.carbon_locale'), $this->app->getLocale());
0 ignored issues
show
Unused Code introduced by
The call to Carbon::setLocale() has too many arguments starting with $this->app->getLocale().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
    }
31
32
    /**
33
     * Register any application services.
34
     *
35
     * @return void
36
     */
37
    public function register()
38
    {
39
        array_map([$this->app, 'register'], $this->getServiceProviders());
40
41
        $this->modifyCurrentRequest();
42
    }
43
44
    /**
45
     * Get service providers to be registered.
46
     *
47
     * @return array
48
     */
49
    protected function getServiceProviders()
50
    {
51
        $providers = [];
52
53
        if (is_app('admin') || $this->app->runningInConsole()) {
54
            array_push(
55
                $providers,
56
                \ElfSundae\Laravel\Datatables\DatatablesServiceProvider::class,
57
                \Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class
58
            );
59
        }
60
61
        return $providers;
62
    }
63
64
    /**
65
     * Modify the current request.
66
     *
67
     * @return void
68
     */
69
    protected function modifyCurrentRequest()
70
    {
71
        Helper::addAcceptableJsonType(
72
            function (Request $request) {
73
                return $this->shouldAddAcceptableJsonType($request);
74
            }
75
        );
76
    }
77
78
    /**
79
     * Determines appending JSON type to the "Accept" header for the current request.
80
     *
81
     * @param  \Illuminate\Http\Request  $request
82
     * @return bool
83
     */
84
    protected function shouldAddAcceptableJsonType(Request $request)
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        return is_app('api');
87
    }
88
}
89