@@ -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\Page; |
| 4 | 4 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param string $title |
| 22 | 22 | * @param Wiki $wiki For the site where the page lives |
| 23 | 23 | */ |
| 24 | - public function __construct( string $title, Wiki $wiki ) { |
|
| 24 | + public function __construct ( string $title, Wiki $wiki ) { |
|
| 25 | 25 | $this->wiki = $wiki; |
| 26 | 26 | $this->title = $title; |
| 27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | - public function getTitle() : string { |
|
| 32 | + public function getTitle () : string { |
|
| 33 | 33 | return $this->title; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param int|null $section A section number to retrieve the content of that section |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - public function getContent( int $section = null ) : string { |
|
| 42 | + public function getContent ( int $section = null ) : string { |
|
| 43 | 43 | if ( $this->content === null ) { |
| 44 | 44 | $this->content = $this->wiki->getPageContent( $this->title, $section ); |
| 45 | 45 | } |
@@ -52,18 +52,18 @@ discard block |
||
| 52 | 52 | * @param array $params |
| 53 | 53 | * @throws \LogicException |
| 54 | 54 | */ |
| 55 | - public function edit( array $params ) : void { |
|
| 55 | + public function edit ( array $params ) : void { |
|
| 56 | 56 | $params = [ |
| 57 | 57 | 'title' => $this->getTitle() |
| 58 | 58 | ] + $params; |
| 59 | 59 | |
| 60 | 60 | $this->wiki->editPage( $params ); |
| 61 | - if ( isset( $params['text'] ) ) { |
|
| 62 | - $this->content = $params['text']; |
|
| 63 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
| 64 | - $this->content .= $params['appendtext']; |
|
| 65 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
| 66 | - $this->content = $params['prependtext'] . $this->content; |
|
| 61 | + if ( isset( $params[ 'text' ] ) ) { |
|
| 62 | + $this->content = $params[ 'text' ]; |
|
| 63 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
| 64 | + $this->content .= $params[ 'appendtext' ]; |
|
| 65 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
| 66 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
| 67 | 67 | } else { |
| 68 | 68 | throw new \LogicException( |
| 69 | 69 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return bool |
| 78 | 78 | */ |
| 79 | - public function exists() : bool { |
|
| 79 | + public function exists () : bool { |
|
| 80 | 80 | $pages = $this->wiki->getRequestFactory()->newFromParams( [ |
| 81 | 81 | 'action' => 'query', |
| 82 | 82 | 'titles' => $this->getTitle() |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param string $regex |
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | - public function matches( string $regex ) : bool { |
|
| 93 | + public function matches ( string $regex ) : bool { |
|
| 94 | 94 | return (bool)preg_match( $regex, $this->getContent() ); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @return string[] |
| 103 | 103 | * @throws MissingMatchException |
| 104 | 104 | */ |
| 105 | - public function getMatch( string $regex ) : array { |
|
| 106 | - $ret = []; |
|
| 105 | + public function getMatch ( string $regex ) : array { |
|
| 106 | + $ret = [ ]; |
|
| 107 | 107 | if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { |
| 108 | 108 | throw new MissingMatchException( "The content of $this does not match the given regex $regex" ); |
| 109 | 109 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @inheritDoc |
| 117 | 117 | */ |
| 118 | - public function getRegex( string $delimiter = '/' ) : string { |
|
| 118 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
| 119 | 119 | return str_replace( ' ', '[ _]', preg_quote( $this->title, $delimiter ) ); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | - public function __toString() : string { |
|
| 127 | + public function __toString () : string { |
|
| 128 | 128 | return $this->getTitle(); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param LoggerInterface $logger |
| 37 | 37 | * @param RequestFactory $requestFactory |
| 38 | 38 | */ |
| 39 | - public function __construct( |
|
| 39 | + public function __construct ( |
|
| 40 | 40 | LoginInfo $li, |
| 41 | 41 | LoggerInterface $logger, |
| 42 | 42 | RequestFactory $requestFactory |
@@ -49,35 +49,35 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @return LoginInfo |
| 51 | 51 | */ |
| 52 | - public function getLoginInfo() : LoginInfo { |
|
| 52 | + public function getLoginInfo () : LoginInfo { |
|
| 53 | 53 | return $this->loginInfo; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @return RequestFactory |
| 58 | 58 | */ |
| 59 | - public function getRequestFactory() : RequestFactory { |
|
| 59 | + public function getRequestFactory () : RequestFactory { |
|
| 60 | 60 | return $this->requestFactory; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @param string $prefix |
| 65 | 65 | */ |
| 66 | - public function setPagePrefix( string $prefix ) : void { |
|
| 66 | + public function setPagePrefix ( string $prefix ) : void { |
|
| 67 | 67 | $this->pagePrefix = $prefix; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * @param string $ident |
| 72 | 72 | */ |
| 73 | - public function setLocalUserIdentifier( string $ident ) : void { |
|
| 73 | + public function setLocalUserIdentifier ( string $ident ) : void { |
|
| 74 | 74 | $this->localUserIdentifier = $ident; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - public function getLocalUserIdentifier() : string { |
|
| 80 | + public function getLocalUserIdentifier () : string { |
|
| 81 | 81 | return $this->localUserIdentifier; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string $title |
| 86 | 86 | * @param int|null $section |
| 87 | 87 | */ |
| 88 | - private function logRead( string $title, int $section = null ) : void { |
|
| 88 | + private function logRead ( string $title, int $section = null ) : void { |
|
| 89 | 89 | $fullTitle = $this->pagePrefix . $title; |
| 90 | 90 | $msg = "Retrieving content of $fullTitle" . ( $section !== null ? ", section $section" : '' ); |
| 91 | 91 | $this->logger->info( $msg ); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @throws MissingPageException |
| 101 | 101 | * @throws MissingSectionException |
| 102 | 102 | */ |
| 103 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 103 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 104 | 104 | $this->logRead( $title, $section ); |
| 105 | 105 | $params = [ |
| 106 | 106 | 'action' => 'query', |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | 113 | if ( $section !== null ) { |
| 114 | - $params['rvsection'] = $section; |
|
| 114 | + $params[ 'rvsection' ] = $section; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $req = $this->buildRequest( $params ); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | throw new MissingPageException( $title ); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $mainSlot = $page->revisions[0]->slots->main; |
|
| 123 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
| 124 | 124 | |
| 125 | 125 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
| 126 | 126 | throw new MissingSectionException( $title, $section ); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param array $params |
| 135 | 135 | * @throws EditException |
| 136 | 136 | */ |
| 137 | - public function editPage( array $params ) : void { |
|
| 137 | + public function editPage ( array $params ) : void { |
|
| 138 | 138 | $this->login(); |
| 139 | 139 | |
| 140 | 140 | $params = [ |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | ] + $params; |
| 144 | 144 | |
| 145 | 145 | if ( BOT_EDITS === true ) { |
| 146 | - $params['bot'] = 1; |
|
| 146 | + $params[ 'bot' ] = 1; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $res = $this->buildRequest( $params )->setPost()->executeSingle(); |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 162 | 162 | * @throws LoginException |
| 163 | 163 | */ |
| 164 | - public function login() : void { |
|
| 164 | + public function login () : void { |
|
| 165 | 165 | if ( $this->loginInfo === null ) { |
| 166 | 166 | throw new CannotLoginException( 'Missing login data' ); |
| 167 | 167 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | $this->loggedIn = true; |
| 193 | 193 | // Clear tokens cache |
| 194 | - $this->tokens = []; |
|
| 194 | + $this->tokens = [ ]; |
|
| 195 | 195 | $this->logger->info( 'Login succeeded' ); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $type |
| 202 | 202 | * @return string |
| 203 | 203 | */ |
| 204 | - public function getToken( string $type ) : string { |
|
| 204 | + public function getToken ( string $type ) : string { |
|
| 205 | 205 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 206 | 206 | $params = [ |
| 207 | 207 | 'action' => 'query', |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @param string $title |
| 222 | 222 | * @return int |
| 223 | 223 | */ |
| 224 | - public function getPageCreationTS( string $title ) : int { |
|
| 224 | + public function getPageCreationTS ( string $title ) : int { |
|
| 225 | 225 | $params = [ |
| 226 | 226 | 'action' => 'query', |
| 227 | 227 | 'prop' => 'revisions', |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | ]; |
| 234 | 234 | |
| 235 | 235 | $page = $this->buildRequest( $params )->executeAsQuery()->current(); |
| 236 | - return strtotime( $page->revisions[0]->timestamp ); |
|
| 236 | + return strtotime( $page->revisions[ 0 ]->timestamp ); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param string $title |
| 243 | 243 | * @param string $reason |
| 244 | 244 | */ |
| 245 | - public function protectPage( string $title, string $reason ) : void { |
|
| 245 | + public function protectPage ( string $title, string $reason ) : void { |
|
| 246 | 246 | $fullTitle = $this->pagePrefix . $title; |
| 247 | 247 | $this->logger->info( "Protecting page $fullTitle" ); |
| 248 | 248 | $this->login(); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param string $username |
| 266 | 266 | * @param string $reason |
| 267 | 267 | */ |
| 268 | - public function blockUser( string $username, string $reason ) : void { |
|
| 268 | + public function blockUser ( string $username, string $reason ) : void { |
|
| 269 | 269 | $this->logger->info( "Blocking user $username" ); |
| 270 | 270 | $this->login(); |
| 271 | 271 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @param array $params |
| 292 | 292 | * @return RequestBase |
| 293 | 293 | */ |
| 294 | - private function buildRequest( array $params ) : RequestBase { |
|
| 294 | + private function buildRequest ( array $params ) : RequestBase { |
|
| 295 | 295 | return $this->requestFactory->newFromParams( $params ); |
| 296 | 296 | } |
| 297 | 297 | } |
@@ -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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** @var string */ |
| 37 | 37 | protected $method = self::METHOD_GET; |
| 38 | 38 | /** @var string[] */ |
| 39 | - protected $newCookies = []; |
|
| 39 | + protected $newCookies = [ ]; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @private Use RequestFactory |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param array $params |
| 45 | 45 | * @param string $domain |
| 46 | 46 | */ |
| 47 | - public function __construct( array $params, string $domain ) { |
|
| 47 | + public function __construct ( array $params, string $domain ) { |
|
| 48 | 48 | $this->params = [ 'format' => 'json' ] + $params; |
| 49 | 49 | $this->url = $domain; |
| 50 | 50 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return self For chaining |
| 56 | 56 | */ |
| 57 | - public function setPost() : self { |
|
| 57 | + public function setPost () : self { |
|
| 58 | 58 | $this->method = self::METHOD_POST; |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | * Optimized version of execute(), to be used with ApiQuery requests. |
| 64 | 64 | * @return Generator |
| 65 | 65 | */ |
| 66 | - public function executeAsQuery() : Generator { |
|
| 67 | - if ( ( $this->params['action'] ?? false ) !== 'query' ) { |
|
| 66 | + public function executeAsQuery () : Generator { |
|
| 67 | + if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) { |
|
| 68 | 68 | throw new BadMethodCallException( 'Not an ApiQuery!' ); |
| 69 | 69 | } |
| 70 | 70 | // TODO Is this always correct? |
| 71 | - $key = $this->params['list'] ?? 'pages'; |
|
| 71 | + $key = $this->params[ 'list' ] ?? 'pages'; |
|
| 72 | 72 | $curParams = $this->params; |
| 73 | 73 | $lim = $this->parseLimit(); |
| 74 | 74 | do { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * Variant of execute() for requests that don't need any continuation. |
| 98 | 98 | * @return stdClass |
| 99 | 99 | */ |
| 100 | - public function executeSingle() : stdClass { |
|
| 100 | + public function executeSingle () : stdClass { |
|
| 101 | 101 | $curParams = $this->params; |
| 102 | 102 | $res = $this->makeRequestInternal( $curParams ); |
| 103 | 103 | $this->handleErrorAndWarnings( $res ); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | /** |
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | - private function parseLimit() : int { |
|
| 110 | + private function parseLimit () : int { |
|
| 111 | 111 | foreach ( $this->params as $name => $val ) { |
| 112 | 112 | if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { |
| 113 | 113 | return $val === 'max' ? -1 : (int)$val; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param string $resKey |
| 125 | 125 | * @return int|null |
| 126 | 126 | */ |
| 127 | - private function countQueryResults( \stdClass $res, string $resKey ) : ?int { |
|
| 127 | + private function countQueryResults ( \stdClass $res, string $resKey ) : ?int { |
|
| 128 | 128 | if ( !isset( $res->query->$resKey ) ) { |
| 129 | 129 | return null; |
| 130 | 130 | } |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | * @param array $params |
| 152 | 152 | * @return \stdClass |
| 153 | 153 | */ |
| 154 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 154 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 155 | 155 | if ( $this->method === self::METHOD_POST ) { |
| 156 | - $params['maxlag'] = self::MAXLAG; |
|
| 156 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 157 | 157 | } |
| 158 | 158 | $query = http_build_query( $params ); |
| 159 | 159 | |
@@ -169,17 +169,17 @@ discard block |
||
| 169 | 169 | * @param string $params |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 172 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * After a request, set cookies for the next ones |
| 176 | 176 | * |
| 177 | 177 | * @param array $cookies |
| 178 | 178 | */ |
| 179 | - protected function setCookies( array $cookies ) : void { |
|
| 179 | + protected function setCookies ( array $cookies ) : void { |
|
| 180 | 180 | foreach ( $cookies as $cookie ) { |
| 181 | 181 | $bits = explode( ';', $cookie ); |
| 182 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
| 182 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
| 183 | 183 | self::$cookiesToSet[ $name ] = $value; |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @param \stdClass $res |
| 191 | 191 | * @return APIRequestException |
| 192 | 192 | */ |
| 193 | - private function getException( \stdClass $res ) : APIRequestException { |
|
| 193 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
| 194 | 194 | switch ( $res->error->code ) { |
| 195 | 195 | case 'missingtitle': |
| 196 | 196 | $ex = new MissingPageException; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @param \stdClass $res |
| 217 | 217 | * @throws APIRequestException |
| 218 | 218 | */ |
| 219 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
| 219 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
| 220 | 220 | if ( isset( $res->error ) ) { |
| 221 | 221 | throw $this->getException( $res ); |
| 222 | 222 | } |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | - protected function getHeaders() :array { |
|
| 235 | + protected function getHeaders () :array { |
|
| 236 | 236 | $ret = self::HEADERS; |
| 237 | 237 | if ( self::$cookiesToSet ) { |
| 238 | - $cookies = []; |
|
| 238 | + $cookies = [ ]; |
|
| 239 | 239 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 240 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 240 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 241 | 241 | } |
| 242 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 242 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 243 | 243 | } |
| 244 | 244 | return $ret; |
| 245 | 245 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param array $headers |
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | - protected function buildHeadersString( array $headers ) : string { |
|
| 253 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 254 | 254 | $ret = ''; |
| 255 | 255 | foreach ( $headers as $header ) { |
| 256 | 256 | $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\Task\Subtask; |
| 4 | 4 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @inheritDoc |
| 19 | 19 | */ |
| 20 | - public function runInternal() : int { |
|
| 20 | + public function runInternal () : int { |
|
| 21 | 21 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 22 | 22 | |
| 23 | 23 | if ( !$users ) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @param User $user |
| 38 | 38 | */ |
| 39 | - protected function processUser( User $user ) : void { |
|
| 39 | + protected function processUser ( User $user ) : void { |
|
| 40 | 40 | $this->getLogger()->info( "Processing user $user" ); |
| 41 | 41 | try { |
| 42 | 42 | $num = $this->getLastPageNum( $user ) + 1; |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | * @return int |
| 72 | 72 | * @throws TaskException |
| 73 | 73 | */ |
| 74 | - protected function getLastPageNum( User $user ) : int { |
|
| 74 | + protected function getLastPageNum ( User $user ) : int { |
|
| 75 | 75 | $this->getLogger()->info( "Retrieving previous pages for $user" ); |
| 76 | 76 | |
| 77 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
| 77 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
| 78 | 78 | |
| 79 | 79 | $prefixes = [ "$unprefixedTitle/$user/" ]; |
| 80 | 80 | foreach ( $user->getAliases() as $alias ) { |
| 81 | - $prefixes[] = "$unprefixedTitle/$alias/"; |
|
| 81 | + $prefixes[ ] = "$unprefixedTitle/$alias/"; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $params = [ |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | ]; |
| 91 | 91 | $pagesIterator = new AppendIterator(); |
| 92 | 92 | foreach ( $prefixes as $prefix ) { |
| 93 | - $params['apprefix'] = $prefix; |
|
| 93 | + $params[ 'apprefix' ] = $prefix; |
|
| 94 | 94 | $res = $this->getRequestFactory()->newFromParams( $params )->executeAsQuery(); |
| 95 | 95 | $pagesIterator->append( new NoRewindIterator( $res ) ); |
| 96 | 96 | } |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * @param string $title |
| 117 | 117 | * @param User $user |
| 118 | 118 | */ |
| 119 | - protected function createPage( string $title, User $user ) : void { |
|
| 119 | + protected function createPage ( string $title, User $user ) : void { |
|
| 120 | 120 | $this->getLogger()->info( "Creating page $title" ); |
| 121 | 121 | $groups = $user->getGroupsWithDates(); |
| 122 | 122 | $textParams = [ |
| 123 | 123 | '$user' => $user->getName(), |
| 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 | |
| 129 | 129 | $params = [ |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param Page $basePage |
| 142 | 142 | * @param string $newText |
| 143 | 143 | */ |
| 144 | - protected function createBasePage( Page $basePage, string $newText ) : void { |
|
| 144 | + protected function createBasePage ( Page $basePage, string $newText ) : void { |
|
| 145 | 145 | $this->getLogger()->info( "Creating base page $basePage" ); |
| 146 | 146 | |
| 147 | 147 | $params = [ |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param Page $basePage |
| 158 | 158 | * @param string $newText |
| 159 | 159 | */ |
| 160 | - protected function updateBasePage( Page $basePage, string $newText ) : void { |
|
| 160 | + protected function updateBasePage ( Page $basePage, string $newText ) : void { |
|
| 161 | 161 | $this->getLogger()->info( "Updating base page $basePage" ); |
| 162 | 162 | |
| 163 | 163 | $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 | |
@@ -19,15 +19,15 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @inheritDoc |
| 21 | 21 | */ |
| 22 | - protected function getSubtasksMap(): array { |
|
| 22 | + protected function getSubtasksMap (): array { |
|
| 23 | 23 | // Everything is done here. |
| 24 | - return []; |
|
| 24 | + return [ ]; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @inheritDoc |
| 29 | 29 | */ |
| 30 | - public function runInternal() : int { |
|
| 30 | + public function runInternal () : int { |
|
| 31 | 31 | $this->actualList = $this->getActualAdmins(); |
| 32 | 32 | $pageBotList = $this->getBotList(); |
| 33 | 33 | $this->botList = $pageBotList->getDecodedContent(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - protected function getActualAdmins() : array { |
|
| 57 | + protected function getActualAdmins () : array { |
|
| 58 | 58 | $params = [ |
| 59 | 59 | 'action' => 'query', |
| 60 | 60 | 'list' => 'allusers', |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param Generator $data |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - protected function extractAdmins( Generator $data ) : array { |
|
| 75 | - $ret = []; |
|
| 74 | + protected function extractAdmins ( Generator $data ) : array { |
|
| 75 | + $ret = [ ]; |
|
| 76 | 76 | $blacklist = $this->getOpt( 'exclude-admins' ); |
| 77 | 77 | foreach ( $data as $u ) { |
| 78 | 78 | if ( in_array( $u->name, $blacklist, true ) ) { |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return array[] |
| 91 | 91 | */ |
| 92 | - protected function getMissingGroups() : array { |
|
| 93 | - $missing = []; |
|
| 92 | + protected function getMissingGroups () : array { |
|
| 93 | + $missing = [ ]; |
|
| 94 | 94 | foreach ( $this->actualList as $adm => $groups ) { |
| 95 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); |
|
| 95 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); |
|
| 96 | 96 | |
| 97 | 97 | foreach ( $curMissing as $group ) { |
| 98 | 98 | try { |
| 99 | 99 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 100 | 100 | } catch ( TaskException $e ) { |
| 101 | - $this->errors[] = $e->getMessage(); |
|
| 101 | + $this->errors[ ] = $e->getMessage(); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @return string |
| 114 | 114 | * @throws TaskException |
| 115 | 115 | */ |
| 116 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 116 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 117 | 117 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 118 | 118 | |
| 119 | 119 | $wiki = $this->getWiki(); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @param string $group |
| 149 | 149 | * @return string|null |
| 150 | 150 | */ |
| 151 | - private function extractTimestamp( Generator $data, string $group ) : ?string { |
|
| 151 | + private function extractTimestamp ( Generator $data, string $group ) : ?string { |
|
| 152 | 152 | $ts = null; |
| 153 | 153 | foreach ( $data as $entry ) { |
| 154 | 154 | if ( |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return array[] |
| 169 | 169 | */ |
| 170 | - protected function getExtraGroups() : array { |
|
| 171 | - $extra = []; |
|
| 170 | + protected function getExtraGroups () : array { |
|
| 171 | + $extra = [ ]; |
|
| 172 | 172 | foreach ( $this->botList as $name => $groups ) { |
| 173 | 173 | $groups = array_diff_key( $groups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ); |
| 174 | 174 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string[] $names |
| 185 | 185 | * @return Generator |
| 186 | 186 | */ |
| 187 | - private function getRenameEntries( array $names ) : Generator { |
|
| 187 | + private function getRenameEntries ( array $names ) : Generator { |
|
| 188 | 188 | $titles = array_map( static function ( $x ) { |
| 189 | 189 | return "Utente:$x"; |
| 190 | 190 | }, $names ); |
@@ -208,14 +208,14 @@ discard block |
||
| 208 | 208 | * @param string[] $names |
| 209 | 209 | * @return string[] [ old_name => new_name ] |
| 210 | 210 | */ |
| 211 | - protected function getRenamedUsers( array $names ) : array { |
|
| 211 | + protected function getRenamedUsers ( array $names ) : array { |
|
| 212 | 212 | if ( !$names ) { |
| 213 | - return []; |
|
| 213 | + return [ ]; |
|
| 214 | 214 | } |
| 215 | 215 | $this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) ); |
| 216 | 216 | |
| 217 | 217 | $data = $this->getRenameEntries( $names ); |
| 218 | - $ret = []; |
|
| 218 | + $ret = [ ]; |
|
| 219 | 219 | foreach ( $data as $entry ) { |
| 220 | 220 | // 1 month is arbitrary |
| 221 | 221 | if ( strtotime( $entry->timestamp ) > strtotime( '-1 month' ) ) { |
@@ -233,18 +233,18 @@ discard block |
||
| 233 | 233 | * @param array &$newContent |
| 234 | 234 | * @param array $removed |
| 235 | 235 | */ |
| 236 | - private function handleRenames( array &$newContent, array $removed ) : void { |
|
| 236 | + private function handleRenames ( array &$newContent, array $removed ) : void { |
|
| 237 | 237 | $renameMap = $this->getRenamedUsers( array_keys( $removed ) ); |
| 238 | 238 | foreach ( $removed as $oldName => $info ) { |
| 239 | 239 | if ( |
| 240 | 240 | array_key_exists( $oldName, $renameMap ) && |
| 241 | - array_key_exists( $renameMap[$oldName], $newContent ) |
|
| 241 | + array_key_exists( $renameMap[ $oldName ], $newContent ) |
|
| 242 | 242 | ) { |
| 243 | 243 | // This user was renamed! Add this name as alias, if they're still listed |
| 244 | 244 | $newName = $renameMap[ $oldName ]; |
| 245 | 245 | $this->getLogger()->info( "Found rename $oldName -> $newName" ); |
| 246 | - $aliases = array_unique( array_merge( $newContent[ $newName ]['aliases'], [ $oldName ] ) ); |
|
| 247 | - $newContent[ $newName ]['aliases'] = $aliases; |
|
| 246 | + $aliases = array_unique( array_merge( $newContent[ $newName ][ 'aliases' ], [ $oldName ] ) ); |
|
| 247 | + $newContent[ $newName ][ 'aliases' ] = $aliases; |
|
| 248 | 248 | // Transfer overrides to the new name. |
| 249 | 249 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); |
| 250 | 250 | $newContent[ $newName ] = array_merge( $newContent[ $newName ], $overrides ); |
@@ -258,12 +258,12 @@ discard block |
||
| 258 | 258 | * @param array[] $extra |
| 259 | 259 | * @return string[] Removed users |
| 260 | 260 | */ |
| 261 | - private function handleExtraAndMissing( |
|
| 261 | + private function handleExtraAndMissing ( |
|
| 262 | 262 | array &$newContent, |
| 263 | 263 | array $missing, |
| 264 | 264 | array $extra |
| 265 | 265 | ) : array { |
| 266 | - $removed = []; |
|
| 266 | + $removed = [ ]; |
|
| 267 | 267 | foreach ( $newContent as $user => $groups ) { |
| 268 | 268 | if ( isset( $missing[ $user ] ) ) { |
| 269 | 269 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { |
| 274 | 274 | $newContent[ $user ] = $newGroups; |
| 275 | 275 | } else { |
| 276 | - $removed[$user] = $newContent[$user]; |
|
| 276 | + $removed[ $user ] = $newContent[ $user ]; |
|
| 277 | 277 | unset( $newContent[ $user ] ); |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param array[] $extra |
| 291 | 291 | * @return array[] |
| 292 | 292 | */ |
| 293 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 293 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 294 | 294 | $newContent = $this->botList; |
| 295 | 295 | |
| 296 | 296 | $removed = $this->handleExtraAndMissing( $newContent, $missing, $extra ); |
@@ -309,12 +309,12 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @param array[] &$newContent |
| 311 | 311 | */ |
| 312 | - protected function removeOverrides( array &$newContent ) : void { |
|
| 313 | - $removed = []; |
|
| 312 | + protected function removeOverrides ( array &$newContent ) : void { |
|
| 313 | + $removed = [ ]; |
|
| 314 | 314 | foreach ( $newContent as $user => $groups ) { |
| 315 | 315 | if ( PageBotList::isOverrideExpired( $groups ) ) { |
| 316 | 316 | unset( $newContent[ $user ][ 'override' ] ); |
| 317 | - $removed[] = $user; |
|
| 317 | + $removed[ ] = $user; |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\TaskHelper; |
| 4 | 4 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** @var User[]|null */ |
| 16 | 16 | private $processUsers; |
| 17 | 17 | /** @var PageRiconferma[] */ |
| 18 | - private $createdPages = []; |
|
| 18 | + private $createdPages = [ ]; |
|
| 19 | 19 | /** @var PageRiconferma[]|null */ |
| 20 | 20 | private $openPages; |
| 21 | 21 | /** @var PageRiconferma[]|null */ |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return User[] |
| 28 | 28 | */ |
| 29 | - public function getUsersToProcess() : array { |
|
| 29 | + public function getUsersToProcess () : array { |
|
| 30 | 30 | if ( $this->processUsers === null ) { |
| 31 | - $this->processUsers = []; |
|
| 31 | + $this->processUsers = [ ]; |
|
| 32 | 32 | foreach ( $this->getBotList()->getAdminsList() as $name => $userInfo ) { |
| 33 | 33 | if ( $this->shouldAddUser( $userInfo ) ) { |
| 34 | 34 | $this->processUsers[ $name ] = new User( $userInfo, $this->getWiki() ); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param UserInfo $ui |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - private function shouldAddUser( UserInfo $ui ) : bool { |
|
| 48 | + private function shouldAddUser ( UserInfo $ui ) : bool { |
|
| 49 | 49 | $timestamp = $this->getBotList()->getOverrideTimestamp( $ui ); |
| 50 | 50 | $override = $timestamp !== null; |
| 51 | 51 | |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return PageRiconferma[] |
| 65 | 65 | */ |
| 66 | - public function getOpenPages() : array { |
|
| 66 | + public function getOpenPages () : array { |
|
| 67 | 67 | if ( $this->openPages === null ) { |
| 68 | - $this->openPages = []; |
|
| 68 | + $this->openPages = [ ]; |
|
| 69 | 69 | $mainTitle = $this->getOpt( 'main-page-title' ); |
| 70 | 70 | $params = [ |
| 71 | 71 | 'action' => 'query', |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $pages = $this->getRequestFactory()->newFromParams( $params )->executeAsQuery(); |
| 80 | 80 | foreach ( $pages->current()->templates as $page ) { |
| 81 | 81 | if ( preg_match( "!$titleReg/[^/]+/\d!", $page->title ) ) { |
| 82 | - $this->openPages[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
| 82 | + $this->openPages[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return PageRiconferma[] |
| 94 | 94 | */ |
| 95 | - public function getPagesToClose() : array { |
|
| 95 | + public function getPagesToClose () : array { |
|
| 96 | 96 | if ( $this->pagesToClose === null ) { |
| 97 | - $this->pagesToClose = []; |
|
| 97 | + $this->pagesToClose = [ ]; |
|
| 98 | 98 | foreach ( $this->getOpenPages() as $page ) { |
| 99 | 99 | if ( time() > $page->getEndTimestamp() ) { |
| 100 | - $this->pagesToClose[] = $page; |
|
| 100 | + $this->pagesToClose[ ] = $page; |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param string $name |
| 111 | 111 | */ |
| 112 | - public function removeUser( string $name ) : void { |
|
| 112 | + public function removeUser ( string $name ) : void { |
|
| 113 | 113 | unset( $this->processUsers[ $name ] ); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * @return PageRiconferma[] |
| 118 | 118 | */ |
| 119 | - public function getCreatedPages() : array { |
|
| 119 | + public function getCreatedPages () : array { |
|
| 120 | 120 | return $this->createdPages; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @param PageRiconferma $page |
| 125 | 125 | */ |
| 126 | - public function addCreatedPage( PageRiconferma $page ) : void { |
|
| 127 | - $this->createdPages[] = $page; |
|
| 126 | + public function addCreatedPage ( PageRiconferma $page ) : void { |
|
| 127 | + $this->createdPages[ ] = $page; |
|
| 128 | 128 | } |
| 129 | 129 | } |