NotifyServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 5
A register() 0 9 2
A registerNotify() 0 8 1
A registerBladeDirectives() 0 14 1
A provides() 0 6 1
1
<?php
2
3
namespace Yoeunes\Notify;
4
5
use Illuminate\Container\Container;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Support\ServiceProvider;
8
use Laravel\Lumen\Application as LumenApplication;
9
use Illuminate\Foundation\Application as LaravelApplication;
10
11
class NotifyServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application events.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $source = realpath($raw = __DIR__.'/../config/notify.php') ?: $raw;
21
22
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
23
            $this->publishes([$source => config_path('notify.php')], 'config');
24
        } elseif ($this->app instanceof LumenApplication) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
25
            $this->app->configure('notify');
26
        }
27
28
        $this->mergeConfigFrom($source, 'notify');
29
30
        $this->registerBladeDirectives();
31
    }
32
33
    /**
34
     * Register the service provider.
35
     *
36
     * @return void
37
     */
38
    public function register()
39
    {
40
        if ($this->app instanceof LumenApplication) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
41
            $this->app->register(\Illuminate\Session\SessionServiceProvider::class);
42
            $this->app->configure('session');
43
        }
44
45
        $this->registerNotify();
46
    }
47
48
    public function registerNotify()
49
    {
50
        $this->app->singleton('notify', function (Container $app) {
51
            return new Notify(NotifierFactory::make($app['config']['notify']), $app['session'], $app['config']);
52
        });
53
54
        $this->app->alias('notify', Notify::class);
55
    }
56
57
    public function registerBladeDirectives()
58
    {
59
        Blade::directive('notify_render', function () {
60
            return "<?php echo app('notify')->render(); ?>";
61
        });
62
63
        Blade::directive('notify_css', function () {
64
            return '<?php echo notify_css(); ?>';
65
        });
66
67
        Blade::directive('notify_js', function () {
68
            return '<?php echo notify_js(); ?>';
69
        });
70
    }
71
72
    /**
73
     * Get the services provided by the provider.
74
     *
75
     * @return string[]
76
     */
77
    public function provides(): array
78
    {
79
        return [
80
            'notify',
81
        ];
82
    }
83
}
84