Passed
Push — master ( c0f464...9c6e80 )
by Gabriel
11:21
created

CreateOrUpdateTransactionFromResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A updateTransaction() 0 13 3
1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
use ByTIC\Omnipay\Librapay\Message\ServerCompletePurchaseResponse;
6
use ByTIC\Payments\Utility\PaymentsModels;
7
use Omnipay\Common\Message\AbstractResponse;
8
9
/**
10
 * Class CreateOrUpdateTransactionFromResponse
11
 * @package ByTIC\Payments\Actions\GatewayNotifications
12
 */
13
class CreateOrUpdateTransactionFromResponse
14
{
15
    /**
16
     * @param $response
17
     * @param $model
18
     * @param $type
19
     * @return \ByTIC\Payments\Models\Transactions\TransactionTrait|\Nip\Records\AbstractModels\Record
20
     */
21
    public static function handle($response, $model, $type)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

21
    public static function handle($response, $model, /** @scrutinizer ignore-unused */ $type)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        $transaction = PaymentsModels::transactions()->findOrCreateForPurchase($model);
24
        static::updateTransaction($response, $transaction);
25
        return $transaction;
26
    }
27
28
29
    /**
30
     * @param AbstractResponse|ServerCompletePurchaseResponse $response
31
     * @param $transaction
32
     */
33
    protected static function updateTransaction(AbstractResponse $response, $transaction)
34
    {
35
        $code = $response->getCode();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $code is correct as $response->getCode() targeting Omnipay\Common\Message\AbstractResponse::getCode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
        if ($code) {
0 ignored issues
show
introduced by
$code is of type null, thus it always evaluated to false.
Loading history...
37
            $transaction->code = $code;
38
        }
39
40
        $reference = $response->getTransactionReference();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $reference is correct as $response->getTransactionReference() targeting Omnipay\Common\Message\A...tTransactionReference() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
        if ($reference) {
0 ignored issues
show
introduced by
$reference is of type null, thus it always evaluated to false.
Loading history...
42
            $transaction->reference = $reference;
43
        }
44
45
        $transaction->update();
46
    }
47
}