@@ -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 = [ |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | 'apprefix' => implode( '|', $prefixes ), |
| 87 | 87 | 'aplimit' => 'max' |
| 88 | 88 | ]; |
| 89 | - $foundPages = []; |
|
| 89 | + $foundPages = [ ]; |
|
| 90 | 90 | foreach ( $prefixes as $prefix ) { |
| 91 | - $params['apprefix'] = $prefix; |
|
| 91 | + $params[ 'apprefix' ] = $prefix; |
|
| 92 | 92 | $res = $this->getRequestFactory()->newFromParams( $params )->execute(); |
| 93 | 93 | $foundPages = array_merge( $foundPages, $res->query->allpages ); |
| 94 | 94 | } |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * @param string $title |
| 115 | 115 | * @param User $user |
| 116 | 116 | */ |
| 117 | - protected function createPage( string $title, User $user ) : void { |
|
| 117 | + protected function createPage ( string $title, User $user ) : void { |
|
| 118 | 118 | $this->getLogger()->info( "Creating page $title" ); |
| 119 | 119 | $groups = $user->getGroupsWithDates(); |
| 120 | 120 | $textParams = [ |
| 121 | 121 | '$user' => $user->getName(), |
| 122 | - '$date' => $groups['sysop'], |
|
| 123 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
| 124 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
| 122 | + '$date' => $groups[ 'sysop' ], |
|
| 123 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
| 124 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
| 125 | 125 | ]; |
| 126 | 126 | |
| 127 | 127 | $params = [ |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param Page $basePage |
| 140 | 140 | * @param string $newText |
| 141 | 141 | */ |
| 142 | - protected function createBasePage( Page $basePage, string $newText ) : void { |
|
| 142 | + protected function createBasePage ( Page $basePage, string $newText ) : void { |
|
| 143 | 143 | $this->getLogger()->info( "Creating base page $basePage" ); |
| 144 | 144 | |
| 145 | 145 | $params = [ |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param Page $basePage |
| 156 | 156 | * @param string $newText |
| 157 | 157 | */ |
| 158 | - protected function updateBasePage( Page $basePage, string $newText ) : void { |
|
| 158 | + protected function updateBasePage ( Page $basePage, string $newText ) : void { |
|
| 159 | 159 | $this->getLogger()->info( "Updating base page $basePage" ); |
| 160 | 160 | |
| 161 | 161 | $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\Wiki\Page; |
| 4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** @var int */ |
| 15 | 15 | private $opposeSection; |
| 16 | 16 | /** @var array Counts of votes for each section */ |
| 17 | - private $sectionCounts = []; |
|
| 17 | + private $sectionCounts = [ ]; |
|
| 18 | 18 | |
| 19 | 19 | // Possible outcomes of a vote |
| 20 | 20 | public const OUTCOME_OK = 0; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * because they can vary depending on whether the page is a vote, which is relatively |
| 34 | 34 | * expensive to know since it requires parsing the content of the page. |
| 35 | 35 | */ |
| 36 | - private function defineSections() : void { |
|
| 36 | + private function defineSections () : void { |
|
| 37 | 37 | $this->supportSection = $this->isVote() ? 3 : 0; |
| 38 | 38 | $this->opposeSection = $this->isVote() ? 4 : 3; |
| 39 | 39 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public function getUserName() : string { |
|
| 47 | - return explode( '/', $this->title )[2]; |
|
| 46 | + public function getUserName () : string { |
|
| 47 | + return explode( '/', $this->title )[ 2 ]; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return int |
| 54 | 54 | */ |
| 55 | - public function getNum() : int { |
|
| 55 | + public function getNum () : int { |
|
| 56 | 56 | $bits = explode( '/', $this->getTitle() ); |
| 57 | 57 | return (int)end( $bits ); |
| 58 | 58 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - public function getUserNum() : string { |
|
| 66 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
| 65 | + public function getUserNum () : string { |
|
| 66 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return int |
| 73 | 73 | */ |
| 74 | - public function getOpposingCount() : int { |
|
| 74 | + public function getOpposingCount () : int { |
|
| 75 | 75 | $this->defineSections(); |
| 76 | 76 | return $this->getCountForSection( $this->opposeSection ); |
| 77 | 77 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @return int |
| 83 | 83 | * @throws \BadMethodCallException |
| 84 | 84 | */ |
| 85 | - public function getSupportCount() : int { |
|
| 85 | + public function getSupportCount () : int { |
|
| 86 | 86 | if ( !$this->isVote() ) { |
| 87 | 87 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
| 88 | 88 | } |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | * @param int $secNum |
| 97 | 97 | * @return int |
| 98 | 98 | */ |
| 99 | - protected function getCountForSection( int $secNum ) : int { |
|
| 99 | + protected function getCountForSection ( int $secNum ) : int { |
|
| 100 | 100 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
| 101 | 101 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
| 102 | 102 | // Let's hope that this is good enough... |
| 103 | - $this->sectionCounts[$secNum] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 103 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 104 | 104 | } |
| 105 | - return $this->sectionCounts[$secNum]; |
|
| 105 | + return $this->sectionCounts[ $secNum ]; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,9 +110,9 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return int |
| 112 | 112 | */ |
| 113 | - protected function getQuorum() : int { |
|
| 113 | + protected function getQuorum () : int { |
|
| 114 | 114 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
| 115 | - return (int)$this->getMatch( $reg )[1]; |
|
| 115 | + return (int)$this->getMatch( $reg )[ 1 ]; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return bool |
| 122 | 122 | */ |
| 123 | - public function hasOpposition() : bool { |
|
| 123 | + public function hasOpposition () : bool { |
|
| 124 | 124 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return int One of the OUTCOME_* constants |
| 131 | 131 | */ |
| 132 | - public function getOutcome() : int { |
|
| 132 | + public function getOutcome () : int { |
|
| 133 | 133 | if ( !$this->isVote() ) { |
| 134 | 134 | return self::OUTCOME_OK; |
| 135 | 135 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @throws \BadMethodCallException |
| 153 | 153 | * @throws \LogicException |
| 154 | 154 | */ |
| 155 | - public function getOutcomeText() : string { |
|
| 155 | + public function getOutcomeText () : string { |
|
| 156 | 156 | if ( !$this->isVote() ) { |
| 157 | 157 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
| 158 | 158 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - public function isVote() : bool { |
|
| 189 | + public function isVote () : bool { |
|
| 190 | 190 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
| 191 | 191 | return !$this->matches( $sectionReg ); |
| 192 | 192 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return int |
| 198 | 198 | */ |
| 199 | - public function getCreationTimestamp() : int { |
|
| 199 | + public function getCreationTimestamp () : int { |
|
| 200 | 200 | return $this->wiki->getPageCreationTS( $this->title ); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return int |
| 207 | 207 | */ |
| 208 | - public function getEndTimestamp() : int { |
|
| 208 | + public function getEndTimestamp () : int { |
|
| 209 | 209 | if ( $this->isVote() ) { |
| 210 | 210 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
| 211 | 211 | [ , $hours, $day ] = $this->getMatch( $reg ); |
@@ -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( get_object_vars( $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,9 +205,9 @@ 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 | if ( !$sets ) { |
| 210 | - return (object)[]; |
|
| 210 | + return (object)[ ]; |
|
| 211 | 211 | } |
| 212 | 212 | // Use the first set as template |
| 213 | 213 | $ret = array_shift( $sets ); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param array|\stdClass $second |
| 226 | 226 | * @return array|\stdClass array |
| 227 | 227 | */ |
| 228 | - private function recursiveMerge( $first, $second ) { |
|
| 228 | + private function recursiveMerge ( $first, $second ) { |
|
| 229 | 229 | $ret = $first; |
| 230 | 230 | if ( is_array( $second ) ) { |
| 231 | 231 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @return array |
| 245 | 245 | */ |
| 246 | - protected function getHeaders() :array { |
|
| 246 | + protected function getHeaders () :array { |
|
| 247 | 247 | $ret = self::HEADERS; |
| 248 | 248 | if ( self::$cookiesToSet ) { |
| 249 | - $cookies = []; |
|
| 249 | + $cookies = [ ]; |
|
| 250 | 250 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 251 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 251 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 252 | 252 | } |
| 253 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 253 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 254 | 254 | } |
| 255 | 255 | return $ret; |
| 256 | 256 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param array $headers |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | - protected function buildHeadersString( array $headers ) : string { |
|
| 264 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 265 | 265 | $ret = ''; |
| 266 | 266 | foreach ( $headers as $header ) { |
| 267 | 267 | $ret .= "$header\r\n"; |
@@ -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\Task\Subtask; |
| 4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | - public function runInternal() : int { |
|
| 16 | + public function runInternal () : int { |
|
| 17 | 17 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 18 | 18 | |
| 19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @param PageRiconferma $page |
| 37 | 37 | */ |
| 38 | - protected function addVoteCloseText( PageRiconferma $page ) : void { |
|
| 38 | + protected function addVoteCloseText ( PageRiconferma $page ) : void { |
|
| 39 | 39 | $content = $page->getContent(); |
| 40 | 40 | $beforeReg = '!è necessario ottenere una maggioranza .+ votanti\.!u'; |
| 41 | 41 | $newContent = preg_replace( $beforeReg, '$0' . "\n" . $page->getOutcomeText(), $content ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param PageRiconferma $page |
| 51 | 51 | * @see CreatePages::updateBasePage() |
| 52 | 52 | */ |
| 53 | - protected function updateBasePage( PageRiconferma $page ) : void { |
|
| 53 | + protected function updateBasePage ( PageRiconferma $page ) : void { |
|
| 54 | 54 | $this->getLogger()->info( "Updating base page for $page" ); |
| 55 | 55 | |
| 56 | 56 | if ( $page->getNum() === 1 ) { |
@@ -62,8 +62,7 @@ discard block |
||
| 62 | 62 | $current = $basePage->getContent(); |
| 63 | 63 | |
| 64 | 64 | $outcomeText = ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) ? |
| 65 | - 'non riconfermato' : |
|
| 66 | - 'riconfermato'; |
|
| 65 | + 'non riconfermato' : 'riconfermato'; |
|
| 67 | 66 | $text = $page->isVote() ? "votazione di riconferma: $outcomeText" : 'riconferma tacita'; |
| 68 | 67 | |
| 69 | 68 | $newContent = preg_replace( '/^(votazione di )?riconferma in corso/m', $text, $current ); |
@@ -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 | |
@@ -15,15 +15,15 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @inheritDoc |
| 17 | 17 | */ |
| 18 | - protected function getSubtasksMap(): array { |
|
| 18 | + protected function getSubtasksMap (): array { |
|
| 19 | 19 | // Everything is done here. |
| 20 | - return []; |
|
| 20 | + return [ ]; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @inheritDoc |
| 25 | 25 | */ |
| 26 | - public function runInternal() : int { |
|
| 26 | + public function runInternal () : int { |
|
| 27 | 27 | $pages = $this->getDataProvider()->getOpenPages(); |
| 28 | 28 | |
| 29 | 29 | if ( !$pages ) { |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | * @param PageRiconferma[] $pages |
| 38 | 38 | * @return int a STATUS_* constant |
| 39 | 39 | */ |
| 40 | - protected function processPages( array $pages ) : int { |
|
| 41 | - $donePages = []; |
|
| 40 | + protected function processPages ( array $pages ) : int { |
|
| 41 | + $donePages = [ ]; |
|
| 42 | 42 | foreach ( $pages as $page ) { |
| 43 | 43 | if ( $page->hasOpposition() && !$page->isVote() ) { |
| 44 | 44 | $this->openVote( $page ); |
| 45 | 45 | $this->updateBasePage( $page ); |
| 46 | - $donePages[] = $page; |
|
| 46 | + $donePages[ ] = $page; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @param PageRiconferma $page |
| 63 | 63 | */ |
| 64 | - protected function openVote( PageRiconferma $page ) : void { |
|
| 64 | + protected function openVote ( PageRiconferma $page ) : void { |
|
| 65 | 65 | $this->getLogger()->info( "Starting vote on $page" ); |
| 66 | 66 | |
| 67 | 67 | $content = $page->getContent(); |
@@ -100,12 +100,12 @@ discard block |
||
| 100 | 100 | * @see SimpleUpdates::updateVotazioni() |
| 101 | 101 | * @see OpenUpdates::addToVotazioni() |
| 102 | 102 | */ |
| 103 | - protected function updateVotazioni( array $pages ) : void { |
|
| 103 | + protected function updateVotazioni ( array $pages ) : void { |
|
| 104 | 104 | $votePage = $this->getPage( $this->getOpt( 'vote-page-title' ) ); |
| 105 | 105 | |
| 106 | - $users = []; |
|
| 106 | + $users = [ ]; |
|
| 107 | 107 | foreach ( $pages as $page ) { |
| 108 | - $users[] = $this->getUser( $page->getUserName() ); |
|
| 108 | + $users[ ] = $this->getUser( $page->getUserName() ); |
|
| 109 | 109 | } |
| 110 | 110 | $usersReg = RegexUtils::regexFromArray( '!', ...$users ); |
| 111 | 111 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param PageRiconferma $page |
| 140 | 140 | * @see ClosePages::updateBasePage() |
| 141 | 141 | */ |
| 142 | - protected function updateBasePage( PageRiconferma $page ) : void { |
|
| 142 | + protected function updateBasePage ( PageRiconferma $page ) : void { |
|
| 143 | 143 | $this->getLogger()->info( "Updating base page for $page" ); |
| 144 | 144 | |
| 145 | 145 | if ( $page->getNum() === 1 ) { |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @see SimpleUpdates::updateNews() |
| 167 | 167 | * @see OpenUpdates::addToNews() |
| 168 | 168 | */ |
| 169 | - protected function updateNews( int $amount ) : void { |
|
| 169 | + protected function updateNews ( int $amount ) : void { |
|
| 170 | 170 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
| 171 | 171 | $newsPage = $this->getPage( $this->getOpt( 'news-page-title' ) ); |
| 172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | throw new TaskException( 'Param "voto" not found in news page' ); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $newTac = ( (int)$newsPage->getMatch( $regTac )[2] - $amount ) ?: ''; |
|
| 185 | - $newVot = ( (int)$newsPage->getMatch( $regVot )[2] + $amount ) ?: ''; |
|
| 184 | + $newTac = ( (int)$newsPage->getMatch( $regTac )[ 2 ] - $amount ) ?: ''; |
|
| 185 | + $newVot = ( (int)$newsPage->getMatch( $regVot )[ 2 ] + $amount ) ?: ''; |
|
| 186 | 186 | |
| 187 | 187 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
| 188 | 188 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |
@@ -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 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @throws MissingPageException |
| 91 | 91 | * @throws MissingSectionException |
| 92 | 92 | */ |
| 93 | - public function getPageContent( string $title, int $section = null ) : string { |
|
| 93 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
| 94 | 94 | $fullTitle = $this->pagePrefix . $title; |
| 95 | 95 | $msg = "Retrieving content of $fullTitle" . ( $section !== null ? ", section $section" : '' ); |
| 96 | 96 | $this->logger->info( $msg ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | ]; |
| 104 | 104 | |
| 105 | 105 | if ( $section !== null ) { |
| 106 | - $params['rvsection'] = $section; |
|
| 106 | + $params[ 'rvsection' ] = $section; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $req = $this->buildRequest( $params ); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | throw new MissingPageException( $title ); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $mainSlot = $page->revisions[0]->slots->main; |
|
| 116 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
| 117 | 117 | |
| 118 | 118 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
| 119 | 119 | throw new MissingSectionException( $title, $section ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param array $params |
| 128 | 128 | * @throws EditException |
| 129 | 129 | */ |
| 130 | - public function editPage( array $params ) : void { |
|
| 130 | + public function editPage ( array $params ) : void { |
|
| 131 | 131 | $this->login(); |
| 132 | 132 | |
| 133 | 133 | $params = [ |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ] + $params; |
| 137 | 137 | |
| 138 | 138 | if ( BOT_EDITS === true ) { |
| 139 | - $params['bot'] = 1; |
|
| 139 | + $params[ 'bot' ] = 1; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
| 155 | 155 | * @throws LoginException |
| 156 | 156 | */ |
| 157 | - public function login() : void { |
|
| 157 | + public function login () : void { |
|
| 158 | 158 | if ( $this->loginInfo === null ) { |
| 159 | 159 | throw new CannotLoginException( 'Missing login data' ); |
| 160 | 160 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | $this->loggedIn = true; |
| 186 | 186 | // Clear tokens cache |
| 187 | - $this->tokens = []; |
|
| 187 | + $this->tokens = [ ]; |
|
| 188 | 188 | $this->logger->info( 'Login succeeded' ); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @param string $type |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public function getToken( string $type ) : string { |
|
| 197 | + public function getToken ( string $type ) : string { |
|
| 198 | 198 | if ( !isset( $this->tokens[ $type ] ) ) { |
| 199 | 199 | $params = [ |
| 200 | 200 | 'action' => 'query', |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @param string $title |
| 218 | 218 | * @return int |
| 219 | 219 | */ |
| 220 | - public function getPageCreationTS( string $title ) : int { |
|
| 220 | + public function getPageCreationTS ( string $title ) : int { |
|
| 221 | 221 | $params = [ |
| 222 | 222 | 'action' => 'query', |
| 223 | 223 | 'prop' => 'revisions', |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $res = $this->buildRequest( $params )->execute(); |
| 232 | 232 | $data = $res->query->pages; |
| 233 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
| 233 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param string $title |
| 240 | 240 | * @param string $reason |
| 241 | 241 | */ |
| 242 | - public function protectPage( string $title, string $reason ) : void { |
|
| 242 | + public function protectPage ( string $title, string $reason ) : void { |
|
| 243 | 243 | $fullTitle = $this->pagePrefix . $title; |
| 244 | 244 | $this->logger->info( "Protecting page $fullTitle" ); |
| 245 | 245 | $this->login(); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param array $params |
| 262 | 262 | * @return RequestBase |
| 263 | 263 | */ |
| 264 | - private function buildRequest( array $params ) : RequestBase { |
|
| 264 | + private function buildRequest ( array $params ) : RequestBase { |
|
| 265 | 265 | return $this->requestFactory->newFromParams( $params ); |
| 266 | 266 | } |
| 267 | 267 | } |