Completed
Pull Request — master (#12)
by
unknown
03:42
created

ExpoPushNotificationsServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0008

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 16
cts 17
cp 0.9412
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0008
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 21
    public function boot()
18
    {
19 21
        $this->publishes([
20 21
            __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'),
21 21
        ], 'config');
22
23 21
        $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications');
24
25 21
        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 21
        $this->app->when(ExpoChannel::class)
33 21
            ->needs(Expo::class)
34 21
            ->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 21
            });
37
38
        //Load routes
39 21
        $this->loadRoutesFrom(__DIR__.'/Http/routes.php');
40 21
    }
41
42
    /**
43
     * Register the application services.
44
     */
45 21
    public function register()
46
    {
47 21
        $this->app->bind(ExpoRepository::class, get_class($this->getInterestsDriver()));
48 21
    }
49
50
    /**
51
     * @return ExpoRepository
52
     */
53 21
    public function getInterestsDriver()
54
    {
55 21
        $driver = config('exponent-push-notifications.interests.driver');
56
57
        switch ($driver) {
58 21
            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 21
                return new ExpoFileDriver();
63
        }
64
    }
65
}
66