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
Pull Request — master (#81)
by Seb
14:26
created

WebPushServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 41.86%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 90
ccs 18
cts 43
cp 0.4186
rs 10
c 0
b 0
f 0

4 Methods

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