Passed
Push — main ( 317075...c1e860 )
by Garbuz
02:43
created

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 3
b 0
f 0
dl 0
loc 55
ccs 20
cts 21
cp 0.9524
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 10 1
A configPath() 0 3 1
A publishPath() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage;
6
7
use Exception;
8
use GarbuzIvan\LaravelGeneratorPackage\Contracts\FieldInterface;
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 24
    public function boot()
20
    {
21 24
        $configPath = $this->configPath();
22
23 24
        $this->publishes([
24 24
            $configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'),
25 24
        ], 'config');
26
27 24
        $this->loadMigrationsFrom(__DIR__ . '/../migrations');
28 24
    }
29
30
    /**
31
     * Register the application services.
32
     *
33
     * @return void
34
     * @throws Exception
35
     */
36 24
    public function register()
37
    {
38
        $this->app->singleton(Configuration::class, function() {
39 22
            return new Configuration;
40 24
        });
41
        $this->app->bind(Field::class, function() {
42 18
            return new Field(app(Configuration::class));
43 24
        });
44
        $this->app->bind(Form::class, function() {
45 4
            return new Form(app(Configuration::class));
46 24
        });
47 24
    }
48
49
    /**
50
     * @return string
51
     */
52 24
    protected function configPath(): string
53
    {
54 24
        return __DIR__ . '/../config';
55
    }
56
57
    /**
58
     * @param $configFile
59
     * @return string
60
     */
61 24
    protected function publishPath($configFile): string
62
    {
63 24
        if (function_exists('config_path')) {
64 24
            return config_path($configFile);
65
        } else {
66
            return base_path('config/' . $configFile);
67
        }
68
    }
69
}
70