Passed
Pull Request — master (#154)
by Zing
04:11
created

SmsServiceProvider::boot()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 13
ccs 6
cts 8
cp 0.75
rs 10
cc 3
nc 3
nop 0
crap 3.1406
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\LaravelSms;
6
7
use Illuminate\Contracts\Container\Container;
8
use Illuminate\Foundation\Application as Laravel;
9
use Illuminate\Notifications\ChannelManager;
10
use Illuminate\Support\Facades\Notification;
11
use Illuminate\Support\ServiceProvider;
12
use Laravel\Lumen\Application as Lumen;
0 ignored issues
show
Bug introduced by
The type Laravel\Lumen\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Zing\LaravelSms\Channels\SmsChannel;
14
use Zing\LaravelSms\Commands\SmsSwitchConnectionCommand;
15
use Zing\LaravelSms\Facades\Sms;
16
17
class SmsServiceProvider extends ServiceProvider
18
{
19
    private const SMS = 'sms';
20
21 50
    public function boot(): void
22
    {
23 50
        if (! $this->app->runningInConsole()) {
24
            return;
25
        }
26
27 50
        if (! $this->app instanceof Laravel) {
28
            return;
29
        }
30
31 50
        $this->publishes([
32 50
            $this->getConfigPath() => config_path('sms.php'),
33 50
        ], 'config');
34 50
    }
35
36 50
    public function register(): void
37
    {
38 50
        $this->registerConfig();
39 50
        Notification::resolved(
40 50
            function (ChannelManager $service): void {
41 11
                $service->extend(self::SMS, function (Container $app) {
42 2
                    return $app->make(SmsChannel::class);
43 11
                });
44 50
            }
45
        );
46 50
        $this->app->singleton(self::SMS, function (Container $app) {
47 12
            return $app->make(SmsManager::class);
48 50
        });
49 50
        $this->app->alias(self::SMS, Sms::class);
50 50
        $this->registerCommands();
51 50
    }
52
53 50
    protected function getConfigPath(): string
54
    {
55 50
        return __DIR__ . '/../config/sms.php';
56
    }
57
58 50
    protected function registerConfig(): void
59
    {
60 50
        if ($this->app instanceof Lumen) {
61
            $this->app->configure(self::SMS);
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean configPath()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
            $this->app->/** @scrutinizer ignore-call */ 
62
                        configure(self::SMS);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        }
63
64 50
        $this->mergeConfigFrom($this->getConfigPath(), self::SMS);
65 50
    }
66
67 50
    protected function registerCommands(): void
68
    {
69 50
        $this->app->singleton('command.sms.gateway', SmsSwitchConnectionCommand::class);
70 50
        $this->commands(['command.sms.gateway']);
71 50
    }
72
}
73