GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6e8b8a...3f3148 )
by Cretu
03:22
created

WebPushServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 51.16%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 91
ccs 22
cts 43
cp 0.5116
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
B webPushConfig() 0 32 7
A boot() 0 15 2
A definePublishing() 0 14 2
1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
use Illuminate\Support\Str;
6
use Minishlink\WebPush\WebPush;
7
use Illuminate\Support\ServiceProvider;
8
9
class WebPushServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the application services.
13
     *
14
     * @return void
15
     */
16 14
    public function register()
17
    {
18 14
        $this->commands([VapidKeysGenerateCommand::class]);
19
20 14
        $this->mergeConfigFrom(__DIR__.'/../config/webpush.php', 'webpush');
21 14
    }
22
23
    /**
24
     * Bootstrap the application services.
25
     *
26
     * @return void
27
     */
28 14
    public function boot()
29
    {
30 14
        $this->app->when(WebPushChannel::class)
31 14
            ->needs(WebPush::class)
32 14
            ->give(function () {
33
                $webPush = new WebPush($this->webPushConfig());
34
                $webPush->setReuseVAPIDHeaders(true);
35
36
                return $webPush;
37 14
            });
38
39 14
        if ($this->app->runningInConsole()) {
40 14
            $this->definePublishing();
41
        }
42 14
    }
43
44
    /**
45
     * @return array
46
     */
47
    protected function webPushConfig()
48
    {
49
        $config = [];
50
        $webpush = config('webpush');
51
        $publicKey = $webpush['vapid']['public_key'];
52
        $privateKey = $webpush['vapid']['private_key'];
53
54
        if (! empty($webpush['gcm']['key'])) {
55
            $config['GCM'] = $webpush['gcm']['key'];
56
        }
57
58
        if (empty($publicKey) || empty($privateKey)) {
59
            return $config;
60
        }
61
62
        $config['VAPID'] = compact('publicKey', 'privateKey');
63
        $config['VAPID']['subject'] = $webpush['vapid']['subject'];
64
65
        if (empty($config['VAPID']['subject'])) {
66
            $config['VAPID']['subject'] = url('/');
67
        }
68
69
        if (! empty($webpush['vapid']['pem_file'])) {
70
            $config['VAPID']['pemFile'] = $webpush['vapid']['pem_file'];
71
72
            if (Str::startsWith($config['VAPID']['pemFile'], 'storage')) {
73
                $config['VAPID']['pemFile'] = base_path($config['VAPID']['pemFile']);
74
            }
75
        }
76
77
        return $config;
78
    }
79
80
    /**
81
     * Define the publishable migrations and resources.
82
     *
83
     * @return void
84
     */
85 14
    protected function definePublishing()
86
    {
87 14
        $this->publishes([
88 14
            __DIR__.'/../config/webpush.php' => config_path('webpush.php'),
89 14
        ], 'config');
90
91 14
        if (! class_exists('CreatePushSubscriptionsTable')) {
92 1
            $timestamp = date('Y_m_d_His', time());
93
94 1
            $this->publishes([
95 1
                __DIR__.'/../migrations/create_push_subscriptions_table.php.stub' => $this->app->databasePath().'/migrations/'.$timestamp.'_create_push_subscriptions_table.php',
96 1
            ], 'migrations');
97
        }
98 14
    }
99
}
100