Completed
Pull Request — master (#10)
by
unknown
02:57
created

SlackResourceOwner   B

Complexity

Total Complexity 42

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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