Passed
Push — master ( dac2c3...0b9717 )
by noitran
19:24
created

ServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 74
ccs 24
cts 27
cp 0.8889
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerConfig() 0 4 1
A bindProcessor() 0 4 1
A getConfigPath() 0 3 1
A register() 0 5 1
A registerService() 0 4 1
A publishConfig() 0 10 2
A boot() 0 3 1
1
<?php
2
3
namespace Noitran\RQL;
4
5
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6
use Noitran\RQL\Contracts\Processor\ProcessorInterface;
7
use Noitran\RQL\Services\RQLService;
8
9
/**
10
 * Class ServiceProvider
11
 */
12
class ServiceProvider extends IlluminateServiceProvider
13
{
14
    /**
15
     * @return void
16
     */
17 12
    public function boot(): void
18
    {
19 12
        $this->publishConfig();
20 12
    }
21
22
    /**
23
     * Register the service provider.
24
     *
25
     * @return void
26
     */
27 12
    public function register(): void
28
    {
29 12
        $this->registerConfig();
30 12
        $this->registerService();
31 12
        $this->bindProcessor();
32 12
    }
33
34
    /**
35
     * @return string
36
     */
37
    protected function getConfigPath(): string
38
    {
39
        return __DIR__ . '/../config/repositories.php';
40
    }
41
42
    /**
43
     * @return void
44
     */
45 12
    protected function publishConfig(): void
46
    {
47 12
        $configPath = __DIR__ . '/../config/rql.php';
48 12
        if (function_exists('config_path')) {
49 12
            $publishPath = config_path('rql.php');
50
        } else {
51
            $publishPath = base_path('config/rql.php');
52
        }
53
54 12
        $this->publishes([$configPath => $publishPath], 'config');
55 12
    }
56
57
    /**
58
     * @return void
59
     */
60 12
    protected function registerConfig(): void
61
    {
62 12
        $configPath = __DIR__ . '/../config/rql.php';
63 12
        $this->mergeConfigFrom($configPath, 'rql');
64 12
    }
65
66
    /**
67
     * Bind the RQL service as singleton
68
     *
69
     * @return void
70
     */
71 12
    protected function registerService(): void
72
    {
73 12
        $this->app->singleton(RQLService::class);
74 12
        $this->app->alias(RQLService::class, 'rql');
75 12
    }
76
77
    /**
78
     * Bind ORM implementation to Processor
79
     *
80
     * @return void
81
     */
82 12
    protected function bindProcessor(): void
83
    {
84
        $this->app->bind(ProcessorInterface::class, function () {
85 12
            return rql()->getProcessor();
86 12
        });
87 12
    }
88
}
89