Completed
Push — develop ( 895c33...0b7f85 )
by Abdelrahman
11:28
created

ContactsServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 15
Bugs 0 Features 0
Metric Value
wmc 7
c 15
b 0
f 0
lcom 1
cbo 4
dl 0
loc 87
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 2
A boot() 0 23 2
A publishResources() 0 5 1
A registerCommands() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\Providers;
6
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
use Rinvex\Contacts\Contracts\ContactContract;
10
use Cortex\Contacts\Console\Commands\SeedCommand;
11
use Cortex\Contacts\Console\Commands\InstallCommand;
12
use Cortex\Contacts\Console\Commands\MigrateCommand;
13
use Cortex\Contacts\Console\Commands\PublishCommand;
14
use Illuminate\Database\Eloquent\Relations\Relation;
15
use Cortex\Contacts\Console\Commands\RollbackCommand;
16
17
class ContactsServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * The commands to be registered.
21
     *
22
     * @var array
23
     */
24
    protected $commands = [
25
        SeedCommand::class => 'command.cortex.contacts.seed',
26
        InstallCommand::class => 'command.cortex.contacts.install',
27
        MigrateCommand::class => 'command.cortex.contacts.migrate',
28
        PublishCommand::class => 'command.cortex.contacts.publish',
29
        RollbackCommand::class => 'command.cortex.contacts.rollback',
30
    ];
31
32
    /**
33
     * Register any application services.
34
     *
35
     * This service provider is a great spot to register your various container
36
     * bindings with the application. As you can see, we are registering our
37
     * "Registrar" implementation here. You can add your own bindings too!
38
     *
39
     * @return void
40
     */
41
    public function register()
42
    {
43
        // Register console commands
44
        ! $this->app->runningInConsole() || $this->registerCommands();
45
    }
46
47
    /**
48
     * Bootstrap any application services.
49
     *
50
     * @return void
51
     */
52
    public function boot(Router $router)
53
    {
54
        // Bind route models and constrains
55
        $router->pattern('contact', '[0-9]+');
56
        $router->model('contact', ContactContract::class);
57
58
        // Map relations
59
        Relation::morphMap([
60
            'contact' => config('rinvex.contacts.models.contact'),
61
        ]);
62
63
        // Load resources
64
        require __DIR__.'/../../routes/breadcrumbs.php';
65
        $this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
66
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/contacts');
67
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/contacts');
68
        $this->app->afterResolving('blade.compiler', function () {
69
            require __DIR__.'/../../routes/menus.php';
70
        });
71
72
        // Publish Resources
73
        ! $this->app->runningInConsole() || $this->publishResources();
74
    }
75
76
    /**
77
     * Publish resources.
78
     *
79
     * @return void
80
     */
81
    protected function publishResources()
82
    {
83
        $this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/contacts')], 'cortex-contacts-lang');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 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...
84
        $this->publishes([realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/contacts')], 'cortex-contacts-views');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 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...
85
    }
86
87
    /**
88
     * Register console commands.
89
     *
90
     * @return void
91
     */
92
    protected function registerCommands()
93
    {
94
        // Register artisan commands
95
        foreach ($this->commands as $key => $value) {
96
            $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...
97
                return new $key();
98
            });
99
        }
100
101
        $this->commands(array_values($this->commands));
102
    }
103
}
104