Completed
Push — develop ( 9db14c...3f0e2c )
by Abdelrahman
02:51
created

ContactsServiceProvider::boot()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Contacts\Providers;
6
7
use Illuminate\Support\ServiceProvider;
8
use Rinvex\Contacts\Contracts\ContactContract;
9
use Rinvex\Contacts\Console\Commands\MigrateCommand;
10
11
class ContactsServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * The commands to be registered.
15
     *
16
     * @var array
17
     */
18
    protected $commands = [
19
        MigrateCommand::class => 'command.rinvex.contacts.migrate',
20
    ];
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function register()
26
    {
27
        // Merge config
28
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.contacts');
29
30
        // Bind eloquent models to IoC container
31
        $this->app->singleton('rinvex.contacts.contact', function ($app) {
32
            return new $app['config']['rinvex.contacts.models.contact']();
33
        });
34
        $this->app->alias('rinvex.contacts.contact', ContactContract::class);
35
36
        // Register console commands
37
        ! $this->app->runningInConsole() || $this->registerCommands();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function boot()
44
    {
45
        // Load migrations
46
        ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
47
48
        // Publish Resources
49
        ! $this->app->runningInConsole() || $this->publishResources();
50
    }
51
52
    /**
53
     * Publish resources.
54
     *
55
     * @return void
56
     */
57
    protected function publishResources()
58
    {
59
        $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.contacts.php')], 'rinvex-contacts-config');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
60
        $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-contacts-migrations');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
    }
62
63
    /**
64
     * Register console commands.
65
     *
66
     * @return void
67
     */
68
    protected function registerCommands()
69
    {
70
        // Register artisan commands
71
        foreach ($this->commands as $key => $value) {
72
            $this->app->singleton($value, function ($app) use ($key) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

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

Loading history...
73
                return new $key();
74
            });
75
        }
76
77
        $this->commands(array_values($this->commands));
78
    }
79
}
80