Passed
Pull Request — master (#36)
by
unknown
04:47
created

MockDataRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 17 4
1
<?php
2
/**
3
 * Copyright © 2016 Magento. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
namespace Pagantis\Pagantis\Gateway\Request;
7
8
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
9
use Magento\Payment\Gateway\Request\BuilderInterface;
10
use Pagantis\Pagantis\Gateway\Http\Client\ClientMock;
11
12
class MockDataRequest implements BuilderInterface
13
{
14
    const FORCE_RESULT = 'FORCE_RESULT';
15
16
    /**
17
     * Builds ENV request
18
     *
19
     * @param array $buildSubject
20
     * @return array
21
     */
22
    public function build(array $buildSubject)
23
    {
24
        if (!isset($buildSubject['payment'])
25
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
26
        ) {
27
            throw new \InvalidArgumentException('Payment data object should be provided');
28
        }
29
30
        /** @var PaymentDataObjectInterface $paymentDO */
31
        $paymentDO = $buildSubject['payment'];
32
        $payment = $paymentDO->getPayment();
33
34
        $transactionResult = $payment->getAdditionalInformation('transaction_result');
35
        return [
36
            self::FORCE_RESULT => $transactionResult === null
37
                ? ClientMock::SUCCESS
38
                : $transactionResult
39
        ];
40
    }
41
}
42