ConvertPaymentAction::supports()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
namespace PayumTW\Collect\Action;
4
5
use Payum\Core\Request\Convert;
6
use Payum\Core\Action\ActionInterface;
7
use Payum\Core\Bridge\Spl\ArrayObject;
8
use Payum\Core\Model\PaymentInterface;
9
use Payum\Core\Exception\RequestNotSupportedException;
10
11
class ConvertPaymentAction implements ActionInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     *
16
     * @param Convert $request
17
     */
18 1
    public function execute($request)
19
    {
20 1
        RequestNotSupportedException::assertSupports($this, $request);
21
22
        /** @var PaymentInterface $payment */
23 1
        $payment = $request->getSource();
24
25 1
        $details = ArrayObject::ensureArrayObject($payment->getDetails());
26
27 1
        $details['cust_order_no'] = $payment->getNumber();
28 1
        $details['order_amount'] = $payment->getTotalAmount();
29 1
        $details['order_detail'] = $payment->getDescription();
30
31
        // CVS
32 1
        $details['cust_order_number'] = $details['cust_order_no'];
33 1
        $details['payer_email'] = $payment->getClientEmail();
34
35 1
        $request->setResult((array) $details);
36 1
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function supports($request)
42
    {
43
        return
44 1
            $request instanceof Convert &&
45 1
            $request->getSource() instanceof PaymentInterface &&
46 1
            $request->getTo() == 'array';
47
    }
48
}
49