Passed
Push — master ( 6514fd...09b598 )
by Бабичев
01:51 queued 12s
created

WalletServiceProvider::shouldMigrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bavix\Wallet;
4
5
use Bavix\Wallet\Commands\RefreshBalance;
6
use Bavix\Wallet\Interfaces\Mathable;
7
use Bavix\Wallet\Interfaces\Rateable;
8
use Bavix\Wallet\Interfaces\Storable;
9
use Bavix\Wallet\Models\Transaction;
10
use Bavix\Wallet\Models\Transfer;
11
use Bavix\Wallet\Models\Wallet;
12
use Bavix\Wallet\Objects\Bring;
13
use Bavix\Wallet\Objects\Cart;
14
use Bavix\Wallet\Objects\EmptyLock;
15
use Bavix\Wallet\Objects\Operation;
16
use Bavix\Wallet\Services\CommonService;
17
use Bavix\Wallet\Services\DbService;
18
use Bavix\Wallet\Services\ExchangeService;
19
use Bavix\Wallet\Services\LockService;
20
use Bavix\Wallet\Simple\Math;
21
use Bavix\Wallet\Services\WalletService;
22
use Bavix\Wallet\Simple\Rate;
23
use Bavix\Wallet\Simple\Store;
24
use Illuminate\Support\ServiceProvider;
25
use function config;
26
use function dirname;
27
use function function_exists;
28
29
class WalletServiceProvider extends ServiceProvider
30
{
31
32
    /**
33
     * Bootstrap services.
34
     *
35
     * @return void
36
     * @codeCoverageIgnore
37
     */
38
    public function boot(): void
39
    {
40
        $this->loadTranslationsFrom(
41
            dirname(__DIR__) . '/resources/lang',
42
            'wallet'
43
        );
44
45
        if (!$this->app->runningInConsole()) {
46
            return;
47
        }
48
49
        $this->commands([RefreshBalance::class]);
50
51
        if ($this->shouldMigrate()) {
52
            $this->loadMigrationsFrom([
53
                __DIR__ . '/../database/migrations_v1',
54
                __DIR__ . '/../database/migrations_v2',
55
            ]);
56
        }
57
58
        if (function_exists('config_path')) {
59
            $this->publishes([
60
                dirname(__DIR__) . '/config/config.php' => config_path('wallet.php'),
61
            ], 'laravel-wallet-config');
62
        }
63
64
        $this->publishes([
65
            dirname(__DIR__) . '/database/migrations_v1/' => database_path('migrations'),
66
            dirname(__DIR__) . '/database/migrations_v2/' => database_path('migrations'),
67
        ], 'laravel-wallet-migrations');
68
69
        $this->publishes([
70
            dirname(__DIR__) . '/database/migrations_v1/' => database_path('migrations'),
71
        ], 'laravel-wallet-migrations-v1');
72
73
        $this->publishes([
74
            dirname(__DIR__) . '/database/migrations_v2/' => database_path('migrations'),
75
        ], 'laravel-wallet-migrations-v2');
76
    }
77
78
    /**
79
     * Register services.
80
     *
81
     * @return void
82
     */
83 169
    public function register(): void
84
    {
85 169
        $this->mergeConfigFrom(
86 169
            dirname(__DIR__) . '/config/config.php',
87 169
            'wallet'
88
        );
89
90
        // Bind eloquent models to IoC container
91 169
        $this->app->singleton(Rateable::class, config('wallet.package.rateable', Rate::class));
92 169
        $this->app->singleton(Storable::class, config('wallet.package.storable', Store::class));
93 169
        $this->app->singleton(Mathable::class, config('wallet.package.mathable', Math::class));
94 169
        $this->app->singleton(DbService::class, config('wallet.services.db', DbService::class));
95 169
        $this->app->singleton(ExchangeService::class, config('wallet.services.exchange', ExchangeService::class));
96 169
        $this->app->singleton(CommonService::class, config('wallet.services.common', CommonService::class));
97 169
        $this->app->singleton(WalletService::class, config('wallet.services.wallet', WalletService::class));
98 169
        $this->app->singleton(LockService::class, config('wallet.services.lock', LockService::class));
99
100
        // models
101 169
        $this->app->bind(Transaction::class, config('wallet.transaction.model', Transaction::class));
102 169
        $this->app->bind(Transfer::class, config('wallet.transfer.model', Transfer::class));
103 169
        $this->app->bind(Wallet::class, config('wallet.wallet.model', Wallet::class));
104
105
        // object's
106 169
        $this->app->bind(Bring::class, config('wallet.objects.bring', Bring::class));
107 169
        $this->app->bind(Cart::class, config('wallet.objects.cart', Cart::class));
108 169
        $this->app->bind(EmptyLock::class, config('wallet.objects.emptyLock', EmptyLock::class));
109 169
        $this->app->bind(Operation::class, config('wallet.objects.operation', Operation::class));
110 169
    }
111
112
    /**
113
     * Determine if we should register the migrations.
114
     *
115
     * @return bool
116
     */
117 169
    protected function shouldMigrate(): bool
118
    {
119 169
        return WalletConfigure::$runsMigrations;
120
    }
121
}
122