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

YourMembershipClient::makeCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 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