Passed
Push — main ( 64366f...2962a2 )
by Garbuz
02:42
created

ServiceProvider::publishPath()   A

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 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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 41
    public function boot()
20
    {
21 41
        if ($this->app->runningInConsole()) {
22 41
            $this->commands([
23 41
                MakeCommand::class,
24
            ]);
25
        }
26
27 41
        $configPath = $this->configPath();
28
29 41
        $this->publishes([
30 41
            $configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'),
31 41
        ], 'config');
32
33 41
        $this->loadMigrationsFrom(__DIR__ . '/../migrations');
34 41
    }
35
36
    /**
37
     * Register the application services.
38
     *
39
     * @return void
40
     * @throws Exception
41
     */
42 41
    public function register()
43
    {
44
        $this->app->singleton(Configuration::class, function() {
45 40
            return new Configuration;
46 41
        });
47
        $this->app->bind(Field::class, function() {
48 23
            return new Field(app(Configuration::class));
49 41
        });
50
        $this->app->bind(Form::class, function() {
51 4
            return new Form(app(Configuration::class));
52 41
        });
53 41
    }
54
55
    /**
56
     * @return string
57
     */
58 41
    protected function configPath(): string
59
    {
60 41
        return __DIR__ . '/../config';
61
    }
62
63
    /**
64
     * @param $configFile
65
     * @return string
66
     */
67 41
    protected function publishPath($configFile): string
68
    {
69 41
        return config_path($configFile);
70
    }
71
}
72