Completed
Push — master ( 1b0622...b59bdb )
by François
01:52
created

AccessWatch::getHttpClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Bouncer\Analyzer;
4
5
class AccessWatch
6
{
7
8
    protected $baseUrl = 'http://access.watch/api/v1';
9
10
    protected $apiKey;
11
12
    protected $httpClient;
13
14
    public function __construct($params)
15
    {
16
        if (isset($params['baseUrl'])) {
17
            $this->baseUrl = $params['baseUrl'];
18
        }
19
        if (isset($params['apiKey'])) {
20
            $this->apiKey = $params['apiKey'];
21
        }
22
        if (isset($params['httpClient'])) {
23
            $this->httpClient = $params['httpClient'];
24
        }
25
    }
26
27
    public function getHttpClient()
28
    {
29
        if (empty($this->httpClient)) {
30
            $this->httpClient = new \Bouncer\Http\SimpleClient;
31
        }
32
        return $this->httpClient;
33
    }
34
35
    public function identityAnalyzer($identity)
36
    {
37
        $result = $this->getHttpClient()->post(
38
            "{$this->baseUrl}/identity",
39
            array(
40
                'key'      => $this->apiKey,
41
                'identity' => $identity,
42
            )
43
        );
44
        return $result ? $result['identity'] + $identity : $identity;
45
    }
46
47
}
48