@@ -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,7 +127,7 @@ 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' ); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @param string $title |
| 152 | 152 | * @see CreatePages::updateBasePage() |
| 153 | 153 | */ |
| 154 | - protected function updateBasePage( string $title ) { |
|
| 154 | + protected function updateBasePage ( string $title ) { |
|
| 155 | 155 | $this->getLogger()->info( "Updating base page $title" ); |
| 156 | 156 | |
| 157 | 157 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal WTF Phan what's wrong w/ u? |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @param string[] $titles |
| 173 | 173 | * @see UpdatesAround::addVote() |
| 174 | 174 | */ |
| 175 | - protected function updateVote( array $titles ) { |
|
| 175 | + protected function updateVote ( array $titles ) { |
|
| 176 | 176 | $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
| 177 | 177 | $content = $this->getController()->getPageContent( $votePage ); |
| 178 | 178 | |
@@ -198,19 +198,19 @@ discard block |
||
| 198 | 198 | * @throws TaskException |
| 199 | 199 | * @see UpdatesAround::addNews() |
| 200 | 200 | */ |
| 201 | - protected function updateNews( int $amount ) { |
|
| 201 | + protected function updateNews ( int $amount ) { |
|
| 202 | 202 | $this->getLogger()->info( "Decreasing the news counter by $amount" ); |
| 203 | 203 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 204 | 204 | |
| 205 | 205 | $content = $this->getController()->getPageContent( $newsPage ); |
| 206 | 206 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 207 | 207 | |
| 208 | - $matches = []; |
|
| 208 | + $matches = [ ]; |
|
| 209 | 209 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 210 | 210 | throw new TaskException( 'Param not found in news page' ); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $newNum = (int)$matches[2] - $amount; |
|
| 213 | + $newNum = (int)$matches[ 2 ] - $amount; |
|
| 214 | 214 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 215 | 215 | |
| 216 | 216 | $params = [ |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @param string[] $titles |
| 229 | 229 | */ |
| 230 | - protected function updateAdminList( array $titles ) { |
|
| 230 | + protected function updateAdminList ( array $titles ) { |
|
| 231 | 231 | $listTitle = $this->getConfig()->get( 'admins-list' ); |
| 232 | 232 | $content = $this->getController()->getPageContent( $listTitle ); |
| 233 | 233 | $newDate = date( 'Ymd', strtotime( '+1 year' ) ); |
| 234 | 234 | foreach ( $titles as $title ) { |
| 235 | - $user = explode( '/', $title )[2]; |
|
| 235 | + $user = explode( '/', $title )[ 2 ]; |
|
| 236 | 236 | $reg = "!(\{\{Amministratore\/riga\|$user.+\| *)\d+(?= *\|(?: *pausa)? *\}\})!"; |
| 237 | 237 | $content = preg_replace( $reg, '$1' . $newDate, $content ); |
| 238 | 238 | } |