Completed
Push — master ( 1a7394...cd7830 )
by Abdelrahman
01:17
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 Rinvex\Contacts\Models\Contact;
8
use Illuminate\Support\ServiceProvider;
9
use Rinvex\Contacts\Console\Commands\MigrateCommand;
10
use Rinvex\Contacts\Console\Commands\PublishCommand;
11
use Rinvex\Contacts\Console\Commands\RollbackCommand;
12
13
class ContactsServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * The commands to be registered.
17
     *
18
     * @var array
19
     */
20
    protected $commands = [
21
        MigrateCommand::class => 'command.rinvex.contacts.migrate',
22
        PublishCommand::class => 'command.rinvex.contacts.publish',
23
        RollbackCommand::class => 'command.rinvex.contacts.rollback',
24
    ];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function register()
30
    {
31
        // Merge config
32
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.contacts');
33
34
        // Bind eloquent models to IoC container
35
        $this->app->singleton('rinvex.contacts.contact', $contactModel = $this->app['config']['rinvex.contacts.models.contact']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 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...
36
        $contactModel === Contact::class || $this->app->alias('rinvex.contacts.contact', Contact::class);
37
38
        // Register console commands
39
        ! $this->app->runningInConsole() || $this->registerCommands();
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function boot()
46
    {
47
        // Load migrations
48
        ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
49
50
        // Publish Resources
51
        ! $this->app->runningInConsole() || $this->publishResources();
52
    }
53
54
    /**
55
     * Publish resources.
56
     *
57
     * @return void
58
     */
59
    protected function publishResources(): void
60
    {
61
        $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...
62
        $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...
63
    }
64
65
    /**
66
     * Register console commands.
67
     *
68
     * @return void
69
     */
70
    protected function registerCommands(): void
71
    {
72
        // Register artisan commands
73
        foreach ($this->commands as $key => $value) {
74
            $this->app->singleton($value, $key);
75
        }
76
77
        $this->commands(array_values($this->commands));
78
    }
79
}
80