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

AccessWatch   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A getHttpClient() 0 7 2
A identityAnalyzer() 0 11 2
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