Conditions | 9 |
Paths | 7 |
Total Lines | 55 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | protected function main() |
||
24 | { |
||
25 | $this->setHtmlTitle('Flagged comments'); |
||
26 | $this->setTemplate('flagged-comments.tpl'); |
||
27 | |||
28 | $database = $this->getDatabase(); |
||
29 | $this->assignCSRFToken(); |
||
30 | |||
31 | /** @var Comment[] $commentObjects */ |
||
32 | $commentObjects = Comment::getFlaggedComments($database); |
||
33 | $comments = []; |
||
34 | |||
35 | $currentUser = User::getCurrent($database); |
||
36 | |||
37 | $seeRestrictedComments = $this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData'); |
||
38 | $seeCheckuserComments = $this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData'); |
||
39 | |||
40 | foreach ($commentObjects as $object) { |
||
41 | $data = [ |
||
42 | 'id' => $object->getId(), |
||
43 | 'visibility' => $object->getVisibility(), |
||
44 | 'updateversion' => $object->getUpdateVersion(), |
||
45 | 'hidden' => false |
||
46 | ]; |
||
47 | |||
48 | if ($object->getVisibility() == 'requester' || $object->getVisibility() == 'user') { |
||
49 | $this->copyCommentData($object, $data, $database); |
||
50 | } |
||
51 | elseif ($object->getVisibility() == 'admin') { |
||
52 | if ($seeRestrictedComments) { |
||
53 | $this->copyCommentData($object, $data, $database); |
||
54 | } |
||
55 | else { |
||
56 | $data['hidden'] = true; |
||
57 | } |
||
58 | } |
||
59 | elseif ($object->getVisibility() == 'checkuser') { |
||
60 | if ($seeCheckuserComments) { |
||
61 | $this->copyCommentData($object, $data, $database); |
||
62 | } |
||
63 | else { |
||
64 | $data['hidden'] = true; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $comments[] = $data; |
||
69 | } |
||
70 | |||
71 | $this->assign('comments', $comments); |
||
72 | $this->assign('seeRestrictedComments', $seeRestrictedComments); |
||
73 | $this->assign('seeCheckuserComments', $seeCheckuserComments); |
||
74 | |||
75 | $this->assign('editOthersComments', $this->barrierTest('editOthers', $currentUser, PageEditComment::class)); |
||
76 | $this->assign('editComments', $this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageEditComment::class)); |
||
77 | $this->assign('canUnflag', $this->barrierTest('unflag', $currentUser, PageFlagComment::class) && $this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageFlagComment::class)); |
||
78 | } |
||
89 | } |