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

YourMembershipClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A makeCall() 0 9 1
A createSession() 0 6 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