HandlesYandexCheckout::createPayment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Orkhanahmadov\YandexCheckout\Models\Traits;
4
5
use Illuminate\Container\Container;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Orkhanahmadov\YandexCheckout\Models\YandexCheckout;
9
use Orkhanahmadov\YandexCheckout\YandexCheckoutService;
10
use YooKassa\Request\Payments\CreatePaymentRequestInterface;
11
12
/**
13
 * Trait Payable.
14
 *
15
 * @mixin Model
16
 */
17
trait HandlesYandexCheckout
18
{
19
    public function yandexCheckouts(): MorphMany
20
    {
21
        return $this->morphMany(YandexCheckout::class, 'payable');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        return $this->/** @scrutinizer ignore-call */ morphMany(YandexCheckout::class, 'payable');
Loading history...
22
    }
23
24
    /**
25
     * @param  CreatePaymentRequestInterface|array  $paymentRequest
26
     * @param  string|null  $idempotenceKey
27
     * @return YandexCheckout
28
     */
29
    public function createPayment($paymentRequest, ?string $idempotenceKey = null): YandexCheckout
30
    {
31
        /** @var YandexCheckoutService $yandexCheckout */
32
        $yandexCheckout = Container::getInstance()->make(YandexCheckoutService::class);
33
34
        return $yandexCheckout->createPayment(
35
            $this,
0 ignored issues
show
Bug introduced by
$this of type Orkhanahmadov\YandexChec...s\HandlesYandexCheckout is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of Orkhanahmadov\YandexChec...ervice::createPayment(). ( Ignorable by Annotation )

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

35
            /** @scrutinizer ignore-type */ $this,
Loading history...
36
            $paymentRequest,
37
            $idempotenceKey ?? $this->yandexCheckoutIdempotenceKey()
38
        );
39
    }
40
41
    public function yandexCheckoutIdempotenceKey(): ?string
42
    {
43
        return "{$this->getTable()}-{$this->getKey()}";
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
        return "{$this->getTable()}-{$this->/** @scrutinizer ignore-call */ getKey()}";
Loading history...
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
        return "{$this->/** @scrutinizer ignore-call */ getTable()}-{$this->getKey()}";
Loading history...
44
    }
45
}
46