setPropertyFromResponse()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
c 0
b 0
f 0
nc 3
nop 4
dl 0
loc 10
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Actions\GatewayNotifications;
4
5
use ByTIC\Omnipay\Librapay\Message\ServerCompletePurchaseResponse;
0 ignored issues
show
Bug introduced by
The type ByTIC\Omnipay\Librapay\M...ompletePurchaseResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use ByTIC\Payments\Utility\PaymentsModels;
7
use Omnipay\Common\Message\AbstractResponse;
8
9
/**
10
 * Class CreateOrUpdateTransactionFromResponse
11
 * @package ByTIC\Payments\Actions\GatewayNotifications
12
 * @internal
13
 */
14
class CreateOrUpdateTransactionFromResponse
15
{
16
    /**
17
     * @param $response
18
     * @param $model
19
     * @param $type
20
     * @return \ByTIC\Payments\Models\Transactions\TransactionTrait|\Nip\Records\AbstractModels\Record
21
     */
22
    public static function handle(NotificationData $notification)
23
    {
24
        $notification->transaction = PaymentsModels::transactions()->findOrCreateForPurchase($notification->purchase);
25
26
        static::updateFromResponse($notification->response, $notification->transaction);
0 ignored issues
show
Bug introduced by
It seems like $notification->response can also be of type ByTIC\Payments\Gateways\...sModelProcessedResponse; however, parameter $response of ByTIC\Payments\Actions\G...e::updateFromResponse() does only seem to accept Omnipay\Common\Message\AbstractResponse, maybe add an additional type check? ( Ignorable by Annotation )

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

26
        static::updateFromResponse(/** @scrutinizer ignore-type */ $notification->response, $notification->transaction);
Loading history...
27
        $notification->transaction->status = $notification->purchase->getStatus();
28
29
        $notification->transaction->update();
30
31
        return $notification->transaction;
32
    }
33
34
35
    /**
36
     * @param AbstractResponse|ServerCompletePurchaseResponse $response
37
     * @param $transaction
38
     */
39
    protected static function updateFromResponse(AbstractResponse $response, $transaction)
40
    {
41
        static::setPropertyFromResponse($response, $transaction, 'getCode', 'code');
42
        static::setPropertyFromResponse($response, $transaction, 'getTransactionReference', 'reference');
43
        static::setPropertyFromResponse($response, $transaction, 'getCardMasked', 'card');
44
    }
45
46
    /**
47
     * @param $response
48
     * @param $transaction
49
     * @param $method
50
     * @param $property
51
     */
52
    protected static function setPropertyFromResponse($response, $transaction, $method, $property)
53
    {
54
        if (!method_exists($response, $method)) {
55
            return;
56
        }
57
        $value = $response->{$method}();
58
        if ($value === null || $value === '') {
59
            return;
60
        }
61
        $transaction->{$property} = $value;
62
    }
63
}
64