GuzzleService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A verifyIpnMessage() 0 20 2
1
<?php
2
3
namespace Mdb\PayPal\Ipn\Service;
4
5
use GuzzleHttp\ClientInterface;
6
use Mdb\PayPal\Ipn\Exception\ServiceException;
7
use Mdb\PayPal\Ipn\Message;
8
use Mdb\PayPal\Ipn\Service;
9
use Mdb\PayPal\Ipn\ServiceResponse;
10
11
class GuzzleService implements Service
12
{
13
    /**
14
     * @var ClientInterface
15
     */
16
    private $httpClient;
17
18
    /**
19
     * @var string
20
     */
21
    private $serviceEndpoint;
22
23
    public function __construct(ClientInterface $httpClient, $serviceEndpoint)
24
    {
25
        $this->httpClient = $httpClient;
26
        $this->serviceEndpoint = $serviceEndpoint;
27
    }
28
29
    public function verifyIpnMessage(Message $message) : ServiceResponse
30
    {
31
        $requestBody = array_merge(
32
            ['cmd' => '_notify-validate'],
33
            $message->getAll()
34
        );
35
36
        try {
37
            $response = $this->httpClient->post(
38
                $this->serviceEndpoint,
39
                ['form_params' => $requestBody]
40
            );
41
        } catch (\Exception $e) {
42
            throw new ServiceException($e->getMessage());
43
        }
44
45
        return new ServiceResponse(
46
            (string) $response->getBody()
47
        );
48
    }
49
}
50