Passed
Push — master ( 96d33b...43186b )
by Gabriel
13:27
created

UpdateSubscriptionFromResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 4
1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
/**
6
 * Class UpdateSubscriptionFromResponse
7
 * @package ByTIC\Payments\Actions\GatewayNotifications
8
 * @internal
9
 */
10
class UpdateSubscriptionFromResponse
11
{
12
    /**
13
     * @param NotificationData $notification
14
     * @return \ByTIC\Payments\Models\Transactions\TransactionTrait|\Nip\Records\AbstractModels\Record
15
     */
16
    public static function handle(NotificationData $notification)
17
    {
18
        if (!is_object($notification->transaction) || $notification->transaction->isSubscription() !== true) {
19
            return null;
20
        }
21
        if (!is_object($notification->token)) {
22
            return null;
23
        }
24
25
        $notification->subscription = $notification->transaction->getSubscription();
26
        $notification->subscription->populateFromToken($notification->token);
27
        $notification->subscription->update();
28
29
        return $notification->subscription;
30
    }
31
}