Conditions | 9 |
Paths | 19 |
Total Lines | 56 |
Code Lines | 33 |
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 |
||
83 | private function process() |
||
84 | { |
||
85 | $notifications = $this->requestNotifications(); |
||
86 | if (empty($notifications)) { |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | krsort($notifications); |
||
91 | |||
92 | $wikilog = []; |
||
93 | foreach ($notifications as $notif) { |
||
94 | $title = $notif['title']['full']; |
||
95 | |||
96 | // Skip bot pages |
||
97 | if (in_array( |
||
98 | $title, |
||
99 | self::SKIP_BOTPAGES |
||
100 | ) |
||
101 | ) { |
||
102 | continue; |
||
103 | } |
||
104 | |||
105 | $date = new DateTime($notif['timestamp']['utciso8601']); |
||
106 | |||
107 | if (isset($notif['title']) && in_array($notif['title']['namespace'], ['', 'Discussion'])) { |
||
108 | $icon = '🌼 '; // Article + Discussion |
||
109 | } |
||
110 | |||
111 | $wikilog[] = sprintf( |
||
112 | '* %s %s[[%s]] ([%s%s diff]) par %s', |
||
113 | $date->format('d-m-Y H\hi'), |
||
114 | $icon ?? '', |
||
115 | $title, |
||
116 | self::DIFF_URL, |
||
117 | $notif['revid'] ?? '', |
||
118 | $notif['agent']['name'] ?? '???' |
||
119 | ); |
||
120 | |||
121 | if (!isset($notif['read'])) { |
||
122 | $this->postNotifAsRead($notif['id']); |
||
123 | } |
||
124 | |||
125 | $this->processSpecialActions($notif); |
||
126 | } |
||
127 | |||
128 | if ($wikilog === []) { |
||
129 | echo "Nothing."; |
||
130 | return; |
||
131 | } |
||
132 | |||
133 | dump($wikilog); |
||
134 | |||
135 | if (self::PUBLISH_LOG_ON_WIKI) { |
||
136 | echo "Stop the script if you want to cancel the log edition on Wikipedia ! Waiting 30 seconds...\n"; |
||
137 | sleep(30); |
||
138 | $this->editWikilog($wikilog); |
||
139 | } |
||
221 |