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

ServiceProvider::configPath()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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