Passed
Push — master ( 19a915...d9efc8 )
by Gabriel
14:56
created

ChargeWithToken   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 20 2
1
<?php
2
3
namespace ByTIC\Payments\Actions\Transactions;
4
5
use ByTIC\Payments\Actions\GatewayNotifications\UpdatePaymentModelsFromResponse;
6
use ByTIC\Payments\Exception\RequestNotSupportedException;
7
use ByTIC\Payments\Models\Transactions\Transaction;
8
use Omnipay\Common\Message\AbstractResponse;
9
10
/**
11
 * Class ChargeWithToken
12
 * @package ByTIC\Payments\Actions\Transactions
13
 */
14
class ChargeWithToken
15
{
16
    /**
17
     * @param Transaction $transaction
18
     */
19
    public static function process($transaction)
20
    {
21
        $purchase = $transaction->getPurchase();
22
        $method = $transaction->getPaymentMethod();
23
        $gateway = $method->getGateway();
24
25
        if (!method_exists($gateway, 'purchaseWithToken')) {
26
            throw RequestNotSupportedException::create('purchaseWithToken', $gateway);
0 ignored issues
show
Bug introduced by
$gateway of type ByTIC\Payments\Gateways\...way\Traits\GatewayTrait is incompatible with the type Omnipay\Common\AbstractGateway|null expected by parameter $gateway of ByTIC\Payments\Exception...rtedException::create(). ( Ignorable by Annotation )

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

26
            throw RequestNotSupportedException::create('purchaseWithToken', /** @scrutinizer ignore-type */ $gateway);
Loading history...
27
        }
28
29
        $parameters = $purchase->getPurchaseParameters();
30
        $parameters['token'] = $transaction->getToken()->getTokenId();
31
32
        /** @var AbstractResponse $response */
33
        $response = $gateway->purchaseWithToken($parameters);
0 ignored issues
show
Bug introduced by
The method purchaseWithToken() does not exist on ByTIC\Payments\Gateways\...way\Traits\GatewayTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

33
        /** @scrutinizer ignore-call */ 
34
        $response = $gateway->purchaseWithToken($parameters);
Loading history...
34
35
        $response->processModel();
0 ignored issues
show
Bug introduced by
The method processModel() does not exist on Omnipay\Common\Message\AbstractResponse. It seems like you code against a sub-type of Omnipay\Common\Message\AbstractResponse such as ByTIC\Payments\Stripe\Me...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Common\Payments\Ga...ompletePurchaseResponse or ByTIC\Common\Payments\Ga...ompletePurchaseResponse or ByTIC\Payments\Mobilpay\...ompletePurchaseResponse or ByTIC\Payments\Mobilpay\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse or ByTIC\Payments\Gateways\...ompletePurchaseResponse. ( Ignorable by Annotation )

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

35
        $response->/** @scrutinizer ignore-call */ 
36
                   processModel();
Loading history...
36
        UpdatePaymentModelsFromResponse::handle($response, $model, 'IPN');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $model seems to be never defined.
Loading history...
37
38
        return $response;
39
    }
40
}