CheckPaymentCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 44
rs 10
c 6
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 23 3
1
<?php
2
3
namespace Orkhanahmadov\YandexCheckout\Commands;
4
5
use Illuminate\Console\Command;
6
use Orkhanahmadov\YandexCheckout\Models\YandexCheckout;
7
use Orkhanahmadov\YandexCheckout\YandexCheckoutService;
8
9
class CheckPaymentCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'yandex-checkout:check {paymentId?}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Checks payment result for given or all pending payments';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @param YandexCheckoutService $yandexCheckoutService
29
     */
30
    public function handle(YandexCheckoutService $yandexCheckoutService): void
31
    {
32
        if ($paymentId = $this->argument('paymentId')) {
33
            $payment = YandexCheckout::where('payment_id', $paymentId)->firstOrFail();
34
35
            $yandexCheckoutService->paymentInfo($payment);
36
37
            $this->output->success("Finished checking Yandex Checkout with payment ID: {$paymentId}");
38
39
            return;
40
        }
41
42
        $pendingCheckouts = YandexCheckout::pending()->get();
43
        $progressBar = $this->output->createProgressBar($pendingCheckouts->count());
44
        $progressBar->start();
45
46
        foreach ($pendingCheckouts as $yandexCheckout) {
47
            $yandexCheckoutService->paymentInfo($yandexCheckout);
48
            $progressBar->advance();
49
        }
50
51
        $progressBar->finish();
52
        $this->output->success('Finished checking all pending Yandex Checkouts');
53
    }
54
}
55