Issues (193)

CreateOrUpdateTokenFromResponse.php (3 issues)

1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
use ByTIC\Payments\Models\Transactions\TransactionTrait;
6
use ByTIC\Payments\Utility\PaymentsModels;
7
use Nip\Records\AbstractModels\Record;
8
use Paytic\Omnipay\Common\Models\TokenInterface;
9
10
/**
11
 * Class CreateOrUpdateTokenFromResponse
12
 * @package ByTIC\Payments\Actions\GatewayNotifications
13
 * @internal
14
 */
15
class CreateOrUpdateTokenFromResponse
16
{
17
    /**
18
     * @param NotificationData $notification
19
     * @return TransactionTrait|Record
20
     */
21
    public static function handle(NotificationData $notification)
22
    {
23
        if (!method_exists($notification->response, 'getToken')) {
24
            return null;
25
        }
26
27
        $token = $notification->response->getToken();
28
        if (!($token instanceof TokenInterface)) {
29
            return null;
30
        }
31
32
        if (empty($token->getId())) {
33
            return null;
34
        }
35
36
        $notification->token = PaymentsModels::tokens()
37
            ->findOrCreateForMethod($notification->purchase->getPaymentMethod(), $token);
38
        $notification->token->populateFromCustomer($notification->purchase->getPurchaseBillingRecord());
0 ignored issues
show
Are you sure the usage of $notification->purchase-...PurchaseBillingRecord() targeting ByTIC\Payments\Models\Pu...PurchaseBillingRecord() 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...
39
        $notification->token->update();
0 ignored issues
show
The method update() does not exist on ByTIC\Payments\Models\Tokens\TokenTrait. Did you maybe mean updatedTimestamps()? ( Ignorable by Annotation )

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

39
        $notification->token->/** @scrutinizer ignore-call */ 
40
                              update();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        return $notification->token;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $notification->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...
42
    }
43
}
44