Passed
Push — master ( 579b04...ee82fc )
by Mykolas
52s queued 11s
created

NotifyAction   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 54.17%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 51
rs 10
ccs 13
cts 24
cp 0.5417
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A execute() 0 26 5
A supports() 0 5 2
1
<?php
2
3
namespace PTS\Paysera\Action;
4
5
use Payum\Core\Action\ActionInterface;
6
use Payum\Core\ApiAwareInterface;
7
use Payum\Core\ApiAwareTrait;
8
use Payum\Core\Bridge\Spl\ArrayObject;
9
use Payum\Core\Exception\RequestNotSupportedException;
10
use Payum\Core\GatewayAwareInterface;
11
use Payum\Core\GatewayAwareTrait;
12
use Payum\Core\Reply\HttpResponse;
13
use Payum\Core\Request\GetHttpRequest;
14
use Payum\Core\Request\Notify;
15
use PTS\Paysera\Api;
16
use PTS\Paysera\MockedApi;
17
18
class NotifyAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
19
{
20
    use ApiAwareTrait;
21
22
    use GatewayAwareTrait;
23
24 25
    public function __construct($mocked = false)
25
    {
26 25
        $mocked ? $this->apiClass = MockedApi::class : $this->apiClass = Api::class;
27 25
    }
28
29
    /**
30
     * @param mixed $request
31
     * @throws \WebToPayException
32
     */
33 7
    public function execute($request)
34
    {
35 7
        RequestNotSupportedException::assertSupports($this, $request);
36
37 1
        $model = ArrayObject::ensureArrayObject($request->getModel());
38
39 1
        $this->gateway->execute($httpRequest = new GetHttpRequest());
40
41 1
        $response = $this->api->doNotify($httpRequest->query);
42
43 1
        if (!$response) {
44 1
            throw new \WebToPayException('Wrong parameters');
45
        }
46
47
        switch ($response['status']) {
48
            case '0':
49
                $model['status'] = 'FAILED';
50
                break;
51
            case '1':
52
                $model['status'] = 'COMPLETED';
53
                break;
54
            case '2':
55
                $model['status'] = 'NOT_EXECUTED';
56
                break;
57
        }
58
        throw new HttpResponse('OK');
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64 15
    public function supports($request)
65
    {
66
        return
67 15
            $request instanceof Notify &&
68 15
            $request->getModel() instanceof \ArrayAccess;
69
    }
70
}
71