Completed
Push — master ( 363a2f...20dbe7 )
by Tyler
02:43
created

PeopleMatter::getClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Zenapply\PeopleMatter;
4
5
use GuzzleHttp\Client;
6
7
class PeopleMatter
8
{
9
    const V3 = 'v3';
10
11
    protected $host;
12
    protected $version;
13
    protected $client;
14
    protected $token;
15
16
    /**
17
     * Creates a PeopleMatter instance that can register and unregister webhooks with the API
18
     * @param string      $username The Username
19
     * @param string      $password The Password
20
     * @param string      $alias    The business alias
21
     * @param string      $host     The host to connect to
22
     * @param Client|null $client   The Guzzle client (used for testing)
23
     */
24 3
    public function __construct($username, $password, $alias, $host = "api.peoplematter.com", Client $client = null)
25
    {
26 3
        $this->alias = $alias;
0 ignored issues
show
Bug introduced by
The property alias does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27 3
        $this->username = $username;
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28 3
        $this->password = $password;
0 ignored issues
show
Bug introduced by
The property password does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29 3
        $this->host = $host;
30 3
        $this->client = $client;
31 3
    }
32
33
    public function hire()
34
    {
35
36
    }
37
38
    protected function login()
39
    {
40
        $url = "https://{$this->host}/api/account/login";
41
        return $this->request('POST', $url, [
42
            'username' => $this->username,
43
            'password' => $this->password,
44
        ]);
45
    }
46
47
    /**
48
     * Returns the Client instance
49
     * @return Client
50
     */
51
    protected function getClient()
52
    {
53
        $client = $this->client;
54
        if (!$client instanceof Client) {
55
            $client = new Client();
56
        }
57
        return $client;
58
    }
59
60
    /**
61
     * Executes a request to the PeopleMatter API
62
     * @param  string $url    The URL to send to
63
     * @return mixed          The response data
64
     */
65
    protected function request($method, $url, $data)
66
    {
67
        $client = $this->getClient();
68
        $response = $client->request($method, $url, ["data" => $data]);
69
        return $response->getBody();
70
    }
71
}
72