SqlDumperServiceProvider::isDeferred()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Cerbero\SqlDumper\Providers;
4
5
use Cerbero\SqlDumper\Dumpers\DumperInterface;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Support\ServiceProvider;
8
9
/**
10
 * The SQL dumper service provider.
11
 *
12
 */
13
class SqlDumperServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * The package configuration path.
17
     *
18
     * @var string
19
     */
20
    protected const CONFIG = __DIR__ . '/../../config/sql_dumper.php';
21
22
    /**
23
     * Indicates if loading of the provider is deferred.
24
     *
25
     * @var bool
26
     */
27
    protected $defer = true;
28
29
    /**
30
     * Bootstrap application services.
31
     *
32
     * @return void
33
     */
34
    public function boot()
35
    {
36
        $this->publishes([static::CONFIG => $this->app->configPath('sql_dumper.php')], 'sql-dumper');
37
    }
38
39
    /**
40
     * Register the bindings
41
     *
42
     * @return void
43
     */
44
    public function register(): void
45
    {
46
        $this->mergeConfigFrom(static::CONFIG, 'sql_dumper');
47
48
        $this->app->bind(DumperInterface::class, function (Application $app) {
49
            $dumper = $this->config('default_dumper');
50
51
            return $app->make($dumper, $this->config($dumper, []));
52
        });
53
    }
54
55
    /**
56
     * Retrieve a configuration value
57
     *
58
     * @param string $key
59
     * @param mixed $default
60
     * @return mixed
61
     */
62
    protected function config(string $key, $default = null)
63
    {
64
        return $this->app->config->get("sql_dumper.{$key}", $default);
0 ignored issues
show
Bug introduced by
Accessing config on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
65
    }
66
67
    /**
68
     * Determine if the provider is deferred.
69
     *
70
     * @return bool
71
     */
72
    public function isDeferred()
73
    {
74
        return $this->defer;
75
    }
76
77
    /**
78
     * Get the services provided by the provider.
79
     *
80
     * @return array
81
     */
82
    public function provides()
83
    {
84
        return [DumperInterface::class];
85
    }
86
}
87