Completed
Pull Request — master (#12)
by
unknown
12:56 queued 11:16
created

AcceptNotificationRequest::sendData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Omnipay\Paysera\Message;
4
5
use Omnipay\Paysera\Common\Encoder;
6
use Omnipay\Paysera\Common\Signature;
7
use Omnipay\Common\Exception\InvalidRequestException;
8
9
class AcceptNotificationRequest extends AbstractRequest
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 7
    public function getData()
15
    {
16
        return [
17 7
            'data' => $this->httpRequest->get('data'),
18 7
            'ss1' => $this->httpRequest->get('ss1'),
19 7
            'ss2' => $this->httpRequest->get('ss2'),
20
        ];
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     *
26
     * @return \Omnipay\Paysera\Message\AcceptNotificationResponse
27
     *
28
     * @throws \Omnipay\Common\Exception\InvalidRequestException
29
     * @throws \Omnipay\Common\Exception\InvalidResponseException
30
     */
31 7
    public function sendData($data)
32
    {
33 7
        if (! Signature::isValid($data, $this->getPassword(), $this->httpClient)) {
34 3
            throw new InvalidRequestException('The signature is invalid.');
35
        }
36
37 4
        $this->response = new AcceptNotificationResponse($this, $this->parseData($data['data']));
38
39 3
        return $this->response;
40
    }
41
42
    /**
43
     * Parse the data.
44
     *
45
     * @param  string  $data
46
     * @return array
47
     */
48 4
    protected function parseData($data)
49
    {
50 4
        $parameters = [];
51
52 4
        parse_str(Encoder::decode($data), $parameters);
53
54 4
        return ! is_null($parameters) ? $parameters : [];
55
    }
56
}
57