Conditions | 9 |
Paths | 13 |
Total Lines | 52 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
40 | return 'patrol'; |
||
41 | } |
||
42 | |||
43 | protected function getRecentChange( $data = null ) { |
||
44 | $rc = null; |
||
45 | // Note: This works both on initial GET url and after submitting the form |
||
46 | $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' ); |
||
47 | if ( $rcId ) { |
||
48 | $rc = RecentChange::newFromId( $rcId ); |
||
49 | } |
||
50 | if ( !$rc ) { |
||
51 | throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' ); |
||
52 | } |
||
53 | return $rc; |
||
54 | } |
||
55 | |||
56 | protected function preText() { |
||
57 | $rc = $this->getRecentChange(); |
||
58 | $title = $rc->getTitle(); |
||
59 | |||
60 | // Based on logentry-patrol-patrol (see PatrolLogFormatter) |
||
61 | $revId = $rc->getAttribute( 'rc_this_oldid' ); |
||
62 | $query = [ |
||
63 | 'curid' => $rc->getAttribute( 'rc_cur_id' ), |
||
64 | 'diff' => $revId, |
||
65 | 'oldid' => $rc->getAttribute( 'rc_last_oldid' ) |
||
66 | ]; |
||
67 | $revlink = Linker::link( $title, htmlspecialchars( $revId ), [], $query ); |
||
68 | $pagelink = Linker::link( $title, htmlspecialchars( $title->getPrefixedText() ) ); |
||
69 | |||
70 | return $this->msg( 'confirm-markpatrolled-top' )->params( |
||
71 | $title->getPrefixedText(), |
||
72 | // Provide pre-rendered link as parser would render [[:$1]] as bold non-link |
||
73 | Message::rawParam( $pagelink ), |
||
74 | Message::rawParam( $revlink ) |
||
75 | )->parse(); |
||
76 | } |
||
77 | |||
78 | protected function alterForm( HTMLForm $form ) { |
||
79 | $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) ); |
||
80 | $form->setTokenSalt( 'patrol' ); |
||
81 | $form->setSubmitTextMsg( 'confirm-markpatrolled-button' ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return bool|array True for success, false for didn't-try, array of errors on failure |
||
86 | */ |
||
87 | public function onSubmit( $data ) { |
||
88 | $user = $this->getUser(); |
||
89 | $rc = $this->getRecentChange( $data ); |
||
90 | $errors = $rc->doMarkPatrolled( $user ); |
||
91 | |||
92 | if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) { |
||
136 |