SwivelServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 80
ccs 18
cts 22
cp 0.8182
rs 10
c 1
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A configPath() 0 3 2
A register() 0 8 1
A setupConfig() 0 11 4
A provides() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelSwivel;
6
7
use Illuminate\Contracts\Container\Container;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Foundation\Application as LaravelApplication;
10
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...
11
12
class SwivelServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * The package version.
16
     *
17
     * @var string
18
     */
19
    const VERSION = '2.0.0';
20
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = true;
27
28
    /**
29
     * Bootstrap any application services.
30
     *
31
     * @return void
32
     */
33 2
    public function boot()
34
    {
35 2
        $this->setupConfig($this->app);
36
37 2
        $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
38 2
    }
39
40
    /**
41
     * Register the application services.
42
     *
43
     * @return void
44
     */
45 2
    public function register()
46
    {
47
        $this->app->singleton('swivel', function (Container $app) {
48 2
            $request = $app->make(\Illuminate\Http\Request::class);
49 2
            return new SwivelComponent($request);
50 2
        });
51
52 2
        $this->app->alias('swivel', SwivelComponent::class);
53 2
    }
54
55
    /**
56
     * Returns the configuration path for the component
57
     *
58
     * @return string
59
     */
60 2
    private function configPath()
61
    {
62 2
        return realpath($raw = __DIR__ . '/../config/swivel.php') ?: $raw;
63
    }
64
65
    /**
66
     * Setup the config.
67
     *
68
     * @param \Illuminate\Contracts\Container\Container $app The container
69
     * @return void
70
     */
71 2
    protected function setupConfig(Container $app)
72
    {
73 2
        $source = $this->configPath();
74
75 2
        if ($app instanceof LaravelApplication && $app->runningInConsole()) {
76 2
            $this->publishes([$source => config_path('swivel.php')]);
77
        } elseif ($app instanceof LumenApplication) {
78
            $app->configure('swivel');
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Container\Container. ( Ignorable by Annotation )

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

78
            $app->/** @scrutinizer ignore-call */ 
79
                  configure('swivel');

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...
79
        }
80
81 2
        $this->mergeConfigFrom($source, 'swivel');
82 2
    }
83
84
    /**
85
     * Get the services provided by the provider.
86
     *
87
     * @return array
88
     */
89
    public function provides()
90
    {
91
        return ['swivel'];
92
    }
93
}
94