Passed
Push — dev-master ( 6bccf2...881343 )
by Petr
02:20
created

YourMembershipClient::makeCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
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
     * Guzzle Client
13
     * @var \GuzzleHttp\Client
14
     */
15
    private $client;
16
    /**
17
     * YourMembership Request
18
     * @var Request
19
     */
20
    private $request;
21
22 1
    public function __construct(Client $client, string $apiKey, string $saPasscode)
23
    {
24 1
        $this->client = $client;
25 1
        $this->request = new Request($apiKey, $saPasscode);
26 1
        $sessionID = $this->createSession();
27 1
        Request::setSessionID($sessionID);
28
29 1
    }
30
    /**
31
     * Makes API Call to YourMembership
32
     * @method makeCall
33
     * @author PA
34
     * @date   2017-01-10
35
     * @param  string     $method    Your Membership API Method
36
     * @param  array      $arguments  Your Membership API Call Arguments
37
     * @return Response
38
     */
39 1
    public function makeCall(string $method, array $arguments = []) {
40
41 1
        Request::$callId++; //Update the Call ID as they need to be unique per call
42 1
        $request = $this->request->buildRequest($method, $arguments);
43
44 1
        $response = $this->client->send($request);
45
46 1
        return new Response($method, $response);
47
    }
48
49
    /**
50
     * Creates a new Session with YourMembership
51
     * @method createSession
52
     * @author PA
53
     * @date   2017-01-10
54
     * @return string        SessionID
55
     */
56 1
    private function createSession() : string
57
    {
58 1
        $response =  $this->makeCall('Session.Create')->toObject();
59 1
        return $response->SessionID;
60
61
    }
62
63
}
64