Passed
Branch master (6e6484)
by Petr
06:04
created

YourMembershipClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 57
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makeCall() 0 10 1
A createSession() 0 6 1
A __construct() 0 8 1
1
<?php
2
3
namespace P2A\YourMembership;
4
5
use GuzzleHttp\Client;
6
use P2A\YourMembership\Core\Request;
7
use P2A\YourMembership\Core\Response;
8
9
class YourMembershipClient
10
{
11
12
    /**
13
     * Guzzle Client
14
     * @var \GuzzleHttp\Client
15
     */
16
    private $client;
17
    /**
18
     * YourMembership Request
19
     * @var Request
20
     */
21
    private $request;
22
23 1
    public function __construct(Client $client, string $apiKey, string $saPasscode)
24
    {
25 1
        $this->client = $client;
26 1
        $this->request = new Request($apiKey, $saPasscode);
27 1
        $sessionID = $this->createSession();
28 1
        Request::setSessionID($sessionID);
29
30 1
    }
31
    /**
32
     * Makes API Call to YourMembership
33
     * @method makeCall
34
     * @author PA
35
     * @date   2017-01-10
36
     * @param  string     $method    Your Membership API Method
37
     * @param  array      $arguments  Your Membership API Call Arguments
38
     * @return Response
39
     */
40 1
    public function makeCall(string $method, array $arguments = [])
41
    {
42
43 1
        Request::$callId++; //Update the Call ID as they need to be unique per call
44 1
        $request = $this->request->buildRequest($method, $arguments);
45
46 1
        $response = $this->client->send($request);
47
48 1
        return new Response($method, $response);
49
    }
50
51
    /**
52
     * Creates a new Session with YourMembership
53
     * @method createSession
54
     * @author PA
55
     * @date   2017-01-10
56
     * @return string        SessionID
57
     */
58 1
    private function createSession() : string
59
    {
60 1
        $response = $this->makeCall('Session.Create')->toObject();
61 1
        return $response->SessionID;
62
63
    }
64
65
}
66