Test Failed
Push — master ( 72daf6...986bed )
by Бабичев
03:30
created

WalletServiceProvider::boot()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 23
nc 3
nop 0
dl 0
loc 36
ccs 0
cts 0
cp 0
crap 12
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet;
4
5
use Bavix\Commands\RefreshBalance;
6
use Bavix\Wallet\Models\Transaction;
7
use Bavix\Wallet\Models\Transfer;
8
use Bavix\Wallet\Models\Wallet;
9
use Bavix\Wallet\Services\CommonService;
10
use Bavix\Wallet\Services\ProxyService;
11
use Bavix\Wallet\Services\WalletService;
12
use Illuminate\Support\ServiceProvider;
13
use function config;
14
use function dirname;
15
use function function_exists;
16
17
class WalletServiceProvider extends ServiceProvider
18
{
19
20
    /**
21
     * Bootstrap services.
22
     *
23
     * @return void
24
     * @codeCoverageIgnore
25
     */
26
    public function boot(): void
27
    {
28
        $this->loadTranslationsFrom(
29
            dirname(__DIR__) . '/resources/lang',
30
            'wallet'
31
        );
32
33
        if (!$this->app->runningInConsole()) {
34
            return;
35
        }
36
37
        $this->commands([RefreshBalance::class]);
38
39
        $this->loadMigrationsFrom([
40
            __DIR__ . '/../database/migrations_v1',
41
            __DIR__ . '/../database/migrations_v2',
42
        ]);
43
44
        if (function_exists('config_path')) {
45
            $this->publishes([
46
                dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'),
47
            ], 'laravel-wallet-config');
48
        }
49
50
        $this->publishes([
51
            dirname(__DIR__) . '/database/migrations_v1/' => database_path('migrations'),
52
            dirname(__DIR__) . '/database/migrations_v2/' => database_path('migrations'),
53
        ], 'laravel-wallet-migrations');
54
55
        $this->publishes([
56
            dirname(__DIR__) . '/database/migrations_v1/' => database_path('migrations'),
57
        ], 'laravel-wallet-migrations-v1');
58
59
        $this->publishes([
60
            dirname(__DIR__) . '/database/migrations_v2/' => database_path('migrations'),
61
        ], 'laravel-wallet-migrations-v2');
62
    }
63
64
    /**
65
     * Register services.
66
     *
67
     * @return void
68
     */
69
    public function register(): void
70
    {
71
        $this->mergeConfigFrom(
72
            dirname(__DIR__) . '/config/config.php',
73
            'wallet'
74
        );
75
76
        // Bind eloquent models to IoC container
77
        $this->app->singleton(Transaction::class, config('wallet.transaction.model'));
78
        $this->app->singleton(Transfer::class, config('wallet.transfer.model'));
79
        $this->app->singleton(Wallet::class, config('wallet.wallet.model'));
80
        $this->app->singleton(CommonService::class, config('wallet.services.common'));
81
        $this->app->singleton(ProxyService::class, config('wallet.services.proxy'));
82
        $this->app->singleton(WalletService::class, config('wallet.services.wallet'));
83
    }
84
85
}
86