SlackResourceOwner   B
last analyzed

Complexity

Total Complexity 42

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 42
lcom 1
cbo 0
dl 0
loc 121
ccs 45
cts 45
cp 1
rs 8.295
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 4 1
A getId() 0 4 2
A getName() 0 4 2
A isDeleted() 0 4 2
A getColor() 0 4 2
A getProfile() 0 4 2
A getFirstName() 0 4 2
A getLastName() 0 4 2
A getRealName() 0 4 2
A getEmail() 0 4 2
A getSkype() 0 4 2
A getPhone() 0 4 2
A getImage24() 0 4 2
A getImage32() 0 4 2
A getImage48() 0 4 2
A getImage72() 0 4 2
A getImage192() 0 4 2
A isAdmin() 0 4 2
A isOwner() 0 4 2
A hasTwoFactorAuthentication() 0 4 2
A hasFiles() 0 4 2

How to fix   Complexity   

Complex Class

Complex classes like SlackResourceOwner often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SlackResourceOwner, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace AdamPaterson\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
6
7
/**
8
 * Class SlackResourceOwner
9
 *
10
 * @author Adam Paterson <[email protected]>
11
 *
12
 * @package AdamPaterson\OAuth2\Client\Provider
13
 */
14
class SlackResourceOwner implements ResourceOwnerInterface
15
{
16
17
    protected $response;
18
19 3
    public function __construct(array $response)
20
    {
21 3
        $this->response = $response;
22 3
    }
23
24
    /**
25
     * Return all of the owner details available as an array.
26
     *
27
     * @return array
28
     */
29 3
    public function toArray()
30
    {
31 3
        return $this->response;
32
    }
33
34 3
    public function getId()
35
    {
36 3
        return $this->response['user']['id'] ?: null;
37
    }
38
39
40 3
    public function getName()
41
    {
42 3
        return $this->response['user']['name'] ?: null;
43
    }
44
45 3
    public function isDeleted()
46
    {
47 3
        return $this->response['user']['deleted'] ?: null;
48
    }
49
50 3
    public function getColor()
51
    {
52 3
        return $this->response['user']['color'] ?: null;
53
    }
54
55 3
    public function getProfile()
56
    {
57 3
        return $this->response['user']['profile'] ?: null;
58
    }
59
60 3
    public function getFirstName()
61
    {
62 3
        return $this->response['user']['profile']['first_name'] ?: null;
63
    }
64
65 3
    public function getLastName()
66
    {
67 3
        return $this->response['user']['profile']['last_name'] ?: null;
68
    }
69
70 3
    public function getRealName()
71
    {
72 3
        return $this->response['user']['profile']['real_name'] ?: null;
73
    }
74
75 3
    public function getEmail()
76
    {
77 3
        return $this->response['user']['profile']['email'] ?: null;
78
    }
79
80 3
    public function getSkype()
81
    {
82 3
        return $this->response['user']['profile']['skype'] ?: null;
83
    }
84
85 3
    public function getPhone()
86
    {
87 3
        return $this->response['user']['profile']['phone'] ?: null;
88
    }
89
90 3
    public function getImage24()
91
    {
92 3
        return $this->response['user']['profile']['image_24'] ?: null;
93
    }
94
95 3
    public function getImage32()
96
    {
97 3
        return $this->response['user']['profile']['image_32'] ?: null;
98
    }
99
100 3
    public function getImage48()
101
    {
102 3
        return $this->response['user']['profile']['image_48'] ?: null;
103
    }
104
105 3
    public function getImage72()
106
    {
107 3
        return $this->response['user']['profile']['image_72'] ?: null;
108
    }
109
110 3
    public function getImage192()
111
    {
112 3
        return $this->response['user']['profile']['image_192'] ?: null;
113
    }
114
115 3
    public function isAdmin()
116
    {
117 3
        return $this->response['user']['is_admin'] ?: null;
118
    }
119
120 3
    public function isOwner()
121
    {
122 3
        return $this->response['user']['is_owner'] ?: null;
123
    }
124
125 3
    public function hasTwoFactorAuthentication()
126
    {
127 3
        return $this->response['user']['has_2fa'] ?: null;
128
    }
129
130 3
    public function hasFiles()
131
    {
132 3
        return $this->response['user']['has_files'] ?: null;
133
    }
134
}
135