Passed
Push — main ( 1d29da...062801 )
by Garbuz
02:29
created

ServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage;
6
7
use Exception;
8
use GarbuzIvan\LaravelGeneratorPackage\Commands\MakeCommand;
9
use GarbuzIvan\LaravelGeneratorPackage\Form\Field;
10
11
class ServiceProvider extends \Illuminate\Support\ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services...
15
     *
16
     * @return void
17
     */
18 67
    public function boot()
19
    {
20 67
        if ($this->app->runningInConsole()) {
21 67
            $this->commands([
22 67
                MakeCommand::class,
23
            ]);
24
        }
25
26 67
        $configPath = $this->configPath();
27
28 67
        $this->publishes([
29 67
            $configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'),
30 67
        ], 'config');
31
32 67
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
33 67
    }
34
35
    /**
36
     * Register the application services.
37
     *
38
     * @return void
39
     * @throws Exception
40
     */
41 67
    public function register()
42
    {
43
        $this->app->singleton(Configuration::class, function() {
44 67
            return new Configuration;
45 67
        });
46
        $this->app->bind(Field::class, function() {
47 48
            return new Field(app(Configuration::class));
48 67
        });
49 67
    }
50
51
    /**
52
     * @return string
53
     */
54 67
    protected function configPath(): string
55
    {
56 67
        return __DIR__ . '/../config';
57
    }
58
59
    /**
60
     * @param $configFile
61
     * @return string
62
     */
63 67
    protected function publishPath($configFile): string
64
    {
65 67
        return config_path($configFile);
66
    }
67
}
68