UpdateSubscriptionFromResponse::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
use ByTIC\Payments\Actions\Subscriptions\UpdateFromTransactionNotification;
6
7
/**
8
 * Class UpdateSubscriptionFromResponse
9
 * @package ByTIC\Payments\Actions\GatewayNotifications
10
 * @internal
11
 */
12
class UpdateSubscriptionFromResponse
13
{
14
    /**
15
     * @param NotificationData $notification
16
     * @return \ByTIC\Payments\Models\Transactions\TransactionTrait|\Nip\Records\AbstractModels\Record
17
     */
18
    public static function handle(NotificationData $notification)
19
    {
20
        if (!is_object($notification->transaction) || $notification->transaction->isSubscription() !== true) {
21
            return null;
22
        }
23
        $notification->subscription = $notification->transaction->getSubscription();
24
25
        if (is_object($notification->token)) {
26
            $notification->subscription->populateFromToken($notification->token);
27
        }
28
        $notification->subscription->update();
29
30
        UpdateFromTransactionNotification::handle($notification->subscription, $notification->transaction);
31
32
        return $notification->subscription;
33
    }
34
}
35