Test Failed
Pull Request — master (#12)
by
unknown
04:19
created

ExpoPushNotificationsServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 54
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 24 2
A register() 0 4 1
A getInterestsDriver() 0 12 2
1
<?php
2
3
namespace NotificationChannels\ExpoPushNotifications;
4
5
use ExponentPhpSDK\Expo;
6
use ExponentPhpSDK\ExpoRegistrar;
7
use ExponentPhpSDK\ExpoRepository;
8
use Illuminate\Support\ServiceProvider;
9
use ExponentPhpSDK\Repositories\ExpoFileDriver;
10
use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver;
11
12
class ExpoPushNotificationsServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     */
17 17
    public function boot()
18
    {
19 17
        $this->publishes([
20 17
            __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'),
21 17
        ], 'config');
22
23 17
        $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications');
24
25 17
        if (! class_exists('CreateExponentPushNotificationInterestsTable')) {
26 1
            $timestamp = date('Y_m_d_His', time());
27 1
            $this->publishes([
28 1
                __DIR__.'/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"),
29 1
            ], 'migrations');
30
        }
31
32 17
        $this->app->when(ExpoChannel::class)
33 17
            ->needs(Expo::class)
34 17
            ->give(function () {
35
                return new Expo(new ExpoRegistrar($this->getInterestsDriver()));
0 ignored issues
show
Bug introduced by
It seems like $this->getInterestsDriver() targeting NotificationChannels\Exp...r::getInterestsDriver() can also be of type null; however, ExponentPhpSDK\ExpoRegistrar::__construct() does only seem to accept object<ExponentPhpSDK\ExpoRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
36 17
            });
37
38
        //Load routes
39 17
        $this->loadRoutesFrom(__DIR__.'/Http/routes.php');
40 17
    }
41
42
    /**
43
     * Register the application services.
44
     */
45 17
    public function register()
46
    {
47 17
        $this->app->bind(ExpoRepository::class, get_class($this->getInterestsDriver()));
48 17
    }
49
50
    /**
51
     * @return ExpoRepository
52
     */
53 17
    public function getInterestsDriver()
54
    {
55 17
        $driver = config('exponent-push-notifications.interests.driver');
56
57
        switch ($driver) {
58 17
            case 'database':
59
                return new ExpoDatabaseDriver();
60
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
61
            default:
62 17
                return new ExpoFileDriver();
63
        }
64
    }
65
}
66