ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Noitran\RQL;
6
7
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
8
use Noitran\RQL\Contracts\Processor\ProcessorInterface;
9
use Noitran\RQL\Services\RQLService;
10
11
/**
12
 * Class ServiceProvider.
13
 */
14
class ServiceProvider extends IlluminateServiceProvider
15
{
16 12
    public function boot(): void
17
    {
18 12
        $this->publishConfig();
19 12
    }
20
21
    /**
22
     * Register the service provider.
23
     */
24 12
    public function register(): void
25
    {
26 12
        $this->registerConfig();
27 12
        $this->registerService();
28 12
        $this->bindProcessor();
29 12
    }
30
31
    /**
32
     * @return string
33
     */
34
    protected function getConfigPath(): string
35
    {
36
        return __DIR__ . '/../config/repositories.php';
37
    }
38
39 12
    protected function publishConfig(): void
40
    {
41 12
        $configPath = __DIR__ . '/../config/rql.php';
42 12
        if (\function_exists('config_path')) {
43 12
            $publishPath = config_path('rql.php');
44
        } else {
45
            $publishPath = base_path('config/rql.php');
46
        }
47
48 12
        $this->publishes([$configPath => $publishPath], 'config');
49 12
    }
50
51 12
    protected function registerConfig(): void
52
    {
53 12
        $configPath = __DIR__ . '/../config/rql.php';
54 12
        $this->mergeConfigFrom($configPath, 'rql');
55 12
    }
56
57
    /**
58
     * Bind the RQL service as singleton.
59
     */
60 12
    protected function registerService(): void
61
    {
62 12
        $this->app->singleton(RQLService::class);
63 12
        $this->app->alias(RQLService::class, 'rql');
64 12
    }
65
66
    /**
67
     * Bind ORM implementation to Processor.
68
     */
69 12
    protected function bindProcessor(): void
70
    {
71
        $this->app->bind(ProcessorInterface::class, function () {
72 12
            return rql()->getProcessor();
73 12
        });
74 12
    }
75
}
76