Complex classes like ShibbolethAttributesResolverTrait 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 ShibbolethAttributesResolverTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | trait ShibbolethAttributesResolverTrait |
||
6 | { |
||
7 | /** |
||
8 | * @var array |
||
9 | */ |
||
10 | protected $attributes = []; |
||
11 | |||
12 | /** |
||
13 | * Returns the attributes. |
||
14 | * |
||
15 | * @return array The attributes |
||
16 | */ |
||
17 | public function getAttributes() |
||
21 | |||
22 | /** |
||
23 | * Sets the attributes. |
||
24 | * |
||
25 | * @param array $attributes The attributes |
||
26 | */ |
||
27 | public function setAttributes(array $attributes) |
||
31 | |||
32 | /** |
||
33 | * Returns true if the attribute exists. |
||
34 | * |
||
35 | * @param string $name The attribute name |
||
36 | * @return bool true if the attribute exists, false otherwise |
||
37 | */ |
||
38 | public function hasAttribute($name) |
||
42 | |||
43 | /** |
||
44 | * Returns an attribute value. |
||
45 | * |
||
46 | * @param string $name The attribute name |
||
47 | * @return mixed The attribute value |
||
48 | * @throws \InvalidArgumentException When attribute doesn't exist |
||
49 | */ |
||
50 | public function getAttribute($name) |
||
58 | |||
59 | /** |
||
60 | * Sets an attribute. |
||
61 | * |
||
62 | * @param string $name The attribute name |
||
63 | * @param mixed $value The attribute value |
||
64 | */ |
||
65 | public function setAttribute($name, $value) |
||
69 | |||
70 | /** |
||
71 | * Returns attribute value. If it's a multivalue, the first value is returned, or the value at the specified index. |
||
72 | * |
||
73 | * @param string $name |
||
74 | * @param null $index |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function getSingleAttribute($name, $index = null) |
||
85 | |||
86 | /** |
||
87 | * Returns an attribute as an array of values. |
||
88 | * |
||
89 | * @param string $name |
||
90 | * @return array |
||
91 | */ |
||
92 | public function getArrayAttribute($name) |
||
97 | |||
98 | /** |
||
99 | * Returns true if attribute exists (if value is given, it will also check the value). |
||
100 | * |
||
101 | * @param string $name |
||
102 | * @param null|string $value |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function hasAttributeValue($name, $value = null) |
||
110 | |||
111 | /** |
||
112 | * @return string uid |
||
113 | */ |
||
114 | public function getUID() |
||
118 | |||
119 | /** |
||
120 | * Alias for cn |
||
121 | * |
||
122 | * @return string cn |
||
123 | */ |
||
124 | public function getCommonName() |
||
128 | |||
129 | /** |
||
130 | * Alias for cn |
||
131 | * |
||
132 | * @return string cn |
||
133 | */ |
||
134 | public function getFullName() |
||
138 | |||
139 | /** |
||
140 | * @return string givenName |
||
141 | */ |
||
142 | public function getGivenName() |
||
146 | |||
147 | /** |
||
148 | * Alias for givenName |
||
149 | * |
||
150 | * @return string givenName |
||
151 | */ |
||
152 | public function getFirstName() |
||
156 | |||
157 | /** |
||
158 | * @return string sn |
||
159 | */ |
||
160 | public function getSurname() |
||
164 | |||
165 | /** |
||
166 | * Alias for sn |
||
167 | * |
||
168 | * @return string sn |
||
169 | */ |
||
170 | public function getLastName() |
||
174 | |||
175 | /** |
||
176 | * Alias for cn, fallback to uid |
||
177 | * |
||
178 | * @return string cn|uid |
||
179 | */ |
||
180 | public function getDisplayName() |
||
184 | |||
185 | /** |
||
186 | * @return string mail |
||
187 | */ |
||
188 | public function getMail() |
||
192 | |||
193 | /** |
||
194 | * Alias for mail |
||
195 | * |
||
196 | * @return string mail |
||
197 | */ |
||
198 | public function getEmail() |
||
202 | |||
203 | /** |
||
204 | * @return string mail |
||
205 | */ |
||
206 | public function getMails() |
||
210 | |||
211 | /** |
||
212 | * @return string affiliation |
||
213 | */ |
||
214 | public function getAffiliation() |
||
218 | |||
219 | /** |
||
220 | * @return string scopedAffiliation |
||
221 | */ |
||
222 | public function getScopedAffiliation() |
||
226 | |||
227 | /** |
||
228 | * @param null|string $value |
||
229 | * @return bool |
||
230 | */ |
||
231 | public function hasAffiliation($value = null) |
||
235 | |||
236 | /** |
||
237 | * @param null|string $value |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function hasScopedAffiliation($value = null) |
||
244 | |||
245 | /** |
||
246 | * @param null|string $scope |
||
247 | * @return bool |
||
248 | */ |
||
249 | public function isMember($scope = null) |
||
253 | |||
254 | /** |
||
255 | * @param null|string $scope |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function isEmployee($scope = null) |
||
262 | |||
263 | /** |
||
264 | * @param null|string $scope |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function isStudent($scope = null) |
||
271 | |||
272 | /** |
||
273 | * @param null|string $scope |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function isStaff($scope = null) |
||
280 | |||
281 | /** |
||
282 | * @param null|string $scope |
||
283 | * @return bool |
||
284 | */ |
||
285 | public function isFaculty($scope = null) |
||
289 | |||
290 | /** |
||
291 | * @return string logoutURL |
||
292 | */ |
||
293 | public function getLogoutURL() |
||
297 | } |
||
298 |