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

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 4
b 0
f 0
dl 0
loc 55
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 15 2
A register() 0 7 1
A configPath() 0 3 1
A publishPath() 0 3 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
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