ServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 96.72%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 40
c 4
b 0
f 0
dl 0
loc 103
ccs 59
cts 61
cp 0.9672
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCallbackFactory() 0 7 1
A register() 0 7 1
A registerEventDispatcher() 0 7 1
A boot() 0 9 4
A registerCascadeTransitionCallback() 0 4 1
A registerFactory() 0 11 1
A provides() 0 7 1
A registerCommands() 0 13 1
1
<?php
2
3
namespace Sebdesign\SM;
4
5
use Illuminate\Foundation\Application as LaravelApplication;
6
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
7
use Laravel\Lumen\Application as LumenApplication;
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...
8
use Sebdesign\SM\Callback\ContainerAwareCallback;
9
use Sebdesign\SM\Callback\ContainerAwareCallbackFactory;
10
use Sebdesign\SM\Commands\Debug;
11
use Sebdesign\SM\Commands\Visualize;
12
use Sebdesign\SM\Event\Dispatcher;
13
use Sebdesign\SM\Factory\Factory;
14
use SM\Callback\CallbackFactoryInterface;
15
use SM\Callback\CascadeTransitionCallback;
16
use SM\Factory\FactoryInterface;
17
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18
19
class ServiceProvider extends BaseServiceProvider
20
{
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = false;
27
28
    /**
29
     * Bootstrap the application services.
30
     */
31 171
    public function boot()
32
    {
33 171
        if ($this->app->runningInConsole()) {
34 171
            if ($this->app instanceof LaravelApplication) {
35 171
                $this->publishes([
36 171
                    __DIR__.'/../config/state-machine.php' => config_path('state-machine.php'),
37 171
                ], 'config');
38
            } elseif ($this->app instanceof LumenApplication) {
39
                $this->app->configure('state-machine');
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

39
                $this->app->/** @scrutinizer ignore-call */ 
40
                            configure('state-machine');

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...
40
            }
41
        }
42 57
    }
43
44
    /**
45
     * Register the application services.
46
     */
47 171
    public function register()
48
    {
49 171
        $this->registerCallbackFactory();
50 171
        $this->registerEventDispatcher();
51 171
        $this->registerFactory();
52 171
        $this->registerCascadeTransitionCallback();
53 171
        $this->registerCommands();
54 57
    }
55
56 171
    protected function registerCallbackFactory()
57
    {
58 114
        $this->app->bind('sm.callback.factory', function ($app) {
59 75
            return new ContainerAwareCallbackFactory(ContainerAwareCallback::class, $app);
60 171
        });
61
62 171
        $this->app->alias('sm.callback.factory', CallbackFactoryInterface::class);
63 57
    }
64
65 171
    protected function registerEventDispatcher()
66
    {
67 114
        $this->app->bind('sm.event.dispatcher', function ($app) {
68 99
            return new Dispatcher($app->make('events'));
69 171
        });
70
71 171
        $this->app->alias('sm.event.dispatcher', EventDispatcherInterface::class);
72 57
    }
73
74 171
    protected function registerFactory()
75
    {
76 114
        $this->app->singleton('sm.factory', function ($app) {
77 27
            return new Factory(
78 27
                $app->make('config')->get('state-machine', []),
79 27
                $app->make('sm.event.dispatcher'),
80 27
                $app->make('sm.callback.factory')
81 18
            );
82 171
        });
83
84 171
        $this->app->alias('sm.factory', FactoryInterface::class);
85 57
    }
86
87 171
    protected function registerCascadeTransitionCallback()
88
    {
89 114
        $this->app->bind(CascadeTransitionCallback::class, function ($app) {
90 3
            return new CascadeTransitionCallback($app->make('sm.factory'));
91 171
        });
92 57
    }
93
94 171
    protected function registerCommands()
95
    {
96 114
        $this->app->bind(Debug::class, function ($app) {
97 18
            return new Debug($app->make('config')->get('state-machine', []));
98 171
        });
99
100 114
        $this->app->bind(Visualize::class, function ($app) {
101 15
            return new Visualize($app->make('config')->get('state-machine', []));
102 171
        });
103
104 171
        $this->commands([
105 171
            Debug::class,
106 114
            Visualize::class,
107 114
        ]);
108 57
    }
109
110
    /**
111
     * Get the services provided by the provider.
112
     *
113
     * @return array
114
     */
115 6
    public function provides()
116
    {
117 4
        return [
118 6
            'sm.callback.factory',
119 4
            'sm.event.dispatcher',
120 4
            'sm.factory',
121 4
            Debug::class,
122 4
        ];
123
    }
124
}
125