ServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 95
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A registerPublishes() 0 16 2
A boot() 0 9 1
A registerViews() 0 3 1
A registerRoutes() 0 19 1
A registerMiddleware() 0 3 1
A register() 0 3 1
1
<?php
2
3
namespace Spinen\QuickBooks\Providers;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
7
use Spinen\QuickBooks\Http\Middleware\Filter;
8
9
/**
10
 * Class ServiceProvider
11
 *
12
 * @package Spinen\QuickBooks
13
 */
14
class ServiceProvider extends LaravelServiceProvider
15
{
16
    /**
17
     * Bootstrap the application services.
18
     *
19
     * @return void
20
     */
21
    public function boot()
22
    {
23
        $this->registerMiddleware();
24
25
        $this->registerPublishes();
26
27
        $this->registerRoutes();
28
29
        $this->registerViews();
30
    }
31
32
    /**
33
     * Register the application services.
34
     *
35
     * @return void
36
     */
37
    public function register()
38
    {
39
        $this->mergeConfigFrom(__DIR__ . '/../../config/quickbooks.php', 'quickbooks');
40
    }
41
42
    /**
43
     * Register the middleware
44
     *
45
     * If a route needs to have the QuickBooks client, then make sure that the user has linked their account.
46
     *
47
     */
48
    public function registerMiddleware()
49
    {
50
        $this->app->router->aliasMiddleware('quickbooks', Filter::class);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
51
    }
52
53
    /**
54
     * There are several resources that get published
55
     *
56
     * Only worry about telling the application about them if running in the console.
57
     *
58
     */
59
    protected function registerPublishes()
60
    {
61
        if ($this->app->runningInConsole()) {
62
            $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
63
64
            $this->publishes([
65
                __DIR__ . '/../../config/quickbooks.php' => config_path('quickbooks.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

65
                __DIR__ . '/../../config/quickbooks.php' => /** @scrutinizer ignore-call */ config_path('quickbooks.php'),
Loading history...
66
            ], 'quickbooks-config');
67
68
            $this->publishes([
69
                __DIR__ . '/../../database/migrations' => database_path('migrations'),
0 ignored issues
show
Bug introduced by
The function database_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

69
                __DIR__ . '/../../database/migrations' => /** @scrutinizer ignore-call */ database_path('migrations'),
Loading history...
70
            ], 'quickbooks-migrations');
71
72
            $this->publishes([
73
                __DIR__ . '/../../resources/views' => base_path('resources/views/vendor/quickbooks'),
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

73
                __DIR__ . '/../../resources/views' => /** @scrutinizer ignore-call */ base_path('resources/views/vendor/quickbooks'),
Loading history...
74
            ], 'quickbooks-views');
75
        }
76
    }
77
78
    /**
79
     * Register the routes needed for the registration flow
80
     */
81
    protected function registerRoutes()
82
    {
83
        $config = $this->app->config->get('quickbooks.route');
0 ignored issues
show
Bug introduced by
Accessing config on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
84
85
        $this->app->router->prefix($config['prefix'])
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
86
                          ->as('quickbooks.')
87
                          ->middleware($config['middleware']['default'])
88
                          ->namespace('Spinen\QuickBooks\Http\Controllers')
89
                          ->group(function (Router $router) use ($config) {
90
                              $router->get($config['paths']['connect'], 'Controller@connect')
91
                                     ->middleware($config['middleware']['authenticated'])
92
                                     ->name('connect');
93
94
                              $router->delete($config['paths']['disconnect'], 'Controller@disconnect')
95
                                     ->middleware($config['middleware']['authenticated'])
96
                                     ->name('disconnect');
97
98
                              $router->get($config['paths']['token'], 'Controller@token')
99
                                     ->name('token');
100
                          });
101
    }
102
103
    /**
104
     * Register the views
105
     */
106
    protected function registerViews()
107
    {
108
        $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'quickbooks');
109
    }
110
}
111