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

CreateorUpdateTokenFromResponse::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 10
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
use ByTIC\Omnipay\Common\Models\TokenInterface;
6
use ByTIC\Payments\Models\Purchases\Purchase;
7
use ByTIC\Payments\Utility\PaymentsModels;
8
9
/**
10
 * Class CreateorUpdateTokenFromResponse
11
 * @package ByTIC\Payments\Actions\GatewayNotifications
12
 */
13
class CreateorUpdateTokenFromResponse
14
{
15
    /**
16
     * @param $response
17
     * @param Purchase $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
        if (!method_exists($response, 'getToken')) {
24
            return null;
25
        }
26
        $token = $response->getToken();
27
        if (!($token instanceof TokenInterface)) {
28
            return null;
29
        }
30
        return PaymentsModels::tokens()->findOrCreateForMethod($model->getPaymentMethod(), $token);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $model->getPaymentMethod() targeting ByTIC\Payments\Models\Pu...ase::getPaymentMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
Bug Best Practice introduced by
The expression return ByTIC\Payments\Ut...aymentMethod(), $token) also could return the type ByTIC\Payments\Models\Tokens\TokenTrait which is incompatible with the documented return type ByTIC\Payments\Models\Tr...s\AbstractModels\Record.
Loading history...
31
    }
32
}