@@ -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\Subtask; |
| 4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @inheritDoc |
| 17 | 17 | */ |
| 18 | - public function runInternal() : int { |
|
| 18 | + public function runInternal () : int { |
|
| 19 | 19 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 20 | 20 | |
| 21 | 21 | if ( !$users ) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param User $user |
| 36 | 36 | */ |
| 37 | - protected function processUser( User $user ) : void { |
|
| 37 | + protected function processUser ( User $user ) : void { |
|
| 38 | 38 | $this->getLogger()->info( "Processing user $user" ); |
| 39 | 39 | try { |
| 40 | 40 | $num = $this->getLastPageNum( $user ) + 1; |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | * @return int |
| 70 | 70 | * @throws TaskException |
| 71 | 71 | */ |
| 72 | - protected function getLastPageNum( User $user ) : int { |
|
| 72 | + protected function getLastPageNum ( User $user ) : int { |
|
| 73 | 73 | $this->getLogger()->info( "Retrieving previous pages for $user" ); |
| 74 | 74 | |
| 75 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
| 75 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
| 76 | 76 | |
| 77 | 77 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
| 78 | 78 | foreach ( $user->getAliases() as $alias ) { |
| 79 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
| 79 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $params = [ |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | * @param string $title |
| 111 | 111 | * @param User $user |
| 112 | 112 | */ |
| 113 | - protected function createPage( string $title, User $user ) : void { |
|
| 113 | + protected function createPage ( string $title, User $user ) : void { |
|
| 114 | 114 | $this->getLogger()->info( "Creating page $title" ); |
| 115 | 115 | $groups = $user->getGroupsWithDates(); |
| 116 | 116 | $textParams = [ |
| 117 | 117 | '$user' => $user->getName(), |
| 118 | - '$date' => $groups['sysop'], |
|
| 119 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 120 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 118 | + '$date' => $groups[ 'sysop' ], |
|
| 119 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 120 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 121 | 121 | ]; |
| 122 | 122 | |
| 123 | 123 | $params = [ |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param Page $basePage |
| 136 | 136 | * @param string $newText |
| 137 | 137 | */ |
| 138 | - protected function createBasePage( Page $basePage, string $newText ) : void { |
|
| 138 | + protected function createBasePage ( Page $basePage, string $newText ) : void { |
|
| 139 | 139 | $this->getLogger()->info( "Creating base page $basePage" ); |
| 140 | 140 | |
| 141 | 141 | $params = [ |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @param Page $basePage |
| 152 | 152 | * @param string $newText |
| 153 | 153 | */ |
| 154 | - protected function updateBasePage( Page $basePage, string $newText ) : void { |
|
| 154 | + protected function updateBasePage ( Page $basePage, string $newText ) : void { |
|
| 155 | 155 | $this->getLogger()->info( "Updating base page $basePage" ); |
| 156 | 156 | |
| 157 | 157 | $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\Request; |
| 4 | 4 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** @var string */ |
| 33 | 33 | protected $method = self::METHOD_GET; |
| 34 | 34 | /** @var string[] */ |
| 35 | - protected $newCookies = []; |
|
| 35 | + protected $newCookies = [ ]; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @private Use RequestFactory |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $params |
| 41 | 41 | * @param string $domain |
| 42 | 42 | */ |
| 43 | - public function __construct( array $params, string $domain ) { |
|
| 43 | + public function __construct ( array $params, string $domain ) { |
|
| 44 | 44 | $this->params = [ 'format' => 'json' ] + $params; |
| 45 | 45 | $this->url = $domain; |
| 46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return self For chaining |
| 52 | 52 | */ |
| 53 | - public function setPost() : self { |
|
| 53 | + public function setPost () : self { |
|
| 54 | 54 | $this->method = self::METHOD_POST; |
| 55 | 55 | return $this; |
| 56 | 56 | } |
@@ -62,15 +62,15 @@ discard block |
||
| 62 | 62 | * @todo Return an iterable object which automatically continues the query only if the last |
| 63 | 63 | * entry available is reached, instead of requesting max results. |
| 64 | 64 | */ |
| 65 | - public function execute() : \stdClass { |
|
| 65 | + public function execute () : \stdClass { |
|
| 66 | 66 | $curParams = $this->params; |
| 67 | 67 | $lim = $this->parseLimit(); |
| 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 | // Assume that we have finished |
| 76 | 76 | $finished = true; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * FIXME Should be revamped together with countResults |
| 96 | 96 | * @return int |
| 97 | 97 | */ |
| 98 | - private function parseLimit() : int { |
|
| 98 | + private function parseLimit () : int { |
|
| 99 | 99 | foreach ( $this->params as $name => $val ) { |
| 100 | 100 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
| 101 | 101 | return $val === 'max' ? -1 : (int)$val; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param \stdClass $res |
| 114 | 114 | * @return int|null |
| 115 | 115 | */ |
| 116 | - private function countResults( \stdClass $res ) : ?int { |
|
| 116 | + private function countResults ( \stdClass $res ) : ?int { |
|
| 117 | 117 | if ( isset( $res->query->pages ) && count( $res->query->pages ) === 1 ) { |
| 118 | 118 | $pages = $res->query->pages; |
| 119 | 119 | return count( reset( $pages )->revisions ); |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @param array $params |
| 128 | 128 | * @return \stdClass |
| 129 | 129 | */ |
| 130 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 130 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 131 | 131 | if ( $this->method === self::METHOD_POST ) { |
| 132 | - $params['maxlag'] = self::MAXLAG; |
|
| 132 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 133 | 133 | } |
| 134 | 134 | $query = http_build_query( $params ); |
| 135 | 135 | |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | * @param string $params |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 148 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * After a request, set cookies for the next ones |
| 152 | 152 | * |
| 153 | 153 | * @param array $cookies |
| 154 | 154 | */ |
| 155 | - protected function setCookies( array $cookies ) : void { |
|
| 155 | + protected function setCookies ( array $cookies ) : void { |
|
| 156 | 156 | foreach ( $cookies as $cookie ) { |
| 157 | 157 | $bits = explode( ';', $cookie ); |
| 158 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
| 158 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
| 159 | 159 | self::$cookiesToSet[ $name ] = $value; |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param \stdClass $res |
| 167 | 167 | * @return APIRequestException |
| 168 | 168 | */ |
| 169 | - private function getException( \stdClass $res ) : APIRequestException { |
|
| 169 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
| 170 | 170 | switch ( $res->error->code ) { |
| 171 | 171 | case 'missingtitle': |
| 172 | 172 | $ex = new MissingPageException; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param \stdClass $res |
| 190 | 190 | * @throws APIRequestException |
| 191 | 191 | */ |
| 192 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
| 192 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
| 193 | 193 | if ( isset( $res->error ) ) { |
| 194 | 194 | throw $this->getException( $res ); |
| 195 | 195 | } elseif ( isset( $res->warnings ) ) { |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param \stdClass[] $sets |
| 206 | 206 | * @return \stdClass |
| 207 | 207 | */ |
| 208 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 208 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 209 | 209 | // Use the first set as template |
| 210 | 210 | $ret = array_shift( $sets ); |
| 211 | 211 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param array|\stdClass $second |
| 223 | 223 | * @return array|\stdClass array |
| 224 | 224 | */ |
| 225 | - private function recursiveMerge( $first, $second ) { |
|
| 225 | + private function recursiveMerge ( $first, $second ) { |
|
| 226 | 226 | $ret = $first; |
| 227 | 227 | if ( is_array( $second ) ) { |
| 228 | 228 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return array |
| 242 | 242 | */ |
| 243 | - protected function getHeaders() :array { |
|
| 243 | + protected function getHeaders () :array { |
|
| 244 | 244 | $ret = self::HEADERS; |
| 245 | 245 | if ( self::$cookiesToSet ) { |
| 246 | - $cookies = []; |
|
| 246 | + $cookies = [ ]; |
|
| 247 | 247 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 248 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 248 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 249 | 249 | } |
| 250 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 250 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 251 | 251 | } |
| 252 | 252 | return $ret; |
| 253 | 253 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param array $headers |
| 259 | 259 | * @return string |
| 260 | 260 | */ |
| 261 | - protected function buildHeadersString( array $headers ) : string { |
|
| 261 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 262 | 262 | $ret = ''; |
| 263 | 263 | foreach ( $headers as $header ) { |
| 264 | 264 | $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\Wiki; |
| 4 | 4 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param LoggerInterface $logger |
| 35 | 35 | * @param RequestFactory $requestFactory |
| 36 | 36 | */ |
| 37 | - public function __construct( |
|
| 37 | + public function __construct ( |
|
| 38 | 38 | LoginInfo $li, |
| 39 | 39 | LoggerInterface $logger, |
| 40 | 40 | RequestFactory $requestFactory |
@@ -47,28 +47,28 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return LoginInfo |
| 49 | 49 | */ |
| 50 | - public function getLoginInfo() : LoginInfo { |
|
| 50 | + public function getLoginInfo () : LoginInfo { |
|
| 51 | 51 | return $this->loginInfo; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @return RequestFactory |
| 56 | 56 | */ |
| 57 | - public function getRequestFactory() : RequestFactory { |
|
| 57 | + public function getRequestFactory () : RequestFactory { |
|
| 58 | 58 | return $this->requestFactory; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @param string $ident |
| 63 | 63 | */ |
| 64 | - public function setLocalUserIdentifier( string $ident ) : void { |
|
| 64 | + public function setLocalUserIdentifier ( string $ident ) : void { |
|
| 65 | 65 | $this->localUserIdentifier = $ident; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - public function getLocalUserIdentifier() : string { |
|
| 71 | + public function getLocalUserIdentifier () : string { |
|
| 72 | 72 | return $this->localUserIdentifier; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @throws MissingPageException |
| 82 | 82 | * @throws MissingSectionException |
| 83 | 83 | */ |
| 84 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 84 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 85 | 85 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
| 86 | 86 | $this->logger->info( $msg ); |
| 87 | 87 | $params = [ |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ]; |
| 94 | 94 | |
| 95 | 95 | if ( $section !== null ) { |
| 96 | - $params['rvsection'] = $section; |
|
| 96 | + $params[ 'rvsection' ] = $section; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $req = $this->buildRequest( $params ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | throw new MissingPageException( $title ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $mainSlot = $page->revisions[0]->slots->main; |
|
| 106 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
| 107 | 107 | |
| 108 | 108 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
| 109 | 109 | throw new MissingSectionException( $title, $section ); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param array $params |
| 118 | 118 | * @throws EditException |
| 119 | 119 | */ |
| 120 | - public function editPage( array $params ) : void { |
|
| 120 | + public function editPage ( array $params ) : void { |
|
| 121 | 121 | $this->login(); |
| 122 | 122 | |
| 123 | 123 | $params = [ |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | ] + $params; |
| 127 | 127 | |
| 128 | 128 | if ( BOT_EDITS === true ) { |
| 129 | - $params['bot'] = 1; |
|
| 129 | + $params[ 'bot' ] = 1; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 145 | 145 | * @throws LoginException |
| 146 | 146 | */ |
| 147 | - public function login() : void { |
|
| 147 | + public function login () : void { |
|
| 148 | 148 | if ( $this->loginInfo === null ) { |
| 149 | 149 | throw new CannotLoginException( 'Missing login data' ); |
| 150 | 150 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | self::$loggedIn = true; |
| 176 | 176 | // Clear tokens cache |
| 177 | - $this->tokens = []; |
|
| 177 | + $this->tokens = [ ]; |
|
| 178 | 178 | $this->logger->info( 'Login succeeded' ); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string $type |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public function getToken( string $type ) : string { |
|
| 187 | + public function getToken ( string $type ) : string { |
|
| 188 | 188 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 189 | 189 | $params = [ |
| 190 | 190 | 'action' => 'query', |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * @param string $title |
| 208 | 208 | * @return int |
| 209 | 209 | */ |
| 210 | - public function getPageCreationTS( string $title ) : int { |
|
| 210 | + public function getPageCreationTS ( string $title ) : int { |
|
| 211 | 211 | $params = [ |
| 212 | 212 | 'action' => 'query', |
| 213 | 213 | 'prop' => 'revisions', |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | $res = $this->buildRequest( $params )->execute(); |
| 222 | 222 | $data = $res->query->pages; |
| 223 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 223 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @param string $title |
| 230 | 230 | * @param string $reason |
| 231 | 231 | */ |
| 232 | - public function protectPage( string $title, string $reason ) : void { |
|
| 232 | + public function protectPage ( string $title, string $reason ) : void { |
|
| 233 | 233 | $this->logger->info( "Protecting page $title" ); |
| 234 | 234 | $this->login(); |
| 235 | 235 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param array $params |
| 251 | 251 | * @return RequestBase |
| 252 | 252 | */ |
| 253 | - private function buildRequest( array $params ) : RequestBase { |
|
| 253 | + private function buildRequest ( array $params ) : RequestBase { |
|
| 254 | 254 | return $this->requestFactory->newFromParams( $params ); |
| 255 | 255 | } |
| 256 | 256 | } |