ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.9
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace GoCardlessPayment;
4
5
use GoCardlessPayment\Console\Commands\ImportMandate;
6
use GoCardlessPayment\Contracts\LocalCustomerRepository;
7
use GoCardlessPayment\Repositories\LocalCustomerEloquentRepository;
8
use Illuminate\Contracts\Foundation\Application;
9
10
class ServiceProvider extends \Illuminate\Support\ServiceProvider
11
{
12 12
    public function boot()
13
    {
14 12
        $this->registerRoutes();
15
16 12
        if ($this->app->runningInConsole()) {
17 12
            $this->publishes([
18 12
                __DIR__.'/../config/gocardless-payment.php' => config_path('gocardless-payment.php'),
19 12
            ], 'config');
20
21 12
            $this->publishes([
22 12
                __DIR__.'/../database/migrations' => $this->app->databasePath('migrations'),
23 12
            ], 'migrations');
24
25 12
            $this->registerMigrations();
26
27 12
            $this->commands([
28 12
                ImportMandate::class,
29 12
            ]);
30
        }
31
32
    }
33
34 12
    public function register()
35
    {
36 12
        $this->mergeConfigFrom(__DIR__.'/../config/gocardless-payment.php', 'gocardless-payment');
37
38 12
        $this->app->singletonIf(LocalCustomerRepository::class, function (Application $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

38
        $this->app->singletonIf(LocalCustomerRepository::class, function (/** @scrutinizer ignore-unused */ Application $app) {

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

Loading history...
39 8
            return new LocalCustomerEloquentRepository(
40 8
                config('gocardless-payment.local_customer_repositories.eloquent.model'),
41 8
                config('gocardless-payment.local_customer_repositories.eloquent.key'),
42 8
            );
43 12
        });
44 12
        $this->app->bindIf(Api::class, function (Application $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

44
        $this->app->bindIf(Api::class, function (/** @scrutinizer ignore-unused */ Application $app) {

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

Loading history...
45 1
            return new Api(
46 1
                config('gocardless-payment.access_token'),
47 1
                config('gocardless-payment.environment'),
48 1
            );
49 12
        });
50
    }
51
52 12
    protected function registerMigrations(): void
53
    {
54 12
        if (GoCardlessPayment::$runsMigrations) {
55 12
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
56
        }
57
    }
58
59 12
    protected function registerRoutes(): void
60
    {
61 12
        if (! GoCardlessPayment::$useRoutes) {
62
            return;
63
        }
64
65 12
        \Illuminate\Support\Facades\Route::group([
66 12
            'prefix' => config('gocardless-payment.web.path_prefix'),
67 12
            'as' => 'gocardless-payment.',
68 12
        ], function () {
69 12
            $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
70 12
        });
71
    }
72
}
73