FetchCustomersDataFromPaystackApi   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 31 1
1
<?php
2
3
namespace Digikraaft\PaystackCustomersTile;
4
5
use Digikraaft\Paystack\Customer;
6
use Digikraaft\Paystack\Paystack;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Carbon;
9
10
class FetchCustomersDataFromPaystackApi extends Command
11
{
12
    protected $signature = 'dashboard:fetch-customers-data-from-paystack-api';
13
14
    protected $description = 'Fetch data for paystack Customer 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 customers ...');
21
22
        $customers = Customer::list(
23
            config('dashboard.tiles.paystack.customers.params') ?? [
24
                'perPage' => 5,
25
            ]
26
        );
27
28
        $customers = collect($customers->data)
29
            ->map(function ($customer) {
30
                return [
31
                    'first_name' => $customer->first_name,
32
                    'last_name' => $customer->last_name,
33
                    'customer_code' => $customer->customer_code,
34
                    'email' => $customer->email,
35
                    'id' => $customer->id,
36
                    'createdAt' => Carbon::parse($customer->createdAt)
37
                        ->setTimezone('UTC')
38
                        ->format("d.m.Y"),
39
                ];
40
            })->toArray();
41
42
        PaystackCustomersStore::make()->setData($customers);
43
44
        $this->info('All done!');
45
46
        return 0;
47
    }
48
}
49