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 ( 05243d...972fac )
by Cretu
09:10
created

WebPushServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 43.9%

Importance

Changes 0
Metric Value
wmc 12
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 88
ccs 18
cts 41
cp 0.439
rs 10

4 Methods

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

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
93
            ], 'migrations');
94
        }
95 12
    }
96
}
97