CreateTransactionAction::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 2
1
<?php
2
3
namespace PayumTW\Collect\Action\Api;
4
5
use Payum\Core\Bridge\Spl\ArrayObject;
6
use Payum\Core\Reply\HttpPostRedirect;
7
use PayumTW\Collect\Request\Api\CreateTransaction;
8
use Payum\Core\Exception\RequestNotSupportedException;
9
10
class CreateTransactionAction extends BaseApiAwareAction
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     * @param $request CreateTransaction
16
     */
17 2
    public function execute($request)
18
    {
19 2
        RequestNotSupportedException::assertSupports($this, $request);
20
21 2
        $details = ArrayObject::ensureArrayObject($request->getModel());
22
23 2
        $details->validateNotEmpty(['cust_order_no', 'order_amount', 'order_detail']);
24
25 2
        $params = $this->api->createTransaction((array) $details);
26
27 2
        if (isset($params['status']) === true) {
28 1
            $details->replace($params);
29
30 1
            return;
31
        }
32
33 1
        throw new HttpPostRedirect(
34 1
            $this->api->getApiEndpoint(), $params
35 1
        );
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 2
    public function supports($request)
42
    {
43
        return
44 2
            $request instanceof CreateTransaction &&
45 2
            $request->getModel() instanceof \ArrayAccess;
46
    }
47
}
48