@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function run() : TaskResult { |
|
| 16 | + public function run () : TaskResult { |
|
| 17 | 17 | $this->getLogger()->info( 'Starting task UpdatesAround' ); |
| 18 | 18 | |
| 19 | 19 | $pages = $this->getDataProvider()->getCreatedPages(); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param string[] $pages |
| 39 | 39 | */ |
| 40 | - protected function addToMainPage( array $pages ) { |
|
| 40 | + protected function addToMainPage ( array $pages ) { |
|
| 41 | 41 | $this->getLogger()->info( |
| 42 | 42 | 'Adding the following to main: ' . implode( ', ', $pages ) |
| 43 | 43 | ); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $summary = preg_replace_callback( |
| 55 | 55 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 56 | 56 | function ( $matches ) { |
| 57 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 57 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 58 | 58 | }, |
| 59 | 59 | $summary |
| 60 | 60 | ); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @param string[] $pages |
| 75 | 75 | */ |
| 76 | - protected function addVote( array $pages ) { |
|
| 76 | + protected function addVote ( array $pages ) { |
|
| 77 | 77 | $this->getLogger()->info( |
| 78 | 78 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
| 79 | 79 | ); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $time = WikiController::getTimeWithArticle( time() + ( 60 * 60 * 24 * 7 ) ); |
| 85 | 85 | $newLines = ''; |
| 86 | 86 | foreach ( $pages as $page ) { |
| 87 | - $user = explode( '/', $page )[2]; |
|
| 87 | + $user = explode( '/', $page )[ 2 ]; |
|
| 88 | 88 | $newLines .= "*[[Utente:$user|]]. La [[$page|procedura]] termina $time;\n"; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $content, 1 ); |
| 95 | 95 | } else { |
| 96 | 96 | // Start section |
| 97 | - $matches = []; |
|
| 97 | + $matches = [ ]; |
|
| 98 | 98 | if ( preg_match( $introReg, $content, $matches ) === false ) { |
| 99 | 99 | throw new TaskException( 'Intro not found in vote page' ); |
| 100 | 100 | } |
| 101 | 101 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 102 | 102 | // Replace semicolon with full stop |
| 103 | 103 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
| 104 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $content, 1 ); |
|
| 104 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $content, 1 ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $summary = strtr( |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | $summary = preg_replace_callback( |
| 112 | 112 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 113 | 113 | function ( $matches ) { |
| 114 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 114 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 115 | 115 | }, |
| 116 | 116 | $summary |
| 117 | 117 | ); |
@@ -130,26 +130,26 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @param int $amount |
| 132 | 132 | */ |
| 133 | - protected function addNews( int $amount ) { |
|
| 133 | + protected function addNews ( int $amount ) { |
|
| 134 | 134 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
| 135 | 135 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 136 | 136 | |
| 137 | 137 | $content = $this->getController()->getPageContent( $newsPage ); |
| 138 | 138 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 139 | 139 | |
| 140 | - $matches = []; |
|
| 140 | + $matches = [ ]; |
|
| 141 | 141 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 142 | 142 | throw new TaskException( 'Param not found in news page' ); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $newNum = (int)$matches[2] + $amount; |
|
| 145 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
| 146 | 146 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 147 | 147 | |
| 148 | 148 | $summary = strtr( $this->getConfig()->get( 'ric-news-page-summary' ), [ '$num' => $amount ] ); |
| 149 | 149 | $summary = preg_replace_callback( |
| 150 | 150 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 151 | 151 | function ( $matches ) { |
| 152 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 152 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 153 | 153 | }, |
| 154 | 154 | $summary |
| 155 | 155 | ); |
@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * @inheritDoc |
| 18 | 18 | */ |
| 19 | - public function run() : TaskResult { |
|
| 19 | + public function run () : TaskResult { |
|
| 20 | 20 | $this->getLogger()->info( 'Starting task ClosePages' ); |
| 21 | 21 | |
| 22 | 22 | $titles = $this->getPagesList(); |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return string[] |
| 43 | 43 | */ |
| 44 | - protected function getPagesList() : array { |
|
| 44 | + protected function getPagesList () : array { |
|
| 45 | 45 | $allPages = $this->getDataProvider()->getOpenPages(); |
| 46 | - $ret = []; |
|
| 46 | + $ret = [ ]; |
|
| 47 | 47 | foreach ( $allPages as $page ) { |
| 48 | 48 | $created = $this->getController()->getPageCreationTS( $page ); |
| 49 | 49 | if ( time() - $created <= 60 * 60 * 24 * 7 && !WikiController::hasOpposition( $page ) ) { |
| 50 | - $ret[] = $page; |
|
| 50 | + $ret[ ] = $page; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | return $ret; |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | * @param string[] $titles |
| 59 | 59 | * @see UpdatesAround::addToMainPage() |
| 60 | 60 | */ |
| 61 | - protected function removeFromMainPage( array $titles ) { |
|
| 61 | + protected function removeFromMainPage ( array $titles ) { |
|
| 62 | 62 | $this->getLogger()->info( 'Removing from main: ' . implode( ', ', $titles ) ); |
| 63 | 63 | |
| 64 | 64 | $mainPage = $this->getConfig()->get( 'ric-main-page' ); |
| 65 | 65 | $content = $this->getController()->getPageContent( $mainPage ); |
| 66 | - $translations = []; |
|
| 66 | + $translations = [ ]; |
|
| 67 | 67 | foreach ( $titles as $title ) { |
| 68 | 68 | $translations[ '{{' . $title . '}}' ] = ''; |
| 69 | 69 | } |
@@ -81,24 +81,24 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @param string[] $titles |
| 83 | 83 | */ |
| 84 | - protected function addToArchive( array $titles ) { |
|
| 84 | + protected function addToArchive ( array $titles ) { |
|
| 85 | 85 | $this->getLogger()->info( 'Adding to archive: ' . implode( ', ', $titles ) ); |
| 86 | 86 | |
| 87 | 87 | $archiveTitle = $this->getConfig()->get( 'close-archive-title' ); |
| 88 | 88 | $archiveTitle = "$archiveTitle/" . date( 'Y' ); |
| 89 | 89 | |
| 90 | 90 | $append = ''; |
| 91 | - $archivedList = []; |
|
| 91 | + $archivedList = [ ]; |
|
| 92 | 92 | foreach ( $titles as $page ) { |
| 93 | 93 | $append .= '{{' . $page . "}}\n"; |
| 94 | - $archivedList[] = explode( '/', $page, 3 )[2]; |
|
| 94 | + $archivedList[ ] = explode( '/', $page, 3 )[ 2 ]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | if ( count( $archivedList ) > 1 ) { |
| 98 | 98 | $last = array_pop( $archivedList ); |
| 99 | 99 | $userNums = implode( ', ', $archivedList ) . " e $last"; |
| 100 | 100 | } else { |
| 101 | - $userNums = $archivedList[0]; |
|
| 101 | + $userNums = $archivedList[ 0 ]; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $summary = strtr( |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param string $title |
| 120 | 120 | * @see CreatePages::updateBasePage() |
| 121 | 121 | */ |
| 122 | - protected function updateBasePage( string $title ) { |
|
| 122 | + protected function updateBasePage ( string $title ) { |
|
| 123 | 123 | $this->getLogger()->info( "Updating base page $title" ); |
| 124 | 124 | |
| 125 | 125 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal WTF Phan what's wrong w/ u? |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param string[] $titles |
| 141 | 141 | * @see UpdatesAround::addVote() |
| 142 | 142 | */ |
| 143 | - protected function updateVote( array $titles ) { |
|
| 143 | + protected function updateVote ( array $titles ) { |
|
| 144 | 144 | $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
| 145 | 145 | $content = $this->getController()->getPageContent( $votePage ); |
| 146 | 146 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $summary = preg_replace_callback( |
| 160 | 160 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 161 | 161 | function ( $matches ) { |
| 162 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 162 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 163 | 163 | }, |
| 164 | 164 | $summary |
| 165 | 165 | ); |
@@ -178,19 +178,19 @@ discard block |
||
| 178 | 178 | * @throws TaskException |
| 179 | 179 | * @see UpdatesAround::addNews() |
| 180 | 180 | */ |
| 181 | - protected function updateNews( int $amount ) { |
|
| 181 | + protected function updateNews ( int $amount ) { |
|
| 182 | 182 | $this->getLogger()->info( "Decreasing the news counter by $amount" ); |
| 183 | 183 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 184 | 184 | |
| 185 | 185 | $content = $this->getController()->getPageContent( $newsPage ); |
| 186 | 186 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 187 | 187 | |
| 188 | - $matches = []; |
|
| 188 | + $matches = [ ]; |
|
| 189 | 189 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 190 | 190 | throw new TaskException( 'Param not found in news page' ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $newNum = (int)$matches[2] - $amount; |
|
| 193 | + $newNum = (int)$matches[ 2 ] - $amount; |
|
| 194 | 194 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 195 | 195 | |
| 196 | 196 | $summary = strtr( |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $summary = preg_replace_callback( |
| 201 | 201 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 202 | 202 | function ( $matches ) { |
| 203 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 203 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 204 | 204 | }, |
| 205 | 205 | $summary |
| 206 | 206 | ); |
@@ -219,15 +219,15 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @param string[] $titles |
| 221 | 221 | */ |
| 222 | - protected function updateAdminList( array $titles ) { |
|
| 222 | + protected function updateAdminList ( array $titles ) { |
|
| 223 | 223 | $listTitle = $this->getConfig()->get( 'admins-list' ); |
| 224 | 224 | $content = $this->getController()->getPageContent( $listTitle ); |
| 225 | 225 | $newDate = date( 'Ymd', strtotime( '+1 year' ) ); |
| 226 | 226 | |
| 227 | - $names = []; |
|
| 227 | + $names = [ ]; |
|
| 228 | 228 | foreach ( $titles as $title ) { |
| 229 | - $user = explode( '/', $title )[2]; |
|
| 230 | - $names[] = $user; |
|
| 229 | + $user = explode( '/', $title )[ 2 ]; |
|
| 230 | + $names[ ] = $user; |
|
| 231 | 231 | $reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+(?= *\|(?: *pausa)? *\}\})!"; |
| 232 | 232 | $content = preg_replace( $reg, '$1' . $newDate, $content ); |
| 233 | 233 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $lastUser = array_pop( $names ); |
| 237 | 237 | $usersList = implode( ', ', $names ) . " e $lastUser"; |
| 238 | 238 | } else { |
| 239 | - $usersList = $names[0]; |
|
| 239 | + $usersList = $names[ 0 ]; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | $summary = strtr( |
@@ -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 | |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function run() : TaskResult { |
|
| 16 | + public function run () : TaskResult { |
|
| 17 | 17 | $this->getLogger()->info( 'Starting task StartVote' ); |
| 18 | 18 | |
| 19 | 19 | $pages = $this->getDataProvider()->getOpenPages(); |
| 20 | 20 | |
| 21 | 21 | if ( $pages ) { |
| 22 | - $actualPages = []; |
|
| 22 | + $actualPages = [ ]; |
|
| 23 | 23 | foreach ( $pages as $page ) { |
| 24 | 24 | if ( WikiController::hasOpposition( $page ) ) { |
| 25 | 25 | try { |
| 26 | 26 | $this->openVote( $page ); |
| 27 | - $actualPages[] = $page; |
|
| 27 | + $actualPages[ ] = $page; |
|
| 28 | 28 | } catch ( TaskException $e ) { |
| 29 | 29 | $this->getLogger()->warning( $e->getMessage() ); |
| 30 | 30 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param string $title |
| 52 | 52 | * @throws TaskException |
| 53 | 53 | */ |
| 54 | - protected function openVote( string $title ) { |
|
| 54 | + protected function openVote ( string $title ) { |
|
| 55 | 55 | $this->getLogger()->info( "Starting vote on $title" ); |
| 56 | 56 | |
| 57 | 57 | $content = $this->getController()->getPageContent( $title ); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @see ClosePages::updateVote() |
| 95 | 95 | * @see UpdatesAround::addVote() |
| 96 | 96 | */ |
| 97 | - protected function updateVotePage( array $titles ) { |
|
| 97 | + protected function updateVotePage ( array $titles ) { |
|
| 98 | 98 | $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
| 99 | 99 | $content = $this->getController()->getPageContent( $votePage ); |
| 100 | 100 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $newLines = ''; |
| 110 | 110 | $time = WikiController::getTimeWithArticle( time() + ( 60 * 60 * 24 * 14 ) ); |
| 111 | 111 | foreach ( $titles as $title ) { |
| 112 | - $user = explode( '/', $title )[2]; |
|
| 112 | + $user = explode( '/', $title )[ 2 ]; |
|
| 113 | 113 | $newLines .= "*[[Utente:$user|]]. La [[$title|votazione]] termina $time;\n"; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $newContent, 1 ); |
| 120 | 120 | } else { |
| 121 | 121 | // Start section |
| 122 | - $matches = []; |
|
| 122 | + $matches = [ ]; |
|
| 123 | 123 | if ( preg_match( $introReg, $content, $matches ) === false ) { |
| 124 | 124 | throw new TaskException( 'Intro not found in vote page' ); |
| 125 | 125 | } |
| 126 | 126 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 127 | 127 | // Replace semicolon with full stop |
| 128 | 128 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
| 129 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $newContent, 1 ); |
|
| 129 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $newContent, 1 ); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $summary = strtr( |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $summary = preg_replace_callback( |
| 137 | 137 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 138 | 138 | function ( $matches ) { |
| 139 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 139 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 140 | 140 | }, |
| 141 | 141 | $summary |
| 142 | 142 | ); |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @see UpdatesAround::addNews() |
| 158 | 158 | * @see ClosePages::updateNews() |
| 159 | 159 | */ |
| 160 | - protected function updateNews( int $amount ) { |
|
| 160 | + protected function updateNews ( int $amount ) { |
|
| 161 | 161 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
| 162 | 162 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 163 | 163 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $regTac = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 166 | 166 | $regVot = '!(\| *riconferme[ _]voto[ _]amministratori *= *)(\d+)!'; |
| 167 | 167 | |
| 168 | - $tacMatches = $votMatches = []; |
|
| 168 | + $tacMatches = $votMatches = [ ]; |
|
| 169 | 169 | if ( preg_match( $regTac, $content, $tacMatches ) === false ) { |
| 170 | 170 | throw new TaskException( 'Param "tacite" not found in news page' ); |
| 171 | 171 | } |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | throw new TaskException( 'Param "voto" not found in news page' ); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $newTac = (int)$tacMatches[2] - $amount; |
|
| 177 | - $newVot = (int)$votMatches[2] + $amount; |
|
| 176 | + $newTac = (int)$tacMatches[ 2 ] - $amount; |
|
| 177 | + $newVot = (int)$votMatches[ 2 ] + $amount; |
|
| 178 | 178 | |
| 179 | 179 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
| 180 | 180 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | $summary = preg_replace_callback( |
| 187 | 187 | '!\{\{$plur|(\d+)|([^|]+)|([^|]+)}}!', |
| 188 | 188 | function ( $matches ) { |
| 189 | - return intval( $matches[1] ) > 1 ? trim( $matches[3] ) : trim( $matches[2] ); |
|
| 189 | + return intval( $matches[ 1 ] ) > 1 ? trim( $matches[ 3 ] ) : trim( $matches[ 2 ] ); |
|
| 190 | 190 | }, |
| 191 | 191 | $summary |
| 192 | 192 | ); |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** @var string[] */ |
| 20 | 20 | private $tokens; |
| 21 | 21 | |
| 22 | - public function __construct() { |
|
| 22 | + public function __construct () { |
|
| 23 | 23 | $this->logger = new Logger; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | * @throws MissingPageException |
| 32 | 32 | */ |
| 33 | - public function getPageContent( string $title ) : string { |
|
| 33 | + public function getPageContent ( string $title ) : string { |
|
| 34 | 34 | $this->logger->debug( "Retrieving page $title" ); |
| 35 | 35 | $params = [ |
| 36 | 36 | 'action' => 'query', |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | throw new MissingPageException( $title ); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return $page->revisions[0]->slots->main->{ '*' }; |
|
| 50 | + return $page->revisions[ 0 ]->slots->main->{ '*' }; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param array $params |
| 57 | 57 | * @throws EditException |
| 58 | 58 | */ |
| 59 | - public function editPage( array $params ) { |
|
| 59 | + public function editPage ( array $params ) { |
|
| 60 | 60 | $this->login(); |
| 61 | 61 | |
| 62 | 62 | $params = [ |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return string |
| 79 | 79 | * @fixme Not the right place for this |
| 80 | 80 | */ |
| 81 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
| 81 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
| 82 | 82 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 83 | 83 | $endTime = strftime( '%e %B alle %R', $timestamp ); |
| 84 | 84 | // Remove the left space if day has a single digit |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @return bool |
| 95 | 95 | * @fixme Not the right place for this |
| 96 | 96 | */ |
| 97 | - public static function hasOpposition( string $page ) : bool { |
|
| 97 | + public static function hasOpposition ( string $page ) : bool { |
|
| 98 | 98 | $params = [ |
| 99 | 99 | 'action' => 'query', |
| 100 | 100 | 'prop' => 'revisions', |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | ]; |
| 106 | 106 | $res = RequestBase::newFromParams( $params )->execute(); |
| 107 | 107 | $page = reset( $res->query->pages ); |
| 108 | - $content = $page->revisions[0]->slots->main->{ '*' }; |
|
| 108 | + $content = $page->revisions[ 0 ]->slots->main->{ '*' }; |
|
| 109 | 109 | // Let's hope that this is good enough... |
| 110 | 110 | $votes = substr_count( $content, "\n\# *(?![#*])" ); |
| 111 | 111 | return $votes >= 15; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 116 | 116 | * @throws LoginException |
| 117 | 117 | */ |
| 118 | - public function login() { |
|
| 118 | + public function login () { |
|
| 119 | 119 | if ( self::$loggedIn ) { |
| 120 | 120 | $this->logger->debug( 'Already logged in' ); |
| 121 | 121 | return; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | self::$loggedIn = true; |
| 144 | 144 | // Clear tokens cache |
| 145 | - $this->tokens = []; |
|
| 145 | + $this->tokens = [ ]; |
|
| 146 | 146 | $this->logger->info( 'Login succeeded' ); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param string $type |
| 153 | 153 | * @return string |
| 154 | 154 | */ |
| 155 | - public function getToken( string $type ) : string { |
|
| 155 | + public function getToken ( string $type ) : string { |
|
| 156 | 156 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 157 | 157 | $params = [ |
| 158 | 158 | 'action' => 'query', |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * @param string $title |
| 176 | 176 | * @return int |
| 177 | 177 | */ |
| 178 | - public function getPageCreationTS( string $title ) : int { |
|
| 178 | + public function getPageCreationTS ( string $title ) : int { |
|
| 179 | 179 | $params = [ |
| 180 | 180 | 'action' => 'query', |
| 181 | 181 | 'prop' => 'revisions', |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $res = ( RequestBase::newFromParams( $params ) )->execute(); |
| 190 | 190 | $data = $res->query->pages; |
| 191 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 191 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @param string $title |
| 198 | 198 | * @param string $reason |
| 199 | 199 | */ |
| 200 | - public function protectPage( string $title, string $reason ) { |
|
| 200 | + public function protectPage ( string $title, string $reason ) { |
|
| 201 | 201 | $this->logger->info( "Protecting page $title" ); |
| 202 | 202 | $this->login(); |
| 203 | 203 | |
@@ -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,20 +12,20 @@ discard block |
||
| 12 | 12 | private $users; |
| 13 | 13 | |
| 14 | 14 | /** @var string[] */ |
| 15 | - private $createdPages = []; |
|
| 15 | + private $createdPages = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Get a list of users to execute tasks on. |
| 19 | 19 | * |
| 20 | 20 | * @return array[] |
| 21 | 21 | */ |
| 22 | - public function getUsersToProcess() : array { |
|
| 22 | + public function getUsersToProcess () : array { |
|
| 23 | 23 | if ( $this->users === null ) { |
| 24 | 24 | $this->getLogger()->debug( 'Retrieving users list' ); |
| 25 | 25 | $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
| 26 | 26 | $listUsers = json_decode( $content, true ); |
| 27 | 27 | |
| 28 | - $this->users = []; |
|
| 28 | + $this->users = [ ]; |
|
| 29 | 29 | foreach ( $listUsers as $user => $groups ) { |
| 30 | 30 | $timestamp = $this->getValidTimestamp( $groups ); |
| 31 | 31 | |
@@ -47,13 +47,11 @@ discard block |
||
| 47 | 47 | * @param array $groups |
| 48 | 48 | * @return int |
| 49 | 49 | */ |
| 50 | - private function getValidTimestamp( array $groups ) : int { |
|
| 50 | + private function getValidTimestamp ( array $groups ) : int { |
|
| 51 | 51 | $checkuser = isset( $groups[ 'checkuser' ] ) ? |
| 52 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 53 | - 0; |
|
| 52 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 54 | 53 | $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
| 55 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 56 | - 0; |
|
| 54 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 57 | 55 | |
| 58 | 56 | $timestamp = max( $bureaucrat, $checkuser ); |
| 59 | 57 | if ( $timestamp === 0 ) { |
@@ -67,7 +65,7 @@ discard block |
||
| 67 | 65 | * |
| 68 | 66 | * @return string[] Their titles |
| 69 | 67 | */ |
| 70 | - public function getOpenPages() : array { |
|
| 68 | + public function getOpenPages () : array { |
|
| 71 | 69 | $baseTitle = $this->getConfig()->get( 'ric-main-page' ); |
| 72 | 70 | $params = [ |
| 73 | 71 | 'action' => 'query', |
@@ -79,10 +77,10 @@ discard block |
||
| 79 | 77 | |
| 80 | 78 | $res = RequestBase::newFromParams( $params )->execute(); |
| 81 | 79 | $pages = $res->query->pages; |
| 82 | - $ret = []; |
|
| 80 | + $ret = [ ]; |
|
| 83 | 81 | foreach ( reset( $pages )->templates as $page ) { |
| 84 | 82 | if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) { |
| 85 | - $ret[] = $page->title; |
|
| 83 | + $ret[ ] = $page->title; |
|
| 86 | 84 | } |
| 87 | 85 | } |
| 88 | 86 | return $ret; |
@@ -93,21 +91,21 @@ discard block |
||
| 93 | 91 | * |
| 94 | 92 | * @param string $name |
| 95 | 93 | */ |
| 96 | - public function removeUser( string $name ) { |
|
| 94 | + public function removeUser ( string $name ) { |
|
| 97 | 95 | unset( $this->users[ $name ] ); |
| 98 | 96 | } |
| 99 | 97 | |
| 100 | 98 | /** |
| 101 | 99 | * @return string[] |
| 102 | 100 | */ |
| 103 | - public function getCreatedPages() : array { |
|
| 101 | + public function getCreatedPages () : array { |
|
| 104 | 102 | return $this->createdPages; |
| 105 | 103 | } |
| 106 | 104 | |
| 107 | 105 | /** |
| 108 | 106 | * @param string $title |
| 109 | 107 | */ |
| 110 | - public function addCreatedPages( string $title ) { |
|
| 111 | - $this->createdPages[] = $title; |
|
| 108 | + public function addCreatedPages ( string $title ) { |
|
| 109 | + $this->createdPages[ ] = $title; |
|
| 112 | 110 | } |
| 113 | 111 | } |