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.

WebPushServiceProvider::definePublishing()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Str;
7
use Minishlink\WebPush\WebPush;
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
            ->give(function () {
33
                $webPush = new WebPush($this->webPushConfig());
34
                $webPush->setReuseVAPIDHeaders(true);
35
36
                return $webPush;
37 14
            });
38
39 14
        $this->app->when(WebPushChannel::class)
40 14
            ->needs(ReportHandlerInterface::class)
41 14
            ->give(ReportHandler::class);
42
43 14
        if ($this->app->runningInConsole()) {
44 14
            $this->definePublishing();
45
        }
46 14
    }
47
48
    /**
49
     * @return array
50
     */
51
    protected function webPushConfig()
52
    {
53
        $config = [];
54
        $webpush = config('webpush');
55
        $publicKey = $webpush['vapid']['public_key'];
56
        $privateKey = $webpush['vapid']['private_key'];
57
58
        if (! empty($webpush['gcm']['key'])) {
59
            $config['GCM'] = $webpush['gcm']['key'];
60
        }
61
62
        if (empty($publicKey) || empty($privateKey)) {
63
            return $config;
64
        }
65
66
        $config['VAPID'] = compact('publicKey', 'privateKey');
67
        $config['VAPID']['subject'] = $webpush['vapid']['subject'];
68
69
        if (empty($config['VAPID']['subject'])) {
70
            $config['VAPID']['subject'] = url('/');
71
        }
72
73
        if (! empty($webpush['vapid']['pem_file'])) {
74
            $config['VAPID']['pemFile'] = $webpush['vapid']['pem_file'];
75
76
            if (Str::startsWith($config['VAPID']['pemFile'], 'storage')) {
77
                $config['VAPID']['pemFile'] = base_path($config['VAPID']['pemFile']);
78
            }
79
        }
80
81
        return $config;
82
    }
83
84
    /**
85
     * Define the publishable migrations and resources.
86
     *
87
     * @return void
88
     */
89 14
    protected function definePublishing()
90
    {
91 14
        $this->publishes([
92 14
            __DIR__.'/../config/webpush.php' => config_path('webpush.php'),
93 14
        ], 'config');
94
95 14
        if (! class_exists('CreatePushSubscriptionsTable')) {
96 1
            $timestamp = date('Y_m_d_His', time());
97
98 1
            $this->publishes([
99 1
                __DIR__.'/../migrations/create_push_subscriptions_table.php.stub' => database_path("migrations/{$timestamp}_create_push_subscriptions_table.php"),
100 1
            ], 'migrations');
101
        }
102 14
    }
103
}
104