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

WrapItUserHelper::getProfilePicture()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 7
cp 0.5714
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3.7085
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