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 ( 17b68b...43ebaf )
by Cretu
08:51
created

WebPushServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 53.66%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A definePublishing() 0 14 2
A boot() 0 12 2
C webPushConfig() 0 32 7
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 13
    public function register()
17
    {
18 13
        $this->commands([VapidKeysGenerateCommand::class]);
19
20 13
        $this->mergeConfigFrom(__DIR__.'/../config/webpush.php', 'webpush');
21 13
    }
22
23
    /**
24
     * Bootstrap the application services.
25
     *
26
     * @return void
27
     */
28 13
    public function boot()
29
    {
30 13
        $this->app->when(WebPushChannel::class)
31 13
            ->needs(WebPush::class)
32 13
            ->give(function () {
33
                return new WebPush($this->webPushConfig());
34 13
            });
35
36 13
        if ($this->app->runningInConsole()) {
37 13
            $this->definePublishing();
38
        }
39 13
    }
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 13
    protected function definePublishing()
83
    {
84 13
        $this->publishes([
85 13
            __DIR__.'/../config/webpush.php' => config_path('webpush.php'),
86 13
        ], 'config');
87
88 13
        if (! class_exists('CreatePushSubscriptionsTable')) {
89 1
            $timestamp = date('Y_m_d_His', time());
90
91 1
            $this->publishes([
92 1
                __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 1
            ], 'migrations');
94
        }
95 13
    }
96
}
97