Passed
Push — main ( 1646d4...1d29da )
by Garbuz
02:32
created

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 4
b 0
f 0
dl 0
loc 58
ccs 21
cts 22
cp 0.9545
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configPath() 0 3 1
A boot() 0 15 2
A publishPath() 0 3 1
A register() 0 10 1
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
use GarbuzIvan\LaravelGeneratorPackage\Form\Form;
11
12
class ServiceProvider extends \Illuminate\Support\ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services...
16
     *
17
     * @return void
18
     */
19 64
    public function boot()
20
    {
21 64
        if ($this->app->runningInConsole()) {
22 64
            $this->commands([
23 64
                MakeCommand::class,
24
            ]);
25
        }
26
27 64
        $configPath = $this->configPath();
28
29 64
        $this->publishes([
30 64
            $configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'),
31 64
        ], 'config');
32
33 64
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
34 64
    }
35
36
    /**
37
     * Register the application services.
38
     *
39
     * @return void
40
     * @throws Exception
41
     */
42 64
    public function register()
43
    {
44
        $this->app->singleton(Configuration::class, function() {
45 64
            return new Configuration;
46 64
        });
47
        $this->app->bind(Field::class, function() {
48 47
            return new Field(app(Configuration::class));
49 64
        });
50
        $this->app->bind(Form::class, function() {
51
            return new Form(app(Configuration::class));
52 64
        });
53 64
    }
54
55
    /**
56
     * @return string
57
     */
58 64
    protected function configPath(): string
59
    {
60 64
        return __DIR__ . '/../config';
61
    }
62
63
    /**
64
     * @param $configFile
65
     * @return string
66
     */
67 64
    protected function publishPath($configFile): string
68
    {
69 64
        return config_path($configFile);
70
    }
71
}
72