FetchBalancesDataFromStripeApi::toReadableAmount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Digikraaft\StripeBalancesTile;
4
5
use Illuminate\Console\Command;
6
use Stripe\Balance;
7
use Stripe\Stripe;
8
9
class FetchBalancesDataFromStripeApi extends Command
10
{
11
    protected $signature = 'dashboard:fetch-balances-data-from-stripe-api';
12
13
    protected $description = 'Fetch data for Stripe balances tile';
14
15
    public function handle()
16
    {
17
        Stripe::setApiKey(
18
            config('dashboard.tiles.stripe.secret_key', env('STRIPE_SECRET'))
0 ignored issues
show
Bug introduced by
The function config 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

18
            /** @scrutinizer ignore-call */ 
19
            config('dashboard.tiles.stripe.secret_key', env('STRIPE_SECRET'))
Loading history...
19
        );
20
21
        $this->info('Fetching Stripe balances ...');
22
23
        $balances = Balance::retrieve();
24
25
        $balances = collect($balances->available)
26
            ->map(function ($balance) {
27
                return [
28
                    'amount' => $this->toReadableAmount($balance->amount),
29
                    'currency' => strtoupper($balance->currency),
30
                ];
31
            })->toArray();
32
33
        StripeBalancesStore::make()->setData($balances);
34
35
        $this->info('All done!');
36
37
        return 0;
38
    }
39
40
    public function toReadableAmount($baseAmount)
41
    {
42
        return $baseAmount / 100;
43
    }
44
}
45