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

WrapItUserHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 10
loc 43
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 2
A getUserData() 0 8 3
A getProfilePicture() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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