Passed
Push — master ( c19fc7...328aea )
by Bence
04:43
created

WrapItUserHelper::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 7
cts 8
cp 0.875
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 2.0078
1
<?php
2
3
namespace WrapIt\Helpers;
4
5
use WrapIt\WrapIt;
6
use WrapIt\Exceptions\WrapItParameterException;
7
use WrapIt\Exceptions\WrapItResponseException;
8
use WrapIt\Http\WrapItUserRequester;
9
10
/**
11
 * Class WrapItUserHelper
12
 *
13
 * @package WrapIt
14
 */
15
class WrapItUserHelper {
16
17
    private $access_token = null;
18
19
    private $client_id = null;
20
    private $client_secret = null;
21
22
    private $requester;
23
24 10 View Code Duplication
    public function __construct($wi, $access_token) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25 10
        if (!($wi instanceof WrapIt)) {
26
            throw new WrapItParameterException("WrapIt class required");
27
        }
28
29 10
        $this->client_id = $wi->getClientId();
30 10
        $this->client_secret = $wi->getClientSecret();
31 10
        $this->access_token = $access_token;
32 10
        $this->requester = new WrapItUserRequester($wi->getDomain(), $access_token);
33 10
    }
34
35 5
    public function getUserData($userid = "me") {
36 5
        $data = $this->requester->get("people/$userid");
37 5
        if ($data != null && !isset($data["error"])) {
38
            return $data;
39
        } else {
40 5
            throw new WrapItResponseException($data["error"]["message"]);
41
        }
42
    }
43
44 5
    public function getProfilePicture($userid = "me") {
45 5
        $data = $this->requester->get("people/$userid/picture", array("redirect" => "false"));
46 5
        if (isset($data["error"])) {
47 5
            throw new WrapItResponseException($data["error"]["message"]);
48
        }
49
50
        if (isset($data["url"])) {
51
            return $data["url"];
52
        } else {
53
            throw new WrapItResponseException("Unknown Exception");
54
        }
55
    }
56
57
}
58