StatisticsServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Statistics\Providers;
6
7
use Illuminate\Routing\Router;
8
use Rinvex\Statistics\Models\Path;
9
use Rinvex\Statistics\Models\Agent;
10
use Rinvex\Statistics\Models\Datum;
11
use Rinvex\Statistics\Models\Geoip;
12
use Rinvex\Statistics\Models\Route;
13
use Rinvex\Statistics\Models\Device;
14
use Rinvex\Statistics\Models\Request;
15
use Rinvex\Statistics\Models\Platform;
16
use Illuminate\Support\ServiceProvider;
17
use Rinvex\Support\Traits\ConsoleTools;
18
use Rinvex\Statistics\Console\Commands\MigrateCommand;
19
use Rinvex\Statistics\Console\Commands\PublishCommand;
20
use Rinvex\Statistics\Http\Middleware\TrackStatistics;
21
use Rinvex\Statistics\Console\Commands\RollbackCommand;
22
23
class StatisticsServiceProvider extends ServiceProvider
24
{
25
    use ConsoleTools;
26
27
    /**
28
     * The commands to be registered.
29
     *
30
     * @var array
31
     */
32
    protected $commands = [
33
        MigrateCommand::class => 'command.rinvex.statistics.migrate',
34
        PublishCommand::class => 'command.rinvex.statistics.publish',
35
        RollbackCommand::class => 'command.rinvex.statistics.rollback',
36
    ];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function register()
42
    {
43
        // Merge config
44
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.statistics');
45
46
        // Bind eloquent models to IoC container
47
        $this->app->singleton('rinvex.statistics.datum', $datumModel = $this->app['config']['rinvex.statistics.models.datum']);
48
        $datumModel === Datum::class || $this->app->alias('rinvex.statistics.datum', Datum::class);
49
50
        $this->app->singleton('rinvex.statistics.request', $requestModel = $this->app['config']['rinvex.statistics.models.request']);
51
        $requestModel === Request::class || $this->app->alias('rinvex.statistics.request', Request::class);
52
53
        $this->app->singleton('rinvex.statistics.agent', $agentModel = $this->app['config']['rinvex.statistics.models.agent']);
54
        $agentModel === Agent::class || $this->app->alias('rinvex.statistics.agent', Agent::class);
55
56
        $this->app->singleton('rinvex.statistics.geoip', $geoipModel = $this->app['config']['rinvex.statistics.models.geoip']);
57
        $geoipModel === Geoip::class || $this->app->alias('rinvex.statistics.geoip', Geoip::class);
58
59
        $this->app->singleton('rinvex.statistics.route', $routeModel = $this->app['config']['rinvex.statistics.models.route']);
60
        $routeModel === Route::class || $this->app->alias('rinvex.statistics.route', Route::class);
61
62
        $this->app->singleton('rinvex.statistics.device', $deviceModel = $this->app['config']['rinvex.statistics.models.device']);
63
        $deviceModel === Device::class || $this->app->alias('rinvex.statistics.device', Device::class);
64
65
        $this->app->singleton('rinvex.statistics.platform', $platformModel = $this->app['config']['rinvex.statistics.models.platform']);
66
        $platformModel === Platform::class || $this->app->alias('rinvex.statistics.platform', Platform::class);
67
68
        $this->app->singleton('rinvex.statistics.path', $pathModel = $this->app['config']['rinvex.statistics.models.path']);
69
        $pathModel === Path::class || $this->app->alias('rinvex.statistics.path', Path::class);
70
71
        // Register console commands
72
        $this->registerCommands($this->commands);
0 ignored issues
show
Unused Code introduced by
The call to StatisticsServiceProvider::registerCommands() has too many arguments starting with $this->commands.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function boot(Router $router)
79
    {
80
        // Publish Resources
81
        $this->publishesConfig('rinvex/laravel-statistics');
82
        $this->publishesMigrations('rinvex/laravel-statistics');
83
        ! $this->autoloadMigrations('rinvex/laravel-statistics') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
84
85
        // Push middleware to web group
86
        $router->pushMiddlewareToGroup('web', TrackStatistics::class);
87
    }
88
}
89