Passed
Branch beta (1b8e35)
by Jon
07:16
created

AppServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 101
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 50 4
B register() 0 37 4
1
<?php
2
3
namespace App\Providers;
4
5
use App\Rules\ValidateGoogleUrl;
6
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
7
use Carbon\Carbon;
8
use Illuminate\Foundation\AliasLoader;
9
use Illuminate\Support\Facades\DB;
10
use Illuminate\Support\Facades\Schema;
11
use Illuminate\Support\Facades\Validator;
12
use Illuminate\Support\ServiceProvider;
13
use Laravel\Dusk\DuskServiceProvider;
14
use Mpociot\LaravelTestFactoryHelper\TestFactoryHelperServiceProvider;
15
use Recca0120\LaravelTracy\LaravelTracyServiceProvider;
16
use STS\Filesystem\VfsFilesystemServiceProvider;
17
use Way\Generators\GeneratorsServiceProvider;
18
19
class AppServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * Bootstrap any application services.
23
     *
24
     * @return void
25
     */
26
    public function boot()
27
    {
28
        /*
29
         * Application locale defaults for various components
30
         *
31
         * These will be overridden by LocaleMiddleware if the session local is set
32
         */
33
34
        /*
35
         * setLocale for php. Enables ->formatLocalized() with localized values for dates
36
         */
37
        setlocale(LC_TIME, config('app.locale_php'));
38
39
        /*
40
         * setLocale to use Carbon source locales. Enables diffForHumans() localized
41
         */
42
        Carbon::setLocale(config('app.locale'));
43
44
        /*
45
         * Set the session variable for whether or not the app is using RTL support
46
         * For use in the blade directive in BladeServiceProvider
47
         */
48
        if (config('locale.languages')[config('app.locale')][2]) {
49
            session(['lang-rtl' => true]);
50
        } else {
51
            session()->forget('lang-rtl');
52
        }
53
54
        // Force SSL in production
55
        if ($this->app->environment() === 'production') {
0 ignored issues
show
introduced by
The condition $this->app->environment() === 'production' can never be true.
Loading history...
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
56
            //URL::forceScheme('https');
1 ignored issue
show
Unused Code Comprehensibility introduced by
72% 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...
57
        } else {
58
            DB::enableQueryLog();
59
            // DB::listen(function ($query) {
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% 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...
60
            //   var_dump([ $query->sql, $query->bindings, $query->time ]);
1 ignored issue
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...
61
            // });
62
        }
63
64
        // Set the default string length for Laravel5.4
65
        // https://laravel-news.com/laravel-5-4-key-too-long-error
66
        Schema::defaultStringLength(191);
67
68
        if (app()->resolved('bugsnag')) {
69
            $bugsnag = app('bugsnag');
70
            $bugsnag->setReleaseStage(env('BUGSNAG_RELEASE_STAGE', ''));
71
            $bugsnag->setErrorReportingLevel(E_ALL & ~E_NOTICE);
72
        }
73
74
        //register validation rules
75
        Validator::extend('googleUrl', ValidateGoogleUrl::class . '@validateSheet');
76
    }
77
78
    /**
79
     * Register any application services.
80
     *
81
     * @return void
82
     */
83
    public function register()
84
    {
85
        /*
86
         * Sets third party service providers that are only needed on local/testing environments
87
         */
88
        $environment = $this->app->environment();
89
        if ($environment !== 'production') {
0 ignored issues
show
introduced by
The condition $environment !== 'production' can never be false.
Loading history...
90
            /**
91
             * Loader for registering facades.
92
             */
93
            $loader = AliasLoader::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $loader is dead and can be removed.
Loading history...
94
            /*
95
             * Load third party local providers and facades
96
             */
97
            //$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
1 ignored issue
show
Unused Code Comprehensibility introduced by
64% 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...
98
            //$loader->alias('Debugbar', Facade::class);
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% 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...
99
            $this->app->register(IdeHelperServiceProvider::class);
100
            $this->app->register(TestFactoryHelperServiceProvider::class);
101
            $this->app->register(GeneratorsServiceProvider::class);
102
            // $this->app->register(MigrationsGeneratorServiceProvider::class);
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% 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...
103
            // $this->app->register(IseedServiceProvider::class);
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% 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...
104
            $this->app->register(DuskServiceProvider::class);
105
            // $this->app->register(DbSnapshotsServiceProvider::class);
1 ignored issue
show
Unused Code Comprehensibility introduced by
59% 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...
106
            $this->app->register(\Backpack\Generators\GeneratorsServiceProvider::class);
107
            if (class_exists(VfsFilesystemServiceProvider::class)) {
108
                $this->app->register(VfsFilesystemServiceProvider::class);
109
            }
110
        }
111
        if (! \in_array($environment, ['production', 'testing'], true)) {
112
            $this->app->register(LaravelTracyServiceProvider::class);
113
        }
114
        $this->app->bind('path.public',
115
            function () {
116
                return base_path() . '/web';
117
            });
118
        $this->app->alias('bugsnag.multi', \Illuminate\Contracts\Logging\Log::class);
119
        $this->app->alias('bugsnag.multi', \Psr\Log\LoggerInterface::class);
120
    }
121
}
122