FetchTransactionsDataFromPaystackApi   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A formatMoney() 0 3 1
A handle() 0 32 1
1
<?php
2
3
namespace Digikraaft\PaystackTransactionsTile;
4
5
use Digikraaft\Paystack\Paystack;
6
use Digikraaft\Paystack\Transaction;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Carbon;
9
10
class FetchTransactionsDataFromPaystackApi extends Command
11
{
12
    protected $signature = 'dashboard:fetch-transactions-data-from-paystack-api';
13
14
    protected $description = 'Fetch data for paystack transactions tile';
15
16
    public function handle()
17
    {
18
        Paystack::setApiKey(config('dashboard.tiles.paystack.secret_key', env('PAYSTACK_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
        Paystack::setApiKey(/** @scrutinizer ignore-call */ config('dashboard.tiles.paystack.secret_key', env('PAYSTACK_SECRET')));
Loading history...
19
20
        $this->info('Fetching Paystack transactions ...');
21
22
        $transactions = Transaction::list(
23
            config('dashboard.tiles.paystack.transactions.params') ?? [
24
                'perPage' => 5,
25
            ]
26
        );
27
28
        $transactions = collect($transactions->data)
29
            ->map(function ($transaction) {
30
                return [
31
                    'amount' => $this->formatMoney($transaction->amount),
32
                    'currency' => $transaction->currency,
33
                    'reference' => $transaction->reference,
34
                    'status' => $transaction->status,
35
                    'customer' => $transaction->customer->email,
36
                    'id' => $transaction->id,
37
                    'createdAt' => Carbon::parse($transaction->created_at)
38
                        ->setTimezone('UTC')
39
                        ->format("d.m.Y"),
40
                ];
41
            })->toArray();
42
43
        PaystackTransactionsStore::make()->setData($transactions);
44
45
        $this->info('All done!');
46
47
        return 0;
48
    }
49
50
    /**
51
     * @param string $amount
52
     * @return float
53
     */
54
    public function formatMoney(string $amount): string
55
    {
56
        return number_format(($amount), 2, '.', ',');
0 ignored issues
show
Bug Best Practice introduced by
The expression return number_format($amount, 2, '.', ',') returns the type string which is incompatible with the documented return type double.
Loading history...
Bug introduced by
$amount of type string is incompatible with the type double expected by parameter $number of number_format(). ( Ignorable by Annotation )

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

56
        return number_format(/** @scrutinizer ignore-type */ ($amount), 2, '.', ',');
Loading history...
57
    }
58
}
59