Passed
Push — main ( 5926a8...a239d4 )
by Garbuz
03:10
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 17
    public function boot()
20
    {
21 17
        $configPath = $this->configPath();
22
23 17
        $this->publishes([
24 17
            $configPath . '/config.php' => $this->publishPath('laravel-generator-package.php'),
25 17
        ], 'config');
26
27 17
        $this->loadMigrationsFrom(__DIR__ . '/../migrations');
28 17
    }
29
30
    /**
31
     * Register the application services.
32
     *
33
     * @return void
34
     * @throws Exception
35
     */
36 17
    public function register()
37
    {
38
        $this->app->singleton(Configuration::class, function($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

38
        $this->app->singleton(Configuration::class, function(/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39 16
            return new Configuration;
40 17
        });
41
        $this->app->bind(Field::class, function($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
        $this->app->bind(Field::class, function(/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42 15
            return new Field(app(Configuration::class));
43 17
        });
44
        $this->app->bind(Form::class, function($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
        $this->app->bind(Form::class, function(/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45 4
            return new Form(app(Configuration::class));
46 17
        });
47 17
    }
48
49
    /**
50
     * @return string
51
     */
52 17
    protected function configPath(): string
53
    {
54 17
        return __DIR__ . '/../config';
55
    }
56
57
    /**
58
     * @param $configFile
59
     * @return string
60
     */
61 17
    protected function publishPath($configFile): string
62
    {
63 17
        if (function_exists('config_path')) {
64 17
            return config_path($configFile);
65
        } else {
66
            return base_path('config/' . $configFile);
67
        }
68
    }
69
70
    /**
71
     * @param string $class
72
     * @return bool
73
     */
74
    public function isFieldInterface(string $class): bool
75
    {
76
        $implements = class_implements($class);
77
        return isset($implements[FieldInterface::class]);
78
    }
79
}
80