CreateTransactionAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 38
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 6 2
A execute() 0 20 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