@@ -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', |
@@ -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(); |
@@ -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 ) ) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * @return array |
| 89 | 89 | */ |
| 90 | - protected function getList() : array { |
|
| 90 | + protected function getList () : array { |
|
| 91 | 91 | $this->getLogger()->debug( 'Retrieving admins - JSON list' ); |
| 92 | 92 | $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
| 93 | 93 | |
@@ -99,22 +99,22 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return array[] |
| 101 | 101 | */ |
| 102 | - protected function getMissingGroups() : array { |
|
| 103 | - $missing = []; |
|
| 102 | + protected function getMissingGroups () : array { |
|
| 103 | + $missing = [ ]; |
|
| 104 | 104 | foreach ( $this->actualList as $adm => $groups ) { |
| 105 | - $groupsList = []; |
|
| 105 | + $groupsList = [ ]; |
|
| 106 | 106 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 107 | 107 | $groupsList = $groups; |
| 108 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 108 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 109 | 109 | // Only some groups are missing |
| 110 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 110 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | foreach ( $groupsList as $group ) { |
| 114 | 114 | try { |
| 115 | 115 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 116 | 116 | } catch ( TaskException $e ) { |
| 117 | - $this->errors[] = $e->getMessage(); |
|
| 117 | + $this->errors[ ] = $e->getMessage(); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @return string |
| 130 | 130 | * @throws TaskException |
| 131 | 131 | */ |
| 132 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 132 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 133 | 133 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 134 | 134 | |
| 135 | 135 | if ( $group === 'checkuser' ) { |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @param string $group |
| 170 | 170 | * @return string|null |
| 171 | 171 | */ |
| 172 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 172 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 173 | 173 | $ts = null; |
| 174 | 174 | foreach ( $data->query->logevents as $entry ) { |
| 175 | 175 | if ( !isset( $entry->params ) ) { |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return array[] |
| 193 | 193 | */ |
| 194 | - protected function getExtraGroups() : array { |
|
| 195 | - $extra = []; |
|
| 194 | + protected function getExtraGroups () : array { |
|
| 195 | + $extra = [ ]; |
|
| 196 | 196 | foreach ( $this->botList as $name => $groups ) { |
| 197 | 197 | if ( !isset( $this->actualList[ $name ] ) ) { |
| 198 | 198 | $extra[ $name ] = $groups; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @param array $newContent |
| 210 | 210 | */ |
| 211 | - protected function doUpdateList( array $newContent ) { |
|
| 211 | + protected function doUpdateList ( array $newContent ) { |
|
| 212 | 212 | $this->getLogger()->info( 'Updating admin list' ); |
| 213 | 213 | |
| 214 | 214 | $params = [ |
@@ -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 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -11,13 +11,13 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @inheritDoc |
| 13 | 13 | */ |
| 14 | - public function run() : TaskResult { |
|
| 14 | + public function run () : TaskResult { |
|
| 15 | 15 | $this->getLogger()->info( 'Starting task UserNotice' ); |
| 16 | 16 | |
| 17 | 17 | $pages = $this->getDataProvider()->getCreatedPages(); |
| 18 | 18 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 19 | 19 | if ( $pages && $users ) { |
| 20 | - $ricNums = []; |
|
| 20 | + $ricNums = [ ]; |
|
| 21 | 21 | foreach ( $pages as $page ) { |
| 22 | 22 | $bits = explode( '/', $page ); |
| 23 | 23 | $num = intval( array_pop( $bits ) ); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $user |
| 42 | 42 | * @param int $ricNum |
| 43 | 43 | */ |
| 44 | - protected function addMsg( string $user, int $ricNum ) { |
|
| 44 | + protected function addMsg ( string $user, int $ricNum ) { |
|
| 45 | 45 | $this->getLogger()->info( "Leaving msg to $user" ); |
| 46 | 46 | $msg = str_replace( '$num', "$ricNum", $this->getConfig()->get( 'user-notice-msg' ) ); |
| 47 | 47 | |
@@ -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,7 +29,7 @@ discard block |
||
| 29 | 29 | /** @var string */ |
| 30 | 30 | protected $method; |
| 31 | 31 | /** @var string[] */ |
| 32 | - protected $newCookies = []; |
|
| 32 | + protected $newCookies = [ ]; |
|
| 33 | 33 | /** @var int */ |
| 34 | 34 | private $limit = -1; |
| 35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param array $params |
| 40 | 40 | * @param bool $isPOST |
| 41 | 41 | */ |
| 42 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 42 | + protected function __construct ( array $params, bool $isPOST = false ) { |
|
| 43 | 43 | $this->params = [ 'format' => 'json' ] + $params; |
| 44 | 44 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 45 | 45 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param bool $isPOST |
| 52 | 52 | * @return self |
| 53 | 53 | */ |
| 54 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 54 | + public static function newFromParams ( array $params, bool $isPOST = false ) : self { |
|
| 55 | 55 | if ( extension_loaded( 'curl' ) ) { |
| 56 | 56 | $ret = new CurlRequest( $params, $isPOST ); |
| 57 | 57 | } else { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param int $val |
| 67 | 67 | */ |
| 68 | - public function setResultLimit( int $val ) { |
|
| 68 | + public function setResultLimit ( int $val ) { |
|
| 69 | 69 | $this->limit = $val; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -74,16 +74,16 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return \stdClass |
| 76 | 76 | */ |
| 77 | - public function execute() : \stdClass { |
|
| 77 | + public function execute () : \stdClass { |
|
| 78 | 78 | $curParams = $this->params; |
| 79 | - $sets = []; |
|
| 79 | + $sets = [ ]; |
|
| 80 | 80 | $amount = 0; |
| 81 | 81 | do { |
| 82 | 82 | $res = $this->makeRequestInternal( $curParams ); |
| 83 | 83 | $amount += count( $res ); |
| 84 | 84 | |
| 85 | 85 | $this->handleErrorAndWarnings( $res ); |
| 86 | - $sets[] = $res; |
|
| 86 | + $sets[ ] = $res; |
|
| 87 | 87 | |
| 88 | 88 | $finished = true; |
| 89 | 89 | if ( isset( $res->continue ) && $this->limit > -1 && $amount < $this->limit ) { |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | * @param array $params |
| 102 | 102 | * @return \stdClass |
| 103 | 103 | */ |
| 104 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 104 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 105 | 105 | if ( $this->method === 'POST' ) { |
| 106 | - $params['maxlag'] = self::MAXLAG; |
|
| 106 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 107 | 107 | } |
| 108 | 108 | $params = http_build_query( $params ); |
| 109 | 109 | |
@@ -119,17 +119,17 @@ discard block |
||
| 119 | 119 | * @param string $params |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 122 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * After a request, set cookies for the next ones |
| 126 | 126 | * |
| 127 | 127 | * @param array $cookies |
| 128 | 128 | */ |
| 129 | - protected function setCookies( array $cookies ) { |
|
| 129 | + protected function setCookies ( array $cookies ) { |
|
| 130 | 130 | foreach ( $cookies as $cookie ) { |
| 131 | 131 | $bits = explode( ';', $cookie ); |
| 132 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 132 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 133 | 133 | self::$cookiesToSet[ $name ] = $value; |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param \stdClass $res |
| 141 | 141 | * @throws APIRequestException |
| 142 | 142 | */ |
| 143 | - protected function handleErrorAndWarnings( $res ) { |
|
| 143 | + protected function handleErrorAndWarnings ( $res ) { |
|
| 144 | 144 | if ( isset( $res->error ) ) { |
| 145 | 145 | switch ( $res->error->code ) { |
| 146 | 146 | case 'missingtitle': |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param \stdClass[] $sets |
| 167 | 167 | * @return \stdClass |
| 168 | 168 | */ |
| 169 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 169 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 170 | 170 | // Use the first set as template |
| 171 | 171 | $ret = array_shift( $sets ); |
| 172 | 172 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param array|\stdClass $second |
| 184 | 184 | * @return array|\stdClass array |
| 185 | 185 | */ |
| 186 | - private function recursiveMerge( $first, $second ) { |
|
| 186 | + private function recursiveMerge ( $first, $second ) { |
|
| 187 | 187 | $ret = $first; |
| 188 | 188 | if ( is_array( $second ) ) { |
| 189 | 189 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | - protected function getHeaders() :array { |
|
| 204 | + protected function getHeaders () :array { |
|
| 205 | 205 | $ret = self::HEADERS; |
| 206 | 206 | if ( self::$cookiesToSet ) { |
| 207 | - $cookies = []; |
|
| 207 | + $cookies = [ ]; |
|
| 208 | 208 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 209 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 209 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 210 | 210 | } |
| 211 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 211 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 212 | 212 | } |
| 213 | 213 | return $ret; |
| 214 | 214 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @param array $headers |
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | - protected function buildHeadersString( array $headers ) : string { |
|
| 222 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 223 | 223 | $ret = ''; |
| 224 | 224 | foreach ( $headers as $header ) { |
| 225 | 225 | $ret .= "$header\r\n"; |