ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
ccs 8
cts 9
cp 0.8889
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0054
1
<?php
2
3
namespace Noitran\Opendox;
4
5
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6
use Noitran\Opendox\Console\TransformDocsCommand;
7
8
/**
9
 * Class ServiceProvider
10
 */
11
class ServiceProvider extends IlluminateServiceProvider
12
{
13
    /**
14
     * @return string
15
     */
16
    protected function getConfigPath(): string
17
    {
18
        return __DIR__ . '/../config/opendox.php';
19
    }
20
21
    /**
22
     * Add the Cors middleware to the router.
23
     *
24
     * @return void
25
     */
26 4
    public function boot(): void
27
    {
28 4
        $viewPath = __DIR__ . '/../resources/views';
29 4
        $this->loadViewsFrom($viewPath, 'opendox');
30
31 4
        $configPath = __DIR__ . '/../config/opendox.php';
32 4
        if (function_exists('config_path')) {
33 4
            $publishPath = config_path('opendox.php');
34
        } else {
35
            $publishPath = base_path('config/opendox.php');
36
        }
37 4
        $this->publishes([$configPath => $publishPath], 'config');
38
39
        $this->app->router->group(['namespace' => 'Noitran\Opendox'], function ($router): void {
40 4
            require __DIR__ . '/routes/routes.php';
41 4
        });
42 4
    }
43
44
    /**
45
     * Register the service provider.
46
     *
47
     * @return void
48
     */
49 4
    public function register(): void
50
    {
51 4
        $configPath = __DIR__ . '/../config/opendox.php';
52 4
        $this->mergeConfigFrom($configPath, 'opendox');
53
54
        $this->app->singleton('command.opendox.transform-docs', function () {
55 1
            return new TransformDocsCommand();
56 4
        });
57
58 4
        $this->commands(
59 4
            'command.opendox.transform-docs'
60
        );
61 4
    }
62
}
63