WalletServiceProvider::shouldMigrate()   A
last analyzed

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