Passed
Push — master ( ca7ad6...579b04 )
by Mykolas
02:00
created

NotifyAction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 48
ccs 16
cts 22
cp 0.7272
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A execute() 0 21 4
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
        switch ($response['status']) {
44 1
            case '0':
45
                $model['status'] = 'FAILED';
46
                break;
47 1
            case '1':
48
                $model['status'] = 'COMPLETED';
49
                throw new HttpResponse('OK');
50
                break;
51 1
            case '2':
52
                $model['status'] = 'NOT_EXECUTED';
53
                break;
54
        }
55
56 1
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 15
    public function supports($request)
62
    {
63
        return
64 15
            $request instanceof Notify &&
65 15
            $request->getModel() instanceof \ArrayAccess;
66
    }
67
}
68