@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | /** @var array[] */ |
| 14 | 14 | private $allUsers; |
| 15 | 15 | /** @var PageRiconferma[] */ |
| 16 | - private $createdPages = []; |
|
| 16 | + private $createdPages = [ ]; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Get the full content of the JSON users list |
| 20 | 20 | * |
| 21 | 21 | * @return array[] |
| 22 | 22 | */ |
| 23 | - public function getUsersList() : array { |
|
| 23 | + public function getUsersList () : array { |
|
| 24 | 24 | if ( $this->allUsers === null ) { |
| 25 | 25 | $this->getLogger()->debug( 'Retrieving users list' ); |
| 26 | 26 | $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return array[] |
| 37 | 37 | */ |
| 38 | - public function getUsersToProcess() : array { |
|
| 38 | + public function getUsersToProcess () : array { |
|
| 39 | 39 | if ( $this->processUsers === null ) { |
| 40 | - $this->processUsers = []; |
|
| 40 | + $this->processUsers = [ ]; |
|
| 41 | 41 | foreach ( $this->getUsersList() as $user => $groups ) { |
| 42 | 42 | $timestamp = $this->getValidTimestamp( $groups ); |
| 43 | 43 | |
@@ -59,13 +59,11 @@ discard block |
||
| 59 | 59 | * @param array $groups |
| 60 | 60 | * @return int |
| 61 | 61 | */ |
| 62 | - private function getValidTimestamp( array $groups ) : int { |
|
| 62 | + private function getValidTimestamp ( array $groups ) : int { |
|
| 63 | 63 | $checkuser = isset( $groups[ 'checkuser' ] ) ? |
| 64 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 65 | - 0; |
|
| 64 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 66 | 65 | $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
| 67 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 68 | - 0; |
|
| 66 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 69 | 67 | |
| 70 | 68 | $timestamp = max( $bureaucrat, $checkuser ); |
| 71 | 69 | if ( $timestamp === 0 ) { |
@@ -79,7 +77,7 @@ discard block |
||
| 79 | 77 | * |
| 80 | 78 | * @return PageRiconferma[] |
| 81 | 79 | */ |
| 82 | - public function getOpenPages() : array { |
|
| 80 | + public function getOpenPages () : array { |
|
| 83 | 81 | $baseTitle = $this->getConfig()->get( 'ric-main-page' ); |
| 84 | 82 | $params = [ |
| 85 | 83 | 'action' => 'query', |
@@ -91,10 +89,10 @@ discard block |
||
| 91 | 89 | |
| 92 | 90 | $res = RequestBase::newFromParams( $params )->execute(); |
| 93 | 91 | $pages = $res->query->pages; |
| 94 | - $ret = []; |
|
| 92 | + $ret = [ ]; |
|
| 95 | 93 | foreach ( reset( $pages )->templates as $page ) { |
| 96 | 94 | if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) { |
| 97 | - $ret[] = new PageRiconferma( $page->title ); |
|
| 95 | + $ret[ ] = new PageRiconferma( $page->title ); |
|
| 98 | 96 | } |
| 99 | 97 | } |
| 100 | 98 | return $ret; |
@@ -105,21 +103,21 @@ discard block |
||
| 105 | 103 | * |
| 106 | 104 | * @param string $name |
| 107 | 105 | */ |
| 108 | - public function removeUser( string $name ) { |
|
| 106 | + public function removeUser ( string $name ) { |
|
| 109 | 107 | unset( $this->processUsers[ $name ] ); |
| 110 | 108 | } |
| 111 | 109 | |
| 112 | 110 | /** |
| 113 | 111 | * @return PageRiconferma[] |
| 114 | 112 | */ |
| 115 | - public function getCreatedPages() : array { |
|
| 113 | + public function getCreatedPages () : array { |
|
| 116 | 114 | return $this->createdPages; |
| 117 | 115 | } |
| 118 | 116 | |
| 119 | 117 | /** |
| 120 | 118 | * @param PageRiconferma $page |
| 121 | 119 | */ |
| 122 | - public function addCreatedPages( PageRiconferma $page ) { |
|
| 123 | - $this->createdPages[] = $page; |
|
| 120 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
| 121 | + $this->createdPages[ ] = $page; |
|
| 124 | 122 | } |
| 125 | 123 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @inheritDoc |
| 17 | 17 | */ |
| 18 | - public function run() : TaskResult { |
|
| 18 | + public function run () : TaskResult { |
|
| 19 | 19 | $this->getLogger()->info( 'Starting task ClosePages' ); |
| 20 | 20 | |
| 21 | 21 | $pages = $this->getPagesList(); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return PageRiconferma[] |
| 54 | 54 | */ |
| 55 | - protected function getPagesList() : array { |
|
| 55 | + protected function getPagesList () : array { |
|
| 56 | 56 | $allPages = $this->getDataProvider()->getOpenPages(); |
| 57 | - $ret = []; |
|
| 57 | + $ret = [ ]; |
|
| 58 | 58 | foreach ( $allPages as $page ) { |
| 59 | 59 | if ( time() > $page->getEndTimestamp() ) { |
| 60 | - $ret[] = $page; |
|
| 60 | + $ret[ ] = $page; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | return $ret; |
@@ -69,11 +69,11 @@ discard block |
||
| 69 | 69 | * @param PageRiconferma[] $pages |
| 70 | 70 | * @return PageRiconferma[] |
| 71 | 71 | */ |
| 72 | - private function getFailures( array $pages ) : array { |
|
| 73 | - $ret = []; |
|
| 72 | + private function getFailures ( array $pages ) : array { |
|
| 73 | + $ret = [ ]; |
|
| 74 | 74 | foreach ( $pages as $page ) { |
| 75 | 75 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
| 76 | - $ret[] = $page; |
|
| 76 | + $ret[ ] = $page; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | return $ret; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * @param PageRiconferma $page |
| 84 | 84 | */ |
| 85 | - protected function addVoteCloseText( PageRiconferma $page ) { |
|
| 85 | + protected function addVoteCloseText ( PageRiconferma $page ) { |
|
| 86 | 86 | $content = $page->getContent(); |
| 87 | 87 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!'; |
| 88 | 88 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | * @param PageRiconferma[] $pages |
| 101 | 101 | * @see UpdatesAround::addToMainPage() |
| 102 | 102 | */ |
| 103 | - protected function removeFromMainPage( array $pages ) { |
|
| 103 | + protected function removeFromMainPage ( array $pages ) { |
|
| 104 | 104 | $this->getLogger()->info( |
| 105 | 105 | 'Removing from main: ' . implode( ', ', array_map( 'strval', $pages ) ) |
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | $mainPage = new Page( $this->getConfig()->get( 'ric-main-page' ) ); |
| 109 | - $translations = []; |
|
| 109 | + $translations = [ ]; |
|
| 110 | 110 | foreach ( $pages as $page ) { |
| 111 | 111 | $translations[ '{{' . $page->getTitle() . '}}' ] = ''; |
| 112 | 112 | } |
@@ -124,17 +124,17 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @param PageRiconferma[] $pages |
| 126 | 126 | */ |
| 127 | - protected function addToArchive( array $pages ) { |
|
| 127 | + protected function addToArchive ( array $pages ) { |
|
| 128 | 128 | $this->getLogger()->info( |
| 129 | 129 | 'Adding to archive: ' . implode( ', ', array_map( 'strval', $pages ) ) |
| 130 | 130 | ); |
| 131 | 131 | |
| 132 | - $simple = $votes = []; |
|
| 132 | + $simple = $votes = [ ]; |
|
| 133 | 133 | foreach ( $pages as $page ) { |
| 134 | 134 | if ( $page->isVote() ) { |
| 135 | - $votes[] = $page; |
|
| 135 | + $votes[ ] = $page; |
|
| 136 | 136 | } else { |
| 137 | - $simple[] = $page; |
|
| 137 | + $simple[ ] = $page; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
@@ -151,21 +151,21 @@ discard block |
||
| 151 | 151 | * @param string $archiveTitle |
| 152 | 152 | * @param array $pages |
| 153 | 153 | */ |
| 154 | - private function reallyAddToArchive( string $archiveTitle, array $pages ) { |
|
| 154 | + private function reallyAddToArchive ( string $archiveTitle, array $pages ) { |
|
| 155 | 155 | $curTitle = "$archiveTitle/" . date( 'Y' ); |
| 156 | 156 | |
| 157 | 157 | $append = ''; |
| 158 | - $archivedList = []; |
|
| 158 | + $archivedList = [ ]; |
|
| 159 | 159 | foreach ( $pages as $page ) { |
| 160 | 160 | $append .= '{{' . $page->getTitle() . "}}\n"; |
| 161 | - $archivedList[] = $page->getUserNum(); |
|
| 161 | + $archivedList[ ] = $page->getUserNum(); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if ( count( $archivedList ) > 1 ) { |
| 165 | 165 | $last = array_pop( $archivedList ); |
| 166 | 166 | $userNums = implode( ', ', $archivedList ) . " e $last"; |
| 167 | 167 | } else { |
| 168 | - $userNums = $archivedList[0]; |
|
| 168 | + $userNums = $archivedList[ 0 ]; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $summary = $this->msg( 'close-archive-summary' ) |
@@ -184,15 +184,14 @@ discard block |
||
| 184 | 184 | * @param PageRiconferma $page |
| 185 | 185 | * @see CreatePages::updateBasePage() |
| 186 | 186 | */ |
| 187 | - protected function updateBasePage( PageRiconferma $page ) { |
|
| 187 | + protected function updateBasePage ( PageRiconferma $page ) { |
|
| 188 | 188 | $this->getLogger()->info( "Updating base page for $page" ); |
| 189 | 189 | |
| 190 | 190 | $basePage = new Page( $page->getBaseTitle() ); |
| 191 | 191 | $current = $basePage->getContent(); |
| 192 | 192 | |
| 193 | 193 | $outcomeText = $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ? |
| 194 | - 'non riconfermato' : |
|
| 195 | - 'riconfermato'; |
|
| 194 | + 'non riconfermato' : 'riconfermato'; |
|
| 196 | 195 | $text = $page->isVote() ? "votazione: $outcomeText" : 'riconferma tacita'; |
| 197 | 196 | |
| 198 | 197 | $newContent = str_replace( 'riconferma in corso', $text, $current ); |
@@ -208,16 +207,16 @@ discard block |
||
| 208 | 207 | * @param PageRiconferma[] $pages |
| 209 | 208 | * @see UpdatesAround::addVote() |
| 210 | 209 | */ |
| 211 | - protected function updateVote( array $pages ) { |
|
| 210 | + protected function updateVote ( array $pages ) { |
|
| 212 | 211 | $this->getLogger()->info( |
| 213 | 212 | 'Updating votazioni: ' . implode( ', ', array_map( 'strval', $pages ) ) |
| 214 | 213 | ); |
| 215 | 214 | $votePage = new Page( $this->getConfig()->get( 'ric-vote-page' ) ); |
| 216 | 215 | $content = $votePage->getContent(); |
| 217 | 216 | |
| 218 | - $titles = []; |
|
| 217 | + $titles = [ ]; |
|
| 219 | 218 | foreach ( $pages as $page ) { |
| 220 | - $titles[] = preg_quote( $page->getTitle() ); |
|
| 219 | + $titles[ ] = preg_quote( $page->getTitle() ); |
|
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | $titleReg = implode( '|', array_map( 'preg_quote', $titles ) ); |
@@ -248,7 +247,7 @@ discard block |
||
| 248 | 247 | * @param array $pages |
| 249 | 248 | * @see UpdatesAround::addNews() |
| 250 | 249 | */ |
| 251 | - protected function updateNews( array $pages ) { |
|
| 250 | + protected function updateNews ( array $pages ) { |
|
| 252 | 251 | $simpleAmount = $voteAmount = 0; |
| 253 | 252 | foreach ( $pages as $page ) { |
| 254 | 253 | if ( $page->isVote() ) { |
@@ -268,12 +267,12 @@ discard block |
||
| 268 | 267 | $simpleReg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 269 | 268 | $voteReg = '!(\| *riconferme[ _]voto[ _]amministratori *= *)(\d+)!'; |
| 270 | 269 | |
| 271 | - $simpleMatches = $voteMatches = []; |
|
| 270 | + $simpleMatches = $voteMatches = [ ]; |
|
| 272 | 271 | preg_match( $simpleReg, $content, $simpleMatches ); |
| 273 | 272 | preg_match( $voteReg, $content, $voteMatches ); |
| 274 | 273 | |
| 275 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
| 276 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
| 274 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
| 275 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
| 277 | 276 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $content ); |
| 278 | 277 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
| 279 | 278 | |
@@ -293,7 +292,7 @@ discard block |
||
| 293 | 292 | * |
| 294 | 293 | * @param PageRiconferma[] $pages |
| 295 | 294 | */ |
| 296 | - protected function updateAdminList( array $pages ) { |
|
| 295 | + protected function updateAdminList ( array $pages ) { |
|
| 297 | 296 | $this->getLogger()->info( |
| 298 | 297 | 'Updating admin list: ' . implode( ', ', array_map( 'strval', $pages ) ) |
| 299 | 298 | ); |
@@ -301,17 +300,17 @@ discard block |
||
| 301 | 300 | $newContent = $adminsPage->getContent(); |
| 302 | 301 | $newDate = date( 'Ymd', strtotime( '+1 year' ) ); |
| 303 | 302 | |
| 304 | - $riconfNames = $removeNames = []; |
|
| 303 | + $riconfNames = $removeNames = [ ]; |
|
| 305 | 304 | foreach ( $pages as $page ) { |
| 306 | 305 | $user = $page->getUser(); |
| 307 | 306 | $reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+( *\|(?: *pausa)? *\}\}\n)!"; |
| 308 | 307 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
| 309 | 308 | // Remove the line |
| 310 | 309 | $newContent = preg_replace( $reg, '', $newContent ); |
| 311 | - $removeNames[] = $user; |
|
| 310 | + $removeNames[ ] = $user; |
|
| 312 | 311 | } else { |
| 313 | 312 | $newContent = preg_replace( $reg, '$1' . $newDate . '$2', $newContent ); |
| 314 | - $riconfNames[] = $user; |
|
| 313 | + $riconfNames[ ] = $user; |
|
| 315 | 314 | } |
| 316 | 315 | } |
| 317 | 316 | |
@@ -319,7 +318,7 @@ discard block |
||
| 319 | 318 | $lastUser = array_pop( $riconfNames ); |
| 320 | 319 | $riconfList = implode( ', ', $riconfNames ) . " e $lastUser"; |
| 321 | 320 | } elseif ( $riconfNames ) { |
| 322 | - $riconfList = $riconfNames[0]; |
|
| 321 | + $riconfList = $riconfNames[ 0 ]; |
|
| 323 | 322 | } else { |
| 324 | 323 | $riconfList = 'nessuno'; |
| 325 | 324 | } |
@@ -328,7 +327,7 @@ discard block |
||
| 328 | 327 | $lastUser = array_pop( $removeNames ); |
| 329 | 328 | $removeList = implode( ', ', $removeNames ) . " e $lastUser"; |
| 330 | 329 | } elseif ( $removeNames ) { |
| 331 | - $removeList = $removeNames[0]; |
|
| 330 | + $removeList = $removeNames[ 0 ]; |
|
| 332 | 331 | } else { |
| 333 | 332 | $removeList = 'nessuno'; |
| 334 | 333 | } |
@@ -351,13 +350,13 @@ discard block |
||
| 351 | 350 | /** |
| 352 | 351 | * @param PageRiconferma[] $pages |
| 353 | 352 | */ |
| 354 | - protected function updateCUList( array $pages ) { |
|
| 353 | + protected function updateCUList ( array $pages ) { |
|
| 355 | 354 | $this->getLogger()->info( 'Checking if CU list needs updating.' ); |
| 356 | 355 | $cuList = new Page( $this->getConfig()->get( 'cu-list-title' ) ); |
| 357 | 356 | $admins = $this->getDataProvider()->getUsersList(); |
| 358 | 357 | $newContent = $cuList->getContent(); |
| 359 | 358 | |
| 360 | - $riconfNames = $removeNames = []; |
|
| 359 | + $riconfNames = $removeNames = [ ]; |
|
| 361 | 360 | foreach ( $pages as $page ) { |
| 362 | 361 | $user = $page->getUser(); |
| 363 | 362 | if ( array_key_exists( 'checkuser', $admins[ $user ] ) ) { |
@@ -365,10 +364,10 @@ discard block |
||
| 365 | 364 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
| 366 | 365 | // Remove the line |
| 367 | 366 | $newContent = preg_replace( $reg, '', $newContent ); |
| 368 | - $removeNames[] = $user; |
|
| 367 | + $removeNames[ ] = $user; |
|
| 369 | 368 | } else { |
| 370 | 369 | $newContent = preg_replace( $reg, '$1{{subst:#time:j F Y}}$2', $newContent ); |
| 371 | - $riconfNames[] = $user; |
|
| 370 | + $riconfNames[ ] = $user; |
|
| 372 | 371 | } |
| 373 | 372 | } |
| 374 | 373 | } |
@@ -385,7 +384,7 @@ discard block |
||
| 385 | 384 | $lastUser = array_pop( $riconfNames ); |
| 386 | 385 | $riconfList = implode( ', ', $riconfNames ) . " e $lastUser"; |
| 387 | 386 | } elseif ( $riconfNames ) { |
| 388 | - $riconfList = $riconfNames[0]; |
|
| 387 | + $riconfList = $riconfNames[ 0 ]; |
|
| 389 | 388 | } else { |
| 390 | 389 | $riconfList = 'nessuno'; |
| 391 | 390 | } |
@@ -394,7 +393,7 @@ discard block |
||
| 394 | 393 | $lastUser = array_pop( $removeNames ); |
| 395 | 394 | $removeList = implode( ', ', $removeNames ) . " e $lastUser"; |
| 396 | 395 | } elseif ( $removeNames ) { |
| 397 | - $removeList = $removeNames[0]; |
|
| 396 | + $removeList = $removeNames[ 0 ]; |
|
| 398 | 397 | } else { |
| 399 | 398 | $removeList = 'nessuno'; |
| 400 | 399 | } |
@@ -416,17 +415,17 @@ discard block |
||
| 416 | 415 | /** |
| 417 | 416 | * @param PageRiconferma[] $pages |
| 418 | 417 | */ |
| 419 | - protected function updateBurList( array $pages ) { |
|
| 418 | + protected function updateBurList ( array $pages ) { |
|
| 420 | 419 | $this->getLogger()->info( 'Checking if bur list needs updating.' ); |
| 421 | 420 | $admins = $this->getDataProvider()->getUsersList(); |
| 422 | 421 | |
| 423 | - $remove = []; |
|
| 422 | + $remove = [ ]; |
|
| 424 | 423 | foreach ( $pages as $page ) { |
| 425 | 424 | $user = $page->getUser(); |
| 426 | 425 | if ( array_key_exists( 'bureaucrat', $admins[ $user ] ) && |
| 427 | 426 | $page->getOutcome() & PageRiconferma::OUTCOME_FAIL |
| 428 | 427 | ) { |
| 429 | - $remove[] = $user; |
|
| 428 | + $remove[ ] = $user; |
|
| 430 | 429 | } |
| 431 | 430 | } |
| 432 | 431 | |
@@ -445,7 +444,7 @@ discard block |
||
| 445 | 444 | $lastUser = array_pop( $remove ); |
| 446 | 445 | $removeList = implode( ', ', $remove ) . " e $lastUser"; |
| 447 | 446 | } else { |
| 448 | - $removeList = $remove[0]; |
|
| 447 | + $removeList = $remove[ 0 ]; |
|
| 449 | 448 | } |
| 450 | 449 | |
| 451 | 450 | $summary = $this->msg( 'bur-list-update-summary' ) |
@@ -464,7 +463,7 @@ discard block |
||
| 464 | 463 | * |
| 465 | 464 | * @param PageRiconferma[] $pages |
| 466 | 465 | */ |
| 467 | - protected function requestRemoval( array $pages ) { |
|
| 466 | + protected function requestRemoval ( array $pages ) { |
|
| 468 | 467 | $this->getLogger()->info( |
| 469 | 468 | 'Requesting removal on meta for: ' . implode( ', ', array_map( 'strval', $pages ) ) |
| 470 | 469 | ); |
@@ -508,14 +507,14 @@ discard block |
||
| 508 | 507 | * |
| 509 | 508 | * @param PageRiconferma[] $pages |
| 510 | 509 | */ |
| 511 | - protected function updateAnnunci( array $pages ) { |
|
| 510 | + protected function updateAnnunci ( array $pages ) { |
|
| 512 | 511 | $this->getLogger()->info( 'Updating annunci' ); |
| 513 | 512 | |
| 514 | - $names = []; |
|
| 513 | + $names = [ ]; |
|
| 515 | 514 | $text = ''; |
| 516 | 515 | foreach ( $pages as $page ) { |
| 517 | 516 | $user = $page->getUser(); |
| 518 | - $names[] = $user; |
|
| 517 | + $names[ ] = $user; |
|
| 519 | 518 | $text .= "{{Breve|admin|{{subst:#time:j}}|[[Utente:$user|]] " . |
| 520 | 519 | "non è stato riconfermato [[WP:A|amministratore]].}}\n"; |
| 521 | 520 | } |
@@ -538,7 +537,7 @@ discard block |
||
| 538 | 537 | $lastUser = array_pop( $names ); |
| 539 | 538 | $namesList = implode( ', ', $names ) . " e $lastUser"; |
| 540 | 539 | } else { |
| 541 | - $namesList = $names[0]; |
|
| 540 | + $namesList = $names[ 0 ]; |
|
| 542 | 541 | } |
| 543 | 542 | |
| 544 | 543 | $summary = $this->msg( 'annunci-summary' ) |
@@ -557,16 +556,16 @@ discard block |
||
| 557 | 556 | * |
| 558 | 557 | * @param PageRiconferma[] $pages |
| 559 | 558 | */ |
| 560 | - protected function updateUltimeNotizie( array $pages ) { |
|
| 559 | + protected function updateUltimeNotizie ( array $pages ) { |
|
| 561 | 560 | $this->getLogger()->info( 'Updating ultime notizie' ); |
| 562 | 561 | $notiziePage = new Page( $this->getConfig()->get( 'ultimenotizie-title' ) ); |
| 563 | 562 | |
| 564 | - $names = []; |
|
| 563 | + $names = [ ]; |
|
| 565 | 564 | $text = ''; |
| 566 | 565 | foreach ( $pages as $page ) { |
| 567 | 566 | $user = $page->getUser(); |
| 568 | 567 | $title = $page->getTitle(); |
| 569 | - $names[] = $user; |
|
| 568 | + $names[ ] = $user; |
|
| 570 | 569 | $text .= "'''{{subst:#time:j F}}''': [[Utente:$user|]] non è stato [[$title|riconfermato]] " . |
| 571 | 570 | '[[WP:A|amministratore]]; ora gli admin sono {{subst:#expr: {{NUMBEROFADMINS}} - 1}}.'; |
| 572 | 571 | } |
@@ -585,7 +584,7 @@ discard block |
||
| 585 | 584 | $lastUser = array_pop( $names ); |
| 586 | 585 | $namesList = implode( ', ', $names ) . " e $lastUser"; |
| 587 | 586 | } else { |
| 588 | - $namesList = $names[0]; |
|
| 587 | + $namesList = $names[ 0 ]; |
|
| 589 | 588 | } |
| 590 | 589 | |
| 591 | 590 | $summary = $this->msg( 'ultimenotizie-summary' ) |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | /** @var self */ |
| 13 | 13 | private static $instance; |
| 14 | 14 | /** @var array */ |
| 15 | - private $opts = []; |
|
| 15 | + private $opts = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Use self::init() and self::getInstance() |
| 19 | 19 | */ |
| 20 | - private function __construct() { |
|
| 20 | + private function __construct () { |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | * @param array $defaults |
| 27 | 27 | * @throws ConfigException |
| 28 | 28 | */ |
| 29 | - public static function init( array $defaults ) { |
|
| 29 | + public static function init ( array $defaults ) { |
|
| 30 | 30 | if ( self::$instance ) { |
| 31 | 31 | throw new ConfigException( 'Config was already initialized' ); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $inst = new self; |
| 35 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
| 36 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
| 37 | - $inst->set( 'username', $defaults['username'] ); |
|
| 38 | - $inst->set( 'password', $defaults['password'] ); |
|
| 35 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
| 36 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
| 37 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
| 38 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
| 39 | 39 | self::$instance = $inst; |
| 40 | 40 | |
| 41 | 41 | // On-wiki values |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param string $key |
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | - public function getWikiMessage( string $key ) : string { |
|
| 57 | + public function getWikiMessage ( string $key ) : string { |
|
| 58 | 58 | static $messages = null; |
| 59 | 59 | if ( $messages === null ) { |
| 60 | 60 | try { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 68 | - return $messages[$key]; |
|
| 68 | + return $messages[ $key ]; |
|
| 69 | 69 | } |
| 70 | 70 | /** |
| 71 | 71 | * Set a config value. |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string $key |
| 74 | 74 | * @param mixed $value |
| 75 | 75 | */ |
| 76 | - protected function set( string $key, $value ) { |
|
| 76 | + protected function set ( string $key, $value ) { |
|
| 77 | 77 | $this->opts[ $key ] = $value; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return self |
| 84 | 84 | * @throws ConfigException |
| 85 | 85 | */ |
| 86 | - public static function getInstance() : self { |
|
| 86 | + public static function getInstance () : self { |
|
| 87 | 87 | if ( !self::$instance ) { |
| 88 | 88 | throw new ConfigException( 'Config not yet initialized' ); |
| 89 | 89 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return mixed |
| 98 | 98 | * @throws ConfigException |
| 99 | 99 | */ |
| 100 | - public function get( string $opt ) { |
|
| 100 | + public function get ( string $opt ) { |
|
| 101 | 101 | if ( !isset( $this->opts[ $opt ] ) ) { |
| 102 | 102 | throw new ConfigException( "Config option '$opt' not set." ); |
| 103 | 103 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | /** @var string */ |
| 30 | 30 | protected $method = 'GET'; |
| 31 | 31 | /** @var string[] */ |
| 32 | - protected $newCookies = []; |
|
| 32 | + protected $newCookies = [ ]; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Use self::newFromParams, which will provide the right class to use |
| 36 | 36 | * |
| 37 | 37 | * @param array $params |
| 38 | 38 | */ |
| 39 | - protected function __construct( array $params ) { |
|
| 39 | + protected function __construct ( array $params ) { |
|
| 40 | 40 | $this->params = [ 'format' => 'json' ] + $params; |
| 41 | 41 | $this->url = DEFAULT_URL; |
| 42 | 42 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param array $params |
| 48 | 48 | * @return self |
| 49 | 49 | */ |
| 50 | - public static function newFromParams( array $params ) : self { |
|
| 50 | + public static function newFromParams ( array $params ) : self { |
|
| 51 | 51 | if ( extension_loaded( 'curl' ) ) { |
| 52 | 52 | $ret = new CurlRequest( $params ); |
| 53 | 53 | } else { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return self For chaining |
| 63 | 63 | */ |
| 64 | - public function setPost() : self { |
|
| 64 | + public function setPost () : self { |
|
| 65 | 65 | $this->method = 'POST'; |
| 66 | 66 | return $this; |
| 67 | 67 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $url |
| 73 | 73 | * @return self for chaining |
| 74 | 74 | */ |
| 75 | - public function setUrl( string $url ) : self { |
|
| 75 | + public function setUrl ( string $url ) : self { |
|
| 76 | 76 | $this->url = $url; |
| 77 | 77 | return $this; |
| 78 | 78 | } |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @return \stdClass |
| 84 | 84 | */ |
| 85 | - public function execute() : \stdClass { |
|
| 85 | + public function execute () : \stdClass { |
|
| 86 | 86 | $curParams = $this->params; |
| 87 | - $sets = []; |
|
| 87 | + $sets = [ ]; |
|
| 88 | 88 | do { |
| 89 | 89 | $res = $this->makeRequestInternal( $curParams ); |
| 90 | 90 | |
| 91 | 91 | $this->handleErrorAndWarnings( $res ); |
| 92 | - $sets[] = $res; |
|
| 92 | + $sets[ ] = $res; |
|
| 93 | 93 | |
| 94 | 94 | $finished = true; |
| 95 | 95 | if ( isset( $res->continue ) ) { |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | * @param array $params |
| 108 | 108 | * @return \stdClass |
| 109 | 109 | */ |
| 110 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 110 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 111 | 111 | if ( $this->method === 'POST' ) { |
| 112 | - $params['maxlag'] = self::MAXLAG; |
|
| 112 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 113 | 113 | } |
| 114 | 114 | $params = http_build_query( $params ); |
| 115 | 115 | |
@@ -125,17 +125,17 @@ discard block |
||
| 125 | 125 | * @param string $params |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 128 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * After a request, set cookies for the next ones |
| 132 | 132 | * |
| 133 | 133 | * @param array $cookies |
| 134 | 134 | */ |
| 135 | - protected function setCookies( array $cookies ) { |
|
| 135 | + protected function setCookies ( array $cookies ) { |
|
| 136 | 136 | foreach ( $cookies as $cookie ) { |
| 137 | 137 | $bits = explode( ';', $cookie ); |
| 138 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 138 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 139 | 139 | self::$cookiesToSet[ $name ] = $value; |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @param \stdClass $res |
| 147 | 147 | * @throws APIRequestException |
| 148 | 148 | */ |
| 149 | - protected function handleErrorAndWarnings( $res ) { |
|
| 149 | + protected function handleErrorAndWarnings ( $res ) { |
|
| 150 | 150 | if ( isset( $res->error ) ) { |
| 151 | 151 | switch ( $res->error->code ) { |
| 152 | 152 | case 'missingtitle': |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @param \stdClass[] $sets |
| 173 | 173 | * @return \stdClass |
| 174 | 174 | */ |
| 175 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 175 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 176 | 176 | // Use the first set as template |
| 177 | 177 | $ret = array_shift( $sets ); |
| 178 | 178 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param array|\stdClass $second |
| 190 | 190 | * @return array|\stdClass array |
| 191 | 191 | */ |
| 192 | - private function recursiveMerge( $first, $second ) { |
|
| 192 | + private function recursiveMerge ( $first, $second ) { |
|
| 193 | 193 | $ret = $first; |
| 194 | 194 | if ( is_array( $second ) ) { |
| 195 | 195 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -207,14 +207,14 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return array |
| 209 | 209 | */ |
| 210 | - protected function getHeaders() :array { |
|
| 210 | + protected function getHeaders () :array { |
|
| 211 | 211 | $ret = self::HEADERS; |
| 212 | 212 | if ( self::$cookiesToSet ) { |
| 213 | - $cookies = []; |
|
| 213 | + $cookies = [ ]; |
|
| 214 | 214 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 215 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 215 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 216 | 216 | } |
| 217 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 217 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 218 | 218 | } |
| 219 | 219 | return $ret; |
| 220 | 220 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param array $headers |
| 226 | 226 | * @return string |
| 227 | 227 | */ |
| 228 | - protected function buildHeadersString( array $headers ) : string { |
|
| 228 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 229 | 229 | $ret = ''; |
| 230 | 230 | foreach ( $headers as $header ) { |
| 231 | 231 | $ret .= "$header\r\n"; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @inheritDoc |
| 11 | 11 | */ |
| 12 | - protected function reallyMakeRequest( string $params ) : string { |
|
| 12 | + protected function reallyMakeRequest ( string $params ) : string { |
|
| 13 | 13 | $context = [ |
| 14 | 14 | 'http' => [ |
| 15 | 15 | 'method' => $this->method, |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | ]; |
| 19 | 19 | $url = $this->url; |
| 20 | 20 | if ( $this->method === 'POST' ) { |
| 21 | - $context['http']['content'] = $params; |
|
| 21 | + $context[ 'http' ][ 'content' ] = $params; |
|
| 22 | 22 | } else { |
| 23 | 23 | $url = "$url?$params"; |
| 24 | 24 | } |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | foreach ( $http_response_header as $header ) { |
| 29 | 29 | $bits = explode( ':', $header, 2 ); |
| 30 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
| 31 | - $this->newCookies[] = $bits[1]; |
|
| 30 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
| 31 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @param string $title |
| 18 | 18 | * @param string $domain The site where the page lives, if different from default |
| 19 | 19 | */ |
| 20 | - public function __construct( string $title, string $domain = DEFAULT_URL ) { |
|
| 20 | + public function __construct ( string $title, string $domain = DEFAULT_URL ) { |
|
| 21 | 21 | $this->title = $title; |
| 22 | 22 | $this->controller = new WikiController( $domain ); |
| 23 | 23 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - public function getTitle() : string { |
|
| 28 | + public function getTitle () : string { |
|
| 29 | 29 | return $this->title; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param int|null $section A section number to retrieve the content of that section |
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | - public function getContent( int $section = null ) : string { |
|
| 38 | + public function getContent ( int $section = null ) : string { |
|
| 39 | 39 | if ( $this->content === null ) { |
| 40 | 40 | $this->content = $this->controller->getPageContent( $this->title, $section ); |
| 41 | 41 | } |
@@ -47,16 +47,16 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param array $params |
| 49 | 49 | */ |
| 50 | - public function edit( array $params ) { |
|
| 50 | + public function edit ( array $params ) { |
|
| 51 | 51 | $params = [ |
| 52 | 52 | 'title' => $this->getTitle() |
| 53 | 53 | ] + $params; |
| 54 | 54 | |
| 55 | 55 | $this->controller->editPage( $params ); |
| 56 | - if ( isset( $params['text'] ) ) { |
|
| 57 | - $this->content = $params['text']; |
|
| 58 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
| 59 | - $this->content .= $params['appendtext']; |
|
| 56 | + if ( isset( $params[ 'text' ] ) ) { |
|
| 57 | + $this->content = $params[ 'text' ]; |
|
| 58 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
| 59 | + $this->content .= $params[ 'appendtext' ]; |
|
| 60 | 60 | } else { |
| 61 | 61 | // Clear the cache anyway |
| 62 | 62 | ( new Logger )->warning( 'Resetting content cache. Params: ' . var_export( $params, true ) ); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | - public function __toString() { |
|
| 72 | + public function __toString () { |
|
| 73 | 73 | return $this->getTitle(); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @param string $domain The URL of the wiki, if different from default |
| 26 | 26 | */ |
| 27 | - public function __construct( string $domain = DEFAULT_URL ) { |
|
| 27 | + public function __construct ( string $domain = DEFAULT_URL ) { |
|
| 28 | 28 | $this->logger = new Logger; |
| 29 | 29 | $this->domain = $domain; |
| 30 | 30 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | * @throws MissingPageException |
| 39 | 39 | */ |
| 40 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 40 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 41 | 41 | $this->logger->debug( "Retrieving page $title" ); |
| 42 | 42 | $params = [ |
| 43 | 43 | 'action' => 'query', |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | ]; |
| 49 | 49 | |
| 50 | 50 | if ( $section !== null ) { |
| 51 | - $params['rvsection'] = $section; |
|
| 51 | + $params[ 'rvsection' ] = $section; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $req = RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | throw new MissingPageException( $title ); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - return $page->revisions[0]->slots->main->{ '*' }; |
|
| 61 | + return $page->revisions[ 0 ]->slots->main->{ '*' }; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param array $params |
| 68 | 68 | * @throws EditException |
| 69 | 69 | */ |
| 70 | - public function editPage( array $params ) { |
|
| 70 | + public function editPage ( array $params ) { |
|
| 71 | 71 | $this->login(); |
| 72 | 72 | |
| 73 | 73 | $params = [ |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @return string |
| 93 | 93 | * @fixme Not the right place for this |
| 94 | 94 | */ |
| 95 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
| 95 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
| 96 | 96 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 97 | 97 | $timeString = strftime( '%e %B alle %R', $timestamp ); |
| 98 | 98 | // Remove the left space if day has a single digit |
@@ -111,16 +111,16 @@ discard block |
||
| 111 | 111 | * @fixme Not the right place for this |
| 112 | 112 | * @todo Is there a better way? |
| 113 | 113 | */ |
| 114 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
| 114 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
| 115 | 115 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 116 | 116 | $bits = strptime( $timeString, '%e %m %Y alle %H:%M' ); |
| 117 | 117 | $timestamp = mktime( |
| 118 | - $bits['tm_hour'], |
|
| 119 | - $bits['tm_min'], |
|
| 118 | + $bits[ 'tm_hour' ], |
|
| 119 | + $bits[ 'tm_min' ], |
|
| 120 | 120 | 0, |
| 121 | - $bits['tm_mon'] + 1, |
|
| 122 | - $bits['tm_mday'], |
|
| 123 | - $bits['tm_year'] + 1900 |
|
| 121 | + $bits[ 'tm_mon' ] + 1, |
|
| 122 | + $bits[ 'tm_mday' ], |
|
| 123 | + $bits[ 'tm_year' ] + 1900 |
|
| 124 | 124 | ); |
| 125 | 125 | setlocale( LC_TIME, $oldLoc ); |
| 126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 131 | 131 | * @throws LoginException |
| 132 | 132 | */ |
| 133 | - public function login() { |
|
| 133 | + public function login () { |
|
| 134 | 134 | if ( self::$loggedIn ) { |
| 135 | 135 | $this->logger->debug( 'Already logged in' ); |
| 136 | 136 | return; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | self::$loggedIn = true; |
| 159 | 159 | // Clear tokens cache |
| 160 | - $this->tokens = []; |
|
| 160 | + $this->tokens = [ ]; |
|
| 161 | 161 | $this->logger->info( 'Login succeeded' ); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param string $type |
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | - public function getToken( string $type ) : string { |
|
| 170 | + public function getToken ( string $type ) : string { |
|
| 171 | 171 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 172 | 172 | $params = [ |
| 173 | 173 | 'action' => 'query', |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @param string $title |
| 191 | 191 | * @return int |
| 192 | 192 | */ |
| 193 | - public function getPageCreationTS( string $title ) : int { |
|
| 193 | + public function getPageCreationTS ( string $title ) : int { |
|
| 194 | 194 | $params = [ |
| 195 | 195 | 'action' => 'query', |
| 196 | 196 | 'prop' => 'revisions', |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $res = RequestBase::newFromParams( $params )->setUrl( $this->domain )->execute(); |
| 205 | 205 | $data = $res->query->pages; |
| 206 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 206 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param string $title |
| 213 | 213 | * @param string $reason |
| 214 | 214 | */ |
| 215 | - public function protectPage( string $title, string $reason ) { |
|
| 215 | + public function protectPage ( string $title, string $reason ) { |
|
| 216 | 216 | $this->logger->info( "Protecting page $title" ); |
| 217 | 217 | $this->login(); |
| 218 | 218 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @inheritDoc |
| 20 | 20 | */ |
| 21 | - public function run() : TaskResult { |
|
| 21 | + public function run () : TaskResult { |
|
| 22 | 22 | $this->getLogger()->info( 'Starting task UpdateList' ); |
| 23 | 23 | $this->actualList = $this->getActualAdmins(); |
| 24 | 24 | $this->botList = $this->getDataProvider()->getUsersList(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | - protected function getActualAdmins() : array { |
|
| 56 | + protected function getActualAdmins () : array { |
|
| 57 | 57 | $this->getLogger()->debug( 'Retrieving admins - API' ); |
| 58 | 58 | $params = [ |
| 59 | 59 | 'action' => 'query', |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param \stdClass $data |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 75 | - $ret = []; |
|
| 74 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 75 | + $ret = [ ]; |
|
| 76 | 76 | $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
| 77 | 77 | foreach ( $data->query->allusers as $u ) { |
| 78 | 78 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -89,22 +89,22 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return array[] |
| 91 | 91 | */ |
| 92 | - protected function getMissingGroups() : array { |
|
| 93 | - $missing = []; |
|
| 92 | + protected function getMissingGroups () : array { |
|
| 93 | + $missing = [ ]; |
|
| 94 | 94 | foreach ( $this->actualList as $adm => $groups ) { |
| 95 | - $groupsList = []; |
|
| 95 | + $groupsList = [ ]; |
|
| 96 | 96 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 97 | 97 | $groupsList = $groups; |
| 98 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 98 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 99 | 99 | // Only some groups are missing |
| 100 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 100 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | foreach ( $groupsList as $group ) { |
| 104 | 104 | try { |
| 105 | 105 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 106 | 106 | } catch ( TaskException $e ) { |
| 107 | - $this->errors[] = $e->getMessage(); |
|
| 107 | + $this->errors[ ] = $e->getMessage(); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return string |
| 120 | 120 | * @throws TaskException |
| 121 | 121 | */ |
| 122 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 122 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 123 | 123 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 124 | 124 | |
| 125 | 125 | $url = DEFAULT_URL; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param string $group |
| 155 | 155 | * @return string|null |
| 156 | 156 | */ |
| 157 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 157 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 158 | 158 | $ts = null; |
| 159 | 159 | foreach ( $data->query->logevents as $entry ) { |
| 160 | 160 | if ( !isset( $entry->params ) ) { |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return array[] |
| 178 | 178 | */ |
| 179 | - protected function getExtraGroups() : array { |
|
| 180 | - $extra = []; |
|
| 179 | + protected function getExtraGroups () : array { |
|
| 180 | + $extra = [ ]; |
|
| 181 | 181 | foreach ( $this->botList as $name => $groups ) { |
| 182 | 182 | if ( !isset( $this->actualList[ $name ] ) ) { |
| 183 | 183 | $extra[ $name ] = $groups; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @param array $newContent |
| 195 | 195 | */ |
| 196 | - protected function doUpdateList( array $newContent ) { |
|
| 196 | + protected function doUpdateList ( array $newContent ) { |
|
| 197 | 197 | $this->getLogger()->info( 'Updating admin list' ); |
| 198 | 198 | |
| 199 | 199 | $params = [ |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param array[] $extra |
| 213 | 213 | * @return array[] |
| 214 | 214 | */ |
| 215 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 215 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 216 | 216 | $newContent = $this->botList; |
| 217 | 217 | foreach ( $newContent as $user => $groups ) { |
| 218 | 218 | if ( isset( $missing[ $user ] ) ) { |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | /** |
| 3 | 3 | * Entry point for the bot, called by CLI |
| 4 | 4 | */ |
@@ -38,9 +38,8 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | /* URL (for debugging purpose) */ |
| 40 | 40 | $urlParam = getopt( '', [ 'force-url:' ] ); |
| 41 | -$url = isset( $urlParam['force-url'] ) ? |
|
| 42 | - $urlParam['force-url'] : |
|
| 43 | - 'https://it.wikipedia.org/w/api.php'; |
|
| 41 | +$url = isset( $urlParam[ 'force-url' ] ) ? |
|
| 42 | + $urlParam[ 'force-url' ] : 'https://it.wikipedia.org/w/api.php'; |
|
| 44 | 43 | |
| 45 | 44 | define( 'DEFAULT_URL', $url ); |
| 46 | 45 | |