Passed
Push — master ( 1828fb...5ac899 )
by Zing
06:56
created

SmsServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 97.14%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 8
eloc 26
c 3
b 1
f 0
dl 0
loc 59
ccs 34
cts 35
cp 0.9714
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 3
A registerCommands() 0 6 1
A getConfigPath() 0 3 1
A register() 0 21 1
A registerConfig() 0 7 2
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 48
    public function boot(): void
22
    {
23 48
        if ($this->app->runningInConsole() && $this->app instanceof Laravel) {
24 48
            $this->publishes(
25
                [
26 48
                    $this->getConfigPath() => config_path('sms.php'),
27
                ],
28 48
                'config'
29
            );
30
        }
31 48
    }
32
33 48
    public function register(): void
34
    {
35 48
        $this->registerConfig();
36 48
        Notification::resolved(
37 48
            function (ChannelManager $service): void {
38 9
                $service->extend(
39 9
                    self::SMS,
40 9
                    function (Container $app) {
41 2
                        return $app->make(SmsChannel::class);
42 9
                    }
43
                );
44 48
            }
45
        );
46 48
        $this->app->singleton(
47 48
            self::SMS,
48 48
            function (Container $app) {
49 12
                return $app->make(SmsManager::class);
50 48
            }
51
        );
52 48
        $this->app->alias(self::SMS, Sms::class);
53 48
        $this->registerCommands();
54 48
    }
55
56 48
    protected function getConfigPath(): string
57
    {
58 48
        return __DIR__ . '/../config/sms.php';
59
    }
60
61 48
    protected function registerConfig(): void
62
    {
63 48
        if ($this->app instanceof Lumen) {
64
            $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

64
            $this->app->/** @scrutinizer ignore-call */ 
65
                        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...
65
        }
66
67 48
        $this->mergeConfigFrom($this->getConfigPath(), self::SMS);
68 48
    }
69
70 48
    protected function registerCommands(): void
71
    {
72 48
        $this->app->singleton('command.sms.gateway', SmsSwitchConnectionCommand::class);
73 48
        $this->commands(
74
            [
75 48
                'command.sms.gateway',
76
            ]
77
        );
78 48
    }
79
}
80