@@ -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 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @inheritDoc |
| 14 | 14 | */ |
| 15 | - public function run() : TaskResult { |
|
| 15 | + public function run () : TaskResult { |
|
| 16 | 16 | $this->getLogger()->info( 'Starting task UpdatesAround' ); |
| 17 | 17 | |
| 18 | 18 | $pages = $this->getDataProvider()->getCreatedPages(); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @param string[] $pages |
| 38 | 38 | */ |
| 39 | - protected function addToMainPage( array $pages ) { |
|
| 39 | + protected function addToMainPage ( array $pages ) { |
|
| 40 | 40 | $this->getLogger()->info( |
| 41 | 41 | 'Adding the following to main: ' . implode( ', ', $pages ) |
| 42 | 42 | ); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $summary = preg_replace_callback( |
| 54 | 54 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 55 | 55 | function ( $matches ) { |
| 56 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 56 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 57 | 57 | }, |
| 58 | 58 | $summary |
| 59 | 59 | ); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param string[] $pages |
| 74 | 74 | */ |
| 75 | - protected function addVote( array $pages ) { |
|
| 75 | + protected function addVote ( array $pages ) { |
|
| 76 | 76 | $this->getLogger()->info( |
| 77 | 77 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
| 78 | 78 | ); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $time = $this->getTimeWithArticle(); |
| 84 | 84 | $newLines = ''; |
| 85 | 85 | foreach ( $pages as $page ) { |
| 86 | - $user = explode( '/', $page )[2]; |
|
| 86 | + $user = explode( '/', $page )[ 2 ]; |
|
| 87 | 87 | $newLines .= "*[[Utente:$user|]]. La [[$page|procedura]] termina $time;\n"; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $content, 1 ); |
| 94 | 94 | } else { |
| 95 | 95 | // Start section |
| 96 | - $matches = []; |
|
| 96 | + $matches = [ ]; |
|
| 97 | 97 | if ( preg_match( $introReg, $content, $matches ) === false ) { |
| 98 | 98 | throw new TaskException( 'Intro not found in vote page' ); |
| 99 | 99 | } |
| 100 | 100 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 101 | 101 | // Replace semicolon with full stop |
| 102 | 102 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
| 103 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $content, 1 ); |
|
| 103 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $content, 1 ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $summary = strtr( |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $summary = preg_replace_callback( |
| 111 | 111 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 112 | 112 | function ( $matches ) { |
| 113 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 113 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 114 | 114 | }, |
| 115 | 115 | $summary |
| 116 | 116 | ); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - private function getTimeWithArticle() : string { |
|
| 132 | + private function getTimeWithArticle () : string { |
|
| 133 | 133 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 134 | 134 | $endTS = time() + ( 60 * 60 * 24 * 7 ); |
| 135 | 135 | $endTime = strftime( '%e %B alle %R', $endTS ); |
@@ -146,26 +146,26 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @param int $amount |
| 148 | 148 | */ |
| 149 | - protected function addNews( int $amount ) { |
|
| 149 | + protected function addNews ( int $amount ) { |
|
| 150 | 150 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
| 151 | 151 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 152 | 152 | |
| 153 | 153 | $content = $this->getController()->getPageContent( $newsPage ); |
| 154 | 154 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 155 | 155 | |
| 156 | - $matches = []; |
|
| 156 | + $matches = [ ]; |
|
| 157 | 157 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 158 | 158 | throw new TaskException( 'Param not found in news page' ); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $newNum = (int)$matches[2] + $amount; |
|
| 161 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
| 162 | 162 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 163 | 163 | |
| 164 | 164 | $summary = strtr( $this->getConfig()->get( 'ric-news-page-summary' ), [ '$num' => $amount ] ); |
| 165 | 165 | $summary = preg_replace_callback( |
| 166 | 166 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 167 | 167 | function ( $matches ) { |
| 168 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 168 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 169 | 169 | }, |
| 170 | 170 | $summary |
| 171 | 171 | ); |
@@ -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 | $titles = $this->getPagesList(); |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return string[] |
| 42 | 42 | */ |
| 43 | - protected function getPagesList() : array { |
|
| 43 | + protected function getPagesList () : array { |
|
| 44 | 44 | $allPages = $this->getTranscludedPages(); |
| 45 | - $ret = []; |
|
| 45 | + $ret = [ ]; |
|
| 46 | 46 | foreach ( $allPages as $page ) { |
| 47 | 47 | $created = $this->getController()->getPageCreationTS( $page ); |
| 48 | 48 | if ( time() - $created <= 60 * 60 * 24 * 7 && !$this->hasOpposition( $page ) ) { |
| 49 | - $ret[] = $page; |
|
| 49 | + $ret[ ] = $page; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | return $ret; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return string[] |
| 59 | 59 | */ |
| 60 | - protected function getTranscludedPages() : array { |
|
| 60 | + protected function getTranscludedPages () : array { |
|
| 61 | 61 | $baseTitle = $this->getConfig()->get( 'ric-main-page' ); |
| 62 | 62 | $params = [ |
| 63 | 63 | 'action' => 'query', |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $res = RequestBase::newFromParams( $params )->execute(); |
| 71 | 71 | $pages = $res->query->pages; |
| 72 | - $ret = []; |
|
| 72 | + $ret = [ ]; |
|
| 73 | 73 | foreach ( reset( $pages )->templates as $page ) { |
| 74 | 74 | if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) { |
| 75 | - $ret[] = $page->title; |
|
| 75 | + $ret[ ] = $page->title; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | return $ret; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param string $page |
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | - protected function hasOpposition( string $page ) : bool { |
|
| 85 | + protected function hasOpposition ( string $page ) : bool { |
|
| 86 | 86 | $params = [ |
| 87 | 87 | 'action' => 'query', |
| 88 | 88 | 'prop' => 'revisions', |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ]; |
| 94 | 94 | $res = RequestBase::newFromParams( $params )->execute(); |
| 95 | 95 | $page = reset( $res->query->pages ); |
| 96 | - $content = $page->revisions[0]->slots->main->{ '*' }; |
|
| 96 | + $content = $page->revisions[ 0 ]->slots->main->{ '*' }; |
|
| 97 | 97 | // Let's hope that this is good enough... |
| 98 | 98 | $votes = substr_count( $content, "\n\# *(?![#*])" ); |
| 99 | 99 | return $votes >= 15; |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | * @param string[] $titles |
| 105 | 105 | * @see UpdatesAround::addToMainPage() |
| 106 | 106 | */ |
| 107 | - protected function removeFromMainPage( array $titles ) { |
|
| 107 | + protected function removeFromMainPage ( array $titles ) { |
|
| 108 | 108 | $this->getLogger()->info( 'Removing from main: ' . implode( ', ', $titles ) ); |
| 109 | 109 | |
| 110 | 110 | $mainPage = $this->getConfig()->get( 'ric-main-page' ); |
| 111 | 111 | $content = $this->getController()->getPageContent( $mainPage ); |
| 112 | - $translations = []; |
|
| 112 | + $translations = [ ]; |
|
| 113 | 113 | foreach ( $titles as $title ) { |
| 114 | 114 | $translations[ '{{' . $title . '}}' ] = ''; |
| 115 | 115 | } |
@@ -127,24 +127,24 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @param string[] $titles |
| 129 | 129 | */ |
| 130 | - protected function addToArchive( array $titles ) { |
|
| 130 | + protected function addToArchive ( array $titles ) { |
|
| 131 | 131 | $this->getLogger()->info( 'Adding to archive: ' . implode( ', ', $titles ) ); |
| 132 | 132 | |
| 133 | 133 | $archiveTitle = $this->getConfig()->get( 'close-archive-title' ); |
| 134 | 134 | $archiveTitle = "$archiveTitle/" . date( 'Y' ); |
| 135 | 135 | |
| 136 | 136 | $append = ''; |
| 137 | - $archivedList = []; |
|
| 137 | + $archivedList = [ ]; |
|
| 138 | 138 | foreach ( $titles as $page ) { |
| 139 | 139 | $append .= '{{' . $page . "}}\n"; |
| 140 | - $archivedList[] = explode( '/', $page, 3 )[2]; |
|
| 140 | + $archivedList[ ] = explode( '/', $page, 3 )[ 2 ]; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | if ( count( $archivedList ) > 1 ) { |
| 144 | 144 | $last = array_pop( $archivedList ); |
| 145 | 145 | $userNums = implode( ', ', $archivedList ) . " e $last"; |
| 146 | 146 | } else { |
| 147 | - $userNums = $archivedList[0]; |
|
| 147 | + $userNums = $archivedList[ 0 ]; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $summary = strtr( |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param string $title |
| 166 | 166 | * @see CreatePages::updateBasePage() |
| 167 | 167 | */ |
| 168 | - protected function updateBasePage( string $title ) { |
|
| 168 | + protected function updateBasePage ( string $title ) { |
|
| 169 | 169 | $this->getLogger()->info( "Updating base page $title" ); |
| 170 | 170 | |
| 171 | 171 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal WTF Phan what's wrong w/ u? |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @param string[] $titles |
| 187 | 187 | * @see UpdatesAround::addVote() |
| 188 | 188 | */ |
| 189 | - protected function updateVote( array $titles ) { |
|
| 189 | + protected function updateVote ( array $titles ) { |
|
| 190 | 190 | $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
| 191 | 191 | $content = $this->getController()->getPageContent( $votePage ); |
| 192 | 192 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $summary = preg_replace_callback( |
| 206 | 206 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 207 | 207 | function ( $matches ) { |
| 208 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 208 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 209 | 209 | }, |
| 210 | 210 | $summary |
| 211 | 211 | ); |
@@ -224,19 +224,19 @@ discard block |
||
| 224 | 224 | * @throws TaskException |
| 225 | 225 | * @see UpdatesAround::addNews() |
| 226 | 226 | */ |
| 227 | - protected function updateNews( int $amount ) { |
|
| 227 | + protected function updateNews ( int $amount ) { |
|
| 228 | 228 | $this->getLogger()->info( "Decreasing the news counter by $amount" ); |
| 229 | 229 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 230 | 230 | |
| 231 | 231 | $content = $this->getController()->getPageContent( $newsPage ); |
| 232 | 232 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 233 | 233 | |
| 234 | - $matches = []; |
|
| 234 | + $matches = [ ]; |
|
| 235 | 235 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 236 | 236 | throw new TaskException( 'Param not found in news page' ); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - $newNum = (int)$matches[2] - $amount; |
|
| 239 | + $newNum = (int)$matches[ 2 ] - $amount; |
|
| 240 | 240 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 241 | 241 | |
| 242 | 242 | $summary = strtr( |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $summary = preg_replace_callback( |
| 247 | 247 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 248 | 248 | function ( $matches ) { |
| 249 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 249 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 250 | 250 | }, |
| 251 | 251 | $summary |
| 252 | 252 | ); |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @param string[] $titles |
| 267 | 267 | */ |
| 268 | - protected function updateAdminList( array $titles ) { |
|
| 268 | + protected function updateAdminList ( array $titles ) { |
|
| 269 | 269 | $listTitle = $this->getConfig()->get( 'admins-list' ); |
| 270 | 270 | $content = $this->getController()->getPageContent( $listTitle ); |
| 271 | 271 | $newDate = date( 'Ymd', strtotime( '+1 year' ) ); |
| 272 | 272 | |
| 273 | - $names = []; |
|
| 273 | + $names = [ ]; |
|
| 274 | 274 | foreach ( $titles as $title ) { |
| 275 | - $user = explode( '/', $title )[2]; |
|
| 276 | - $names[] = $user; |
|
| 275 | + $user = explode( '/', $title )[ 2 ]; |
|
| 276 | + $names[ ] = $user; |
|
| 277 | 277 | $reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+(?= *\|(?: *pausa)? *\}\})!"; |
| 278 | 278 | $content = preg_replace( $reg, '$1' . $newDate, $content ); |
| 279 | 279 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | $lastUser = array_pop( $names ); |
| 283 | 283 | $usersList = implode( ', ', $names ) . " e $lastUser"; |
| 284 | 284 | } else { |
| 285 | - $usersList = $names[0]; |
|
| 285 | + $usersList = $names[ 0 ]; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $summary = strtr( |