@@ -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(); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param string[] $pages |
| 34 | 34 | */ |
| 35 | - protected function addToMainPage( array $pages ) { |
|
| 35 | + protected function addToMainPage ( array $pages ) { |
|
| 36 | 36 | $this->getLogger()->info( |
| 37 | 37 | 'Adding the following to main: ' . implode( ', ', $pages ) |
| 38 | 38 | ); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @param string[] $pages |
| 58 | 58 | */ |
| 59 | - protected function addVote( array $pages ) { |
|
| 59 | + protected function addVote ( array $pages ) { |
|
| 60 | 60 | $this->getLogger()->info( |
| 61 | 61 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
| 62 | 62 | ); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $time = $this->getTimeWithArticle(); |
| 70 | 70 | $newLines = ''; |
| 71 | 71 | foreach ( $pages as $page ) { |
| 72 | - $user = explode( '/', $page )[2]; |
|
| 72 | + $user = explode( '/', $page )[ 2 ]; |
|
| 73 | 73 | $newLines .= "*[[Utente:$user|]]. La [[$page|procedura]] termina $time;\n"; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | $newContent = preg_replace( $introReg, '$0' . "\n$newLines", $content, 1 ); |
| 80 | 80 | } else { |
| 81 | 81 | // Start section |
| 82 | - $matches = []; |
|
| 82 | + $matches = [ ]; |
|
| 83 | 83 | if ( preg_match( $introReg, $content, $matches ) === false ) { |
| 84 | 84 | throw new TaskException( 'Intro not found in vote page' ); |
| 85 | 85 | } |
| 86 | 86 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 87 | 87 | // Replace semicolon with full stop |
| 88 | 88 | $newLines = substr( $newLines, 0, -2 ) . ".\n"; |
| 89 | - $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $content, 1 ); |
|
| 89 | + $newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $content, 1 ); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $params = [ |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | - private function getTimeWithArticle() : string { |
|
| 106 | + private function getTimeWithArticle () : string { |
|
| 107 | 107 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 108 | 108 | $endTS = time() + ( 60 * 60 * 24 * 7 ); |
| 109 | 109 | $endTime = strftime( '%e %B alle %R', $endTS ); |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @param int $amount |
| 122 | 122 | */ |
| 123 | - protected function addNews( int $amount ) { |
|
| 123 | + protected function addNews ( int $amount ) { |
|
| 124 | 124 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
| 125 | 125 | $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
| 126 | 126 | |
| 127 | 127 | $content = $this->getController()->getPageContent( $newsPage ); |
| 128 | 128 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 129 | 129 | |
| 130 | - $matches = []; |
|
| 130 | + $matches = [ ]; |
|
| 131 | 131 | if ( preg_match( $reg, $content, $matches ) === false ) { |
| 132 | 132 | throw new TaskException( 'Param not found in news page' ); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - $newNum = (int)$matches[2] + $amount; |
|
| 135 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
| 136 | 136 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
| 137 | 137 | |
| 138 | 138 | $params = [ |
@@ -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->getList(); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | - protected function getActualAdmins() : array { |
|
| 49 | + protected function getActualAdmins () : array { |
|
| 50 | 50 | $this->getLogger()->debug( 'Retrieving admins - API' ); |
| 51 | 51 | $params = [ |
| 52 | 52 | 'action' => 'query', |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | * @param \stdClass $data |
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 68 | - $ret = []; |
|
| 67 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 68 | + $ret = [ ]; |
|
| 69 | 69 | $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
| 70 | 70 | foreach ( $data->query->allusers as $u ) { |
| 71 | 71 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | /** |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - protected function getList() : array { |
|
| 83 | + protected function getList () : array { |
|
| 84 | 84 | $this->getLogger()->debug( 'Retrieving admins - JSON list' ); |
| 85 | 85 | $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
| 86 | 86 | |
@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return array[] |
| 94 | 94 | */ |
| 95 | - protected function getMissingGroups() : array { |
|
| 96 | - $missing = []; |
|
| 95 | + protected function getMissingGroups () : array { |
|
| 96 | + $missing = [ ]; |
|
| 97 | 97 | foreach ( $this->actualList as $adm => $groups ) { |
| 98 | - $groupsList = []; |
|
| 98 | + $groupsList = [ ]; |
|
| 99 | 99 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 100 | 100 | $groupsList = $groups; |
| 101 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 101 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 102 | 102 | // Only some groups are missing |
| 103 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 103 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | foreach ( $groupsList as $group ) { |
| 107 | 107 | try { |
| 108 | 108 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 109 | 109 | } catch ( TaskException $e ) { |
| 110 | - $this->errors[] = $e->getMessage(); |
|
| 110 | + $this->errors[ ] = $e->getMessage(); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return string |
| 123 | 123 | * @throws TaskException |
| 124 | 124 | */ |
| 125 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 125 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 126 | 126 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 127 | 127 | |
| 128 | 128 | if ( $group === 'checkuser' ) { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param string $group |
| 163 | 163 | * @return string|null |
| 164 | 164 | */ |
| 165 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 165 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 166 | 166 | $ts = null; |
| 167 | 167 | foreach ( $data->query->logevents as $entry ) { |
| 168 | 168 | if ( !isset( $entry->params ) ) { |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return array[] |
| 186 | 186 | */ |
| 187 | - protected function getExtraGroups() : array { |
|
| 188 | - $extra = []; |
|
| 187 | + protected function getExtraGroups () : array { |
|
| 188 | + $extra = [ ]; |
|
| 189 | 189 | foreach ( $this->botList as $name => $groups ) { |
| 190 | 190 | if ( !isset( $this->actualList[ $name ] ) ) { |
| 191 | 191 | $extra[ $name ] = $groups; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @param array $newContent |
| 203 | 203 | */ |
| 204 | - protected function doUpdateList( array $newContent ) { |
|
| 204 | + protected function doUpdateList ( array $newContent ) { |
|
| 205 | 205 | ksort( $newContent ); |
| 206 | 206 | |
| 207 | 207 | if ( $newContent === $this->botList ) { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @param array[] $extra |
| 228 | 228 | * @return array[] |
| 229 | 229 | */ |
| 230 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 230 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 231 | 231 | $newContent = $this->botList; |
| 232 | 232 | foreach ( $newContent as $user => $groups ) { |
| 233 | 233 | if ( isset( $missing[ $user ] ) ) { |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -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', |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | throw new MissingPageException( $title ); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return $page->revisions[0]->slots->main->{ '*' }; |
|
| 51 | + return $page->revisions[ 0 ]->slots->main->{ '*' }; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param array $params |
| 58 | 58 | * @throws EditException |
| 59 | 59 | */ |
| 60 | - public function editPage( array $params ) { |
|
| 60 | + public function editPage ( array $params ) { |
|
| 61 | 61 | $this->login(); |
| 62 | 62 | |
| 63 | 63 | $params = [ |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 77 | 77 | * @throws LoginException |
| 78 | 78 | */ |
| 79 | - public function login() { |
|
| 79 | + public function login () { |
|
| 80 | 80 | if ( self::$loggedIn ) { |
| 81 | 81 | $this->logger->debug( 'Already logged in' ); |
| 82 | 82 | return; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | self::$loggedIn = true; |
| 105 | 105 | // Clear tokens cache |
| 106 | - $this->tokens = []; |
|
| 106 | + $this->tokens = [ ]; |
|
| 107 | 107 | $this->logger->info( 'Login succeeded' ); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param string $type |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public function getToken( string $type ) : string { |
|
| 116 | + public function getToken ( string $type ) : string { |
|
| 117 | 117 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 118 | 118 | $params = [ |
| 119 | 119 | 'action' => 'query', |