Total Complexity | 48 |
Total Lines | 388 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AccountSearchItem 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.
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 AccountSearchItem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | final class AccountSearchItem |
||
41 | { |
||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | public static $accountLink = false; |
||
46 | /** |
||
47 | * @var bool |
||
48 | */ |
||
49 | public static $topNavbar = false; |
||
50 | /** |
||
51 | * @var bool |
||
52 | */ |
||
53 | public static $optionalActions = false; |
||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | public static $requestEnabled = true; |
||
58 | /** |
||
59 | * @var bool |
||
60 | */ |
||
61 | public static $wikiEnabled = false; |
||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | public static $dokuWikiEnabled = false; |
||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | public static $publicLinkEnabled = false; |
||
70 | /** |
||
71 | * @var bool |
||
72 | */ |
||
73 | public static $isDemoMode = false; |
||
74 | |||
75 | /** |
||
76 | * @var AccountSearchVData |
||
77 | */ |
||
78 | protected $accountSearchVData; |
||
79 | /** |
||
80 | * @var string |
||
81 | */ |
||
82 | protected $color; |
||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $link; |
||
87 | /** |
||
88 | * @var bool |
||
89 | */ |
||
90 | protected $url_islink = false; |
||
91 | /** |
||
92 | * @var string |
||
93 | */ |
||
94 | protected $numFiles; |
||
95 | /** |
||
96 | * @var bool |
||
97 | */ |
||
98 | protected $favorite = false; |
||
99 | /** |
||
100 | * @var int |
||
101 | */ |
||
102 | protected $textMaxLength = 60; |
||
103 | /** |
||
104 | * @var ItemData[] |
||
105 | */ |
||
106 | protected $users; |
||
107 | /** |
||
108 | * @var ItemData[] |
||
109 | */ |
||
110 | protected $tags; |
||
111 | /** |
||
112 | * @var ItemData[] |
||
113 | */ |
||
114 | protected $userGroups; |
||
115 | /** |
||
116 | * @var ConfigData |
||
117 | */ |
||
118 | private $configData; |
||
119 | /** |
||
120 | * @var AccountAcl |
||
121 | */ |
||
122 | private $accountAcl; |
||
123 | |||
124 | /** |
||
125 | * AccountsSearchItem constructor. |
||
126 | * |
||
127 | * @param AccountSearchVData $accountSearchVData |
||
128 | * @param AccountAcl $accountAcl |
||
129 | * @param ConfigData $configData |
||
130 | */ |
||
131 | public function __construct(AccountSearchVData $accountSearchVData, AccountAcl $accountAcl, ConfigData $configData) |
||
132 | { |
||
133 | $this->accountSearchVData = $accountSearchVData; |
||
134 | $this->accountAcl = $accountAcl; |
||
135 | $this->configData = $configData; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return boolean |
||
140 | */ |
||
141 | public function isFavorite() |
||
142 | { |
||
143 | return $this->favorite; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param boolean $favorite |
||
148 | */ |
||
149 | public function setFavorite($favorite) |
||
150 | { |
||
151 | $this->favorite = $favorite; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @return boolean |
||
156 | */ |
||
157 | public function isShowRequest() |
||
158 | { |
||
159 | return (!$this->accountAcl->isShow() && self::$requestEnabled); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function isShowCopyPass() |
||
166 | { |
||
167 | return ($this->accountAcl->isShowViewPass() && !$this->configData->isAccountPassToImage()); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function isShowViewPass() |
||
174 | { |
||
175 | return $this->accountAcl->isShowViewPass(); |
||
176 | } |
||
177 | |||
178 | |||
179 | /** |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function isShowOptional() |
||
183 | { |
||
184 | return (!self::$optionalActions && $this->accountAcl->isShow()); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @param int $textMaxLength |
||
189 | */ |
||
190 | public function setTextMaxLength($textMaxLength) |
||
191 | { |
||
192 | $this->textMaxLength = $textMaxLength; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getShortUrl() |
||
199 | { |
||
200 | return Html::truncate($this->accountSearchVData->getUrl(), $this->textMaxLength); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return boolean |
||
205 | */ |
||
206 | public function isUrlIslink() |
||
207 | { |
||
208 | return preg_match('#^https?://#i', $this->accountSearchVData->getUrl()); |
||
|
|||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getShortLogin() |
||
215 | { |
||
216 | return Html::truncate($this->accountSearchVData->getLogin(), $this->textMaxLength); |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getShortClientName() |
||
223 | { |
||
224 | return Html::truncate($this->accountSearchVData->getClientName(), $this->textMaxLength / 3); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getClientLink() |
||
231 | { |
||
232 | return self::$wikiEnabled ? $this->configData->getWikiSearchurl() . $this->accountSearchVData->getClientName() : null; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getPublicLink() |
||
239 | { |
||
240 | return self::$publicLinkEnabled |
||
241 | && $this->accountSearchVData->getPublicLinkHash() !== null ? PublicLinkService::getLinkForHash($this->accountSearchVData->getPublicLinkHash()) : null; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getColor() |
||
248 | { |
||
249 | return $this->color; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * @param string $color |
||
254 | */ |
||
255 | public function setColor($color) |
||
256 | { |
||
257 | $this->color = $color; |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * @return string |
||
262 | */ |
||
263 | public function getLink() |
||
264 | { |
||
265 | return $this->link; |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * @param string $link |
||
270 | */ |
||
271 | public function setLink($link) |
||
272 | { |
||
273 | $this->link = $link; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * @return array |
||
278 | */ |
||
279 | public function getAccesses() |
||
280 | { |
||
281 | $accesses = [ |
||
282 | '(G*) <em>' . $this->accountSearchVData->getUserGroupName() . '</em>', |
||
283 | '(U*) <em>' . $this->accountSearchVData->getUserLogin() . '</em>' |
||
284 | ]; |
||
285 | |||
286 | $userLabel = $this->accountSearchVData->getOtherUserEdit() === 1 ? 'U+' : 'U'; |
||
287 | $userGroupLabel = $this->accountSearchVData->getOtherUserGroupEdit() === 1 ? 'G+' : 'G'; |
||
288 | |||
289 | foreach ($this->userGroups as $group) { |
||
290 | $accesses[] = sprintf('(%s) <em>%s</em>', $userGroupLabel, $group->getName()); |
||
291 | } |
||
292 | |||
293 | foreach ($this->users as $user) { |
||
294 | $accesses[] = sprintf('(%s) <em>%s</em>', $userLabel, $user->login); |
||
295 | } |
||
296 | |||
297 | return $accesses; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getNumFiles() |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @param string $numFiles |
||
310 | */ |
||
311 | public function setNumFiles($numFiles) |
||
312 | { |
||
313 | $this->numFiles = $numFiles; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @return boolean |
||
318 | */ |
||
319 | public function isShow() |
||
320 | { |
||
321 | return $this->accountAcl->isShow(); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @return boolean |
||
326 | */ |
||
327 | public function isShowView() |
||
328 | { |
||
329 | return $this->accountAcl->isShowView(); |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * @return boolean |
||
334 | */ |
||
335 | public function isShowEdit() |
||
336 | { |
||
337 | return $this->accountAcl->isShowEdit(); |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * @return boolean |
||
342 | */ |
||
343 | public function isShowCopy() |
||
344 | { |
||
345 | return $this->accountAcl->isShowCopy(); |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * @return boolean |
||
350 | */ |
||
351 | public function isShowDelete() |
||
352 | { |
||
353 | return $this->accountAcl->isShowDelete(); |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @return AccountSearchVData |
||
358 | */ |
||
359 | public function getAccountSearchVData() |
||
360 | { |
||
361 | return $this->accountSearchVData; |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * @return string |
||
366 | */ |
||
367 | public function getShortNotes() |
||
368 | { |
||
369 | if ($this->accountSearchVData->getNotes()) { |
||
370 | return nl2br(Html::truncate($this->accountSearchVData->getNotes(), 300)); |
||
371 | } |
||
372 | |||
373 | return ''; |
||
374 | } |
||
375 | |||
376 | /** |
||
377 | * Develve si la clave ha caducado |
||
378 | * |
||
379 | * @return bool |
||
380 | */ |
||
381 | public function isPasswordExpired() |
||
382 | { |
||
383 | return $this->configData->isAccountExpireEnabled() |
||
384 | && $this->accountSearchVData->getPassDateChange() > 0 |
||
385 | && time() > $this->accountSearchVData->getPassDateChange(); |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @param ItemData[] $userGroups |
||
390 | */ |
||
391 | public function setUserGroups(array $userGroups) |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * @param ItemData[] $users |
||
398 | */ |
||
399 | public function setUsers(array $users) |
||
400 | { |
||
401 | $this->users = $users; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @return ItemData[] |
||
406 | */ |
||
407 | public function getTags() |
||
408 | { |
||
409 | return $this->tags; |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * @param ItemData[] $tags |
||
414 | */ |
||
415 | public function setTags(array $tags) |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @param $wikiFilter |
||
422 | * |
||
423 | * @return bool |
||
424 | */ |
||
425 | public function isWikiMatch($wikiFilter) |
||
426 | { |
||
427 | return preg_match('/^(' . $wikiFilter . ').*/i', $this->accountSearchVData->getName()) !== false; |
||
428 | } |
||
429 | } |