ResultCommand::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
nc 3
nop 1
dl 0
loc 12
c 1
b 0
f 0
cc 3
rs 10
1
<?php
2
3
namespace Orkhanahmadov\LaravelGoldenpay\Commands;
4
5
use Illuminate\Console\Command;
6
use Orkhanahmadov\LaravelGoldenpay\Goldenpay;
7
use Orkhanahmadov\LaravelGoldenpay\Models\Payment;
8
9
class ResultCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'goldenpay:result {paymentKey?}';
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 Goldenpay $goldenpay
29
     */
30
    public function handle(Goldenpay $goldenpay): void
31
    {
32
        if ($paymentKey = $this->argument('paymentKey')) {
33
            $payment = Payment::where('payment_key', $paymentKey)->firstOrFail();
34
35
            $goldenpay->result($payment);
36
37
            return;
38
        }
39
40
        foreach (Payment::wherePending()->cursor() as $payment) {
41
            $goldenpay->result($payment);
42
        }
43
    }
44
}
45