Passed
Push — master ( 70c8fa...dac2c3 )
by noitran
09:31
created

ServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 9
eloc 21
dl 0
loc 87
ccs 28
cts 32
cp 0.875
rs 10
c 0
b 0
f 0

8 Methods

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