@@ -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 | |
| 34 | 34 | /** |
| 35 | 35 | * Use self::newFromParams, which will provide the right class to use |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param array $params |
| 38 | 38 | * @param bool $isPOST |
| 39 | 39 | */ |
| 40 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 40 | + protected function __construct ( array $params, bool $isPOST = false ) { |
|
| 41 | 41 | $this->params = [ 'format' => 'json' ] + $params; |
| 42 | 42 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 43 | 43 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param bool $isPOST |
| 50 | 50 | * @return self |
| 51 | 51 | */ |
| 52 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 52 | + public static function newFromParams ( array $params, bool $isPOST = false ) : self { |
|
| 53 | 53 | if ( extension_loaded( 'curl' ) ) { |
| 54 | 54 | $ret = new CurlRequest( $params, $isPOST ); |
| 55 | 55 | } else { |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return \stdClass |
| 65 | 65 | */ |
| 66 | - public function execute() : \stdClass { |
|
| 66 | + public function execute () : \stdClass { |
|
| 67 | 67 | $curParams = $this->params; |
| 68 | - $sets = []; |
|
| 68 | + $sets = [ ]; |
|
| 69 | 69 | do { |
| 70 | 70 | $res = $this->makeRequestInternal( $curParams ); |
| 71 | 71 | |
| 72 | 72 | $this->handleErrorAndWarnings( $res ); |
| 73 | - $sets[] = $res; |
|
| 73 | + $sets[ ] = $res; |
|
| 74 | 74 | |
| 75 | 75 | $finished = true; |
| 76 | 76 | if ( isset( $res->continue ) ) { |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * @param array $params |
| 89 | 89 | * @return \stdClass |
| 90 | 90 | */ |
| 91 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 91 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 92 | 92 | if ( $this->method === 'POST' ) { |
| 93 | - $params['maxlag'] = self::MAXLAG; |
|
| 93 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 94 | 94 | } |
| 95 | 95 | $params = http_build_query( $params ); |
| 96 | 96 | |
@@ -106,17 +106,17 @@ discard block |
||
| 106 | 106 | * @param string $params |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 109 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * After a request, set cookies for the next ones |
| 113 | 113 | * |
| 114 | 114 | * @param array $cookies |
| 115 | 115 | */ |
| 116 | - protected function setCookies( array $cookies ) { |
|
| 116 | + protected function setCookies ( array $cookies ) { |
|
| 117 | 117 | foreach ( $cookies as $cookie ) { |
| 118 | 118 | $bits = explode( ';', $cookie ); |
| 119 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 119 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 120 | 120 | self::$cookiesToSet[ $name ] = $value; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param \stdClass $res |
| 128 | 128 | * @throws APIRequestException |
| 129 | 129 | */ |
| 130 | - protected function handleErrorAndWarnings( $res ) { |
|
| 130 | + protected function handleErrorAndWarnings ( $res ) { |
|
| 131 | 131 | if ( isset( $res->error ) ) { |
| 132 | 132 | switch ( $res->error->code ) { |
| 133 | 133 | case 'missingtitle': |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param \stdClass[] $sets |
| 154 | 154 | * @return \stdClass |
| 155 | 155 | */ |
| 156 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 156 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 157 | 157 | // Use the first set as template |
| 158 | 158 | $ret = array_shift( $sets ); |
| 159 | 159 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param array|\stdClass $second |
| 171 | 171 | * @return array|\stdClass array |
| 172 | 172 | */ |
| 173 | - private function recursiveMerge( $first, $second ) { |
|
| 173 | + private function recursiveMerge ( $first, $second ) { |
|
| 174 | 174 | $ret = $first; |
| 175 | 175 | if ( is_array( $second ) ) { |
| 176 | 176 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -193,14 +193,14 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return array |
| 195 | 195 | */ |
| 196 | - protected function getHeaders() :array { |
|
| 196 | + protected function getHeaders () :array { |
|
| 197 | 197 | $ret = self::HEADERS; |
| 198 | 198 | if ( self::$cookiesToSet ) { |
| 199 | - $cookies = []; |
|
| 199 | + $cookies = [ ]; |
|
| 200 | 200 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 201 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 201 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 202 | 202 | } |
| 203 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 203 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 204 | 204 | } |
| 205 | 205 | return $ret; |
| 206 | 206 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param array $headers |
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | - protected function buildHeadersString( array $headers ) : string { |
|
| 214 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 215 | 215 | $ret = ''; |
| 216 | 216 | foreach ( $headers as $header ) { |
| 217 | 217 | $ret .= "$header\r\n"; |
@@ -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 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** @var string[] */ |
| 19 | 19 | private $tokens; |
| 20 | 20 | |
| 21 | - public function __construct() { |
|
| 21 | + public function __construct () { |
|
| 22 | 22 | $this->logger = new Logger; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return string |
| 30 | 30 | * @throws MissingPageException |
| 31 | 31 | */ |
| 32 | - public function getPageContent( string $title ) : string { |
|
| 32 | + public function getPageContent ( string $title ) : string { |
|
| 33 | 33 | $this->logger->debug( "Retrieving page $title" ); |
| 34 | 34 | $params = [ |
| 35 | 35 | '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 APIRequestException |
| 58 | 58 | */ |
| 59 | - public function editPage( array $params ) { |
|
| 59 | + public function editPage ( array $params ) { |
|
| 60 | 60 | $this->login(); |
| 61 | 61 | |
| 62 | 62 | $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; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | self::$loggedIn = true; |
| 106 | 106 | // Clear tokens cache |
| 107 | - $this->tokens = []; |
|
| 107 | + $this->tokens = [ ]; |
|
| 108 | 108 | $this->logger->debug( 'Login succeeded' ); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param string $type |
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | - public function getToken( string $type ) : string { |
|
| 117 | + public function getToken ( string $type ) : string { |
|
| 118 | 118 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 119 | 119 | $params = [ |
| 120 | 120 | '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 | |
@@ -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 CreatePage' ); |
| 18 | 18 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 19 | 19 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param string $user |
| 32 | 32 | * @param array $groups |
| 33 | 33 | */ |
| 34 | - protected function processUser( string $user, array $groups ) { |
|
| 34 | + protected function processUser ( string $user, array $groups ) { |
|
| 35 | 35 | try { |
| 36 | 36 | $num = $this->getLastPageNum( $user ) + 1; |
| 37 | 37 | } catch ( TaskException $e ) { |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | * @return int |
| 62 | 62 | * @throws TaskException |
| 63 | 63 | */ |
| 64 | - protected function getLastPageNum( string $user ) : int { |
|
| 64 | + protected function getLastPageNum ( string $user ) : int { |
|
| 65 | 65 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
| 66 | - $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1]; |
|
| 66 | + $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[ 1 ]; |
|
| 67 | 67 | $params = [ |
| 68 | 68 | 'action' => 'query', |
| 69 | 69 | 'list' => 'allpages', |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $title |
| 93 | 93 | * @return bool |
| 94 | 94 | */ |
| 95 | - private function pageWasCreatedToday( string $title ) : bool { |
|
| 95 | + private function pageWasCreatedToday ( string $title ) : bool { |
|
| 96 | 96 | $params = [ |
| 97 | 97 | 'action' => 'query', |
| 98 | 98 | 'prop' => 'revisions', |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | $res = ( RequestBase::newFromParams( $params ) )->execute(); |
| 107 | 107 | $data = $res->query->pages; |
| 108 | - $time = strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 108 | + $time = strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 109 | 109 | return date( 'z/Y' ) === date( 'z/Y', $time ); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * @param string $user |
| 117 | 117 | * @param array $groups |
| 118 | 118 | */ |
| 119 | - protected function doCreatePage( string $title, string $user, array $groups ) { |
|
| 119 | + protected function doCreatePage ( string $title, string $user, array $groups ) { |
|
| 120 | 120 | $this->getLogger()->info( "Creating page $title" ); |
| 121 | 121 | $text = $this->getConfig()->get( 'ric-page-text' ); |
| 122 | 122 | $textParams = [ |
| 123 | 123 | '$user' => $user, |
| 124 | - '$date' => $groups['sysop'], |
|
| 125 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 126 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 124 | + '$date' => $groups[ 'sysop' ], |
|
| 125 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 126 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 127 | 127 | ]; |
| 128 | 128 | $text = strtr( $text, $textParams ); |
| 129 | 129 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param string $title |
| 143 | 143 | * @param string $newText |
| 144 | 144 | */ |
| 145 | - protected function createBasePage( string $title, string $newText ) { |
|
| 145 | + protected function createBasePage ( string $title, string $newText ) { |
|
| 146 | 146 | $this->getLogger()->info( "Creating base page $title" ); |
| 147 | 147 | |
| 148 | 148 | $params = [ |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param string $title |
| 160 | 160 | * @param string $newText |
| 161 | 161 | */ |
| 162 | - protected function updateBasePage( string $title, string $newText ) { |
|
| 162 | + protected function updateBasePage ( string $title, string $newText ) { |
|
| 163 | 163 | $this->getLogger()->info( "Updating base page $title" ); |
| 164 | 164 | |
| 165 | 165 | $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,14 +92,14 @@ 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 | 98 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 99 | 99 | $groupsList = $groups; |
| 100 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 100 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 101 | 101 | // Only some groups are missing |
| 102 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 102 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 103 | 103 | } else { |
| 104 | 104 | continue; |
| 105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | try { |
| 109 | 109 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 110 | 110 | } catch ( TaskException $e ) { |
| 111 | - $this->errors[] = $e->getMessage(); |
|
| 111 | + $this->errors[ ] = $e->getMessage(); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return string |
| 124 | 124 | * @throws TaskException |
| 125 | 125 | */ |
| 126 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 126 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 127 | 127 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 128 | 128 | |
| 129 | 129 | if ( $group === 'checkuser' ) { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @param string $group |
| 165 | 165 | * @return string|null |
| 166 | 166 | */ |
| 167 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 167 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 168 | 168 | $ts = null; |
| 169 | 169 | foreach ( $data->query->logevents as $entry ) { |
| 170 | 170 | if ( !isset( $entry->params ) ) { |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return array[] |
| 188 | 188 | */ |
| 189 | - protected function getExtraGroups() : array { |
|
| 190 | - $extra = []; |
|
| 189 | + protected function getExtraGroups () : array { |
|
| 190 | + $extra = [ ]; |
|
| 191 | 191 | foreach ( $this->botList as $name => $groups ) { |
| 192 | 192 | if ( !isset( $this->actualList[ $name ] ) ) { |
| 193 | 193 | $extra[ $name ] = $groups; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param array $newContent |
| 205 | 205 | */ |
| 206 | - protected function doUpdateList( array $newContent ) { |
|
| 206 | + protected function doUpdateList ( array $newContent ) { |
|
| 207 | 207 | ksort( $newContent ); |
| 208 | 208 | |
| 209 | 209 | if ( $newContent !== $this->botList ) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @param array[] $extra |
| 232 | 232 | * @return array[] |
| 233 | 233 | */ |
| 234 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 234 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 235 | 235 | $newContent = $this->botList; |
| 236 | 236 | foreach ( $newContent as $user => $groups ) { |
| 237 | 237 | if ( isset( $missing[ $user ] ) ) { |