| @@ -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 ); | 
| @@ -121,7 +121,7 @@ discard block | ||
| 121 | 121 | throw new MissingPageException( $title ); | 
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | - $mainSlot = $page->revisions[0]->slots->main; | |
| 124 | + $mainSlot = $page->revisions[ 0 ]->slots->main; | |
| 125 | 125 | |
| 126 | 126 |  		if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { | 
| 127 | 127 | throw new MissingSectionException( $title, $section ); | 
| @@ -135,7 +135,7 @@ discard block | ||
| 135 | 135 | * @param array $params | 
| 136 | 136 | * @throws EditException | 
| 137 | 137 | */ | 
| 138 | -	public function editPage( array $params ) : void { | |
| 138 | +	public function editPage ( array $params ) : void { | |
| 139 | 139 | $this->login(); | 
| 140 | 140 | |
| 141 | 141 | $params = [ | 
| @@ -144,7 +144,7 @@ discard block | ||
| 144 | 144 | ] + $params; | 
| 145 | 145 | |
| 146 | 146 |  		if ( BOT_EDITS === true ) { | 
| 147 | - $params['bot'] = 1; | |
| 147 | + $params[ 'bot' ] = 1; | |
| 148 | 148 | } | 
| 149 | 149 | |
| 150 | 150 | $res = $this->buildRequest( $params )->setPost()->execute(); | 
| @@ -162,7 +162,7 @@ discard block | ||
| 162 | 162 | * Login wrapper. Checks if we're already logged in and clears tokens cache | 
| 163 | 163 | * @throws LoginException | 
| 164 | 164 | */ | 
| 165 | -	public function login() : void { | |
| 165 | +	public function login () : void { | |
| 166 | 166 |  		if ( $this->loginInfo === null ) { | 
| 167 | 167 | throw new CannotLoginException( 'Missing login data' ); | 
| 168 | 168 | } | 
| @@ -192,7 +192,7 @@ discard block | ||
| 192 | 192 | |
| 193 | 193 | $this->loggedIn = true; | 
| 194 | 194 | // Clear tokens cache | 
| 195 | - $this->tokens = []; | |
| 195 | + $this->tokens = [ ]; | |
| 196 | 196 | $this->logger->info( 'Login succeeded' ); | 
| 197 | 197 | } | 
| 198 | 198 | |
| @@ -202,7 +202,7 @@ discard block | ||
| 202 | 202 | * @param string $type | 
| 203 | 203 | * @return string | 
| 204 | 204 | */ | 
| 205 | -	public function getToken( string $type ) : string { | |
| 205 | +	public function getToken ( string $type ) : string { | |
| 206 | 206 |  		if ( !isset( $this->tokens[ $type ] ) ) { | 
| 207 | 207 | $params = [ | 
| 208 | 208 | 'action' => 'query', | 
| @@ -225,7 +225,7 @@ discard block | ||
| 225 | 225 | * @param string $title | 
| 226 | 226 | * @return int | 
| 227 | 227 | */ | 
| 228 | -	public function getPageCreationTS( string $title ) : int { | |
| 228 | +	public function getPageCreationTS ( string $title ) : int { | |
| 229 | 229 | $params = [ | 
| 230 | 230 | 'action' => 'query', | 
| 231 | 231 | 'prop' => 'revisions', | 
| @@ -238,7 +238,7 @@ discard block | ||
| 238 | 238 | |
| 239 | 239 | $res = $this->buildRequest( $params )->execute(); | 
| 240 | 240 | $data = $res->query->pages; | 
| 241 | - return strtotime( reset( $data )->revisions[0]->timestamp ); | |
| 241 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); | |
| 242 | 242 | } | 
| 243 | 243 | |
| 244 | 244 | /** | 
| @@ -247,7 +247,7 @@ discard block | ||
| 247 | 247 | * @param string $title | 
| 248 | 248 | * @param string $reason | 
| 249 | 249 | */ | 
| 250 | -	public function protectPage( string $title, string $reason ) : void { | |
| 250 | +	public function protectPage ( string $title, string $reason ) : void { | |
| 251 | 251 | $fullTitle = $this->pagePrefix . $title; | 
| 252 | 252 | $this->logger->info( "Protecting page $fullTitle" ); | 
| 253 | 253 | $this->login(); | 
| @@ -270,7 +270,7 @@ discard block | ||
| 270 | 270 | * @param string $username | 
| 271 | 271 | * @param string $reason | 
| 272 | 272 | */ | 
| 273 | -	public function blockUser( string $username, string $reason ) : void { | |
| 273 | +	public function blockUser ( string $username, string $reason ) : void { | |
| 274 | 274 | $this->logger->info( "Blocking user $username" ); | 
| 275 | 275 | $this->login(); | 
| 276 | 276 | |
| @@ -296,7 +296,7 @@ discard block | ||
| 296 | 296 | * @param array $params | 
| 297 | 297 | * @return RequestBase | 
| 298 | 298 | */ | 
| 299 | -	private function buildRequest( array $params ) : RequestBase { | |
| 299 | +	private function buildRequest ( array $params ) : RequestBase { | |
| 300 | 300 | return $this->requestFactory->newFromParams( $params ); | 
| 301 | 301 | } | 
| 302 | 302 | } | 
| @@ -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 | |
| @@ -14,15 +14,15 @@ discard block | ||
| 14 | 14 | /** | 
| 15 | 15 | * @inheritDoc | 
| 16 | 16 | */ | 
| 17 | -	protected function getSubtasksMap(): array { | |
| 17 | +	protected function getSubtasksMap (): array { | |
| 18 | 18 | // Everything is done here. | 
| 19 | - return []; | |
| 19 | + return [ ]; | |
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | 22 | /** | 
| 23 | 23 | * @inheritDoc | 
| 24 | 24 | */ | 
| 25 | -	public function runInternal() : int { | |
| 25 | +	public function runInternal () : int { | |
| 26 | 26 | $pages = $this->getDataProvider()->getOpenPages(); | 
| 27 | 27 | |
| 28 | 28 |  		if ( !$pages ) { | 
| @@ -36,13 +36,13 @@ discard block | ||
| 36 | 36 | * @param PageRiconferma[] $pages | 
| 37 | 37 | * @return int a STATUS_* constant | 
| 38 | 38 | */ | 
| 39 | -	protected function processPages( array $pages ) : int { | |
| 40 | - $donePages = []; | |
| 39 | +	protected function processPages ( array $pages ) : int { | |
| 40 | + $donePages = [ ]; | |
| 41 | 41 |  		foreach ( $pages as $page ) { | 
| 42 | 42 |  			if ( $page->hasOpposition() && !$page->isVote() ) { | 
| 43 | 43 | $this->openVote( $page ); | 
| 44 | 44 | $this->updateBasePage( $page ); | 
| 45 | - $donePages[] = $page; | |
| 45 | + $donePages[ ] = $page; | |
| 46 | 46 | } | 
| 47 | 47 | } | 
| 48 | 48 | |
| @@ -60,7 +60,7 @@ discard block | ||
| 60 | 60 | * | 
| 61 | 61 | * @param PageRiconferma $page | 
| 62 | 62 | */ | 
| 63 | -	protected function openVote( PageRiconferma $page ) : void { | |
| 63 | +	protected function openVote ( PageRiconferma $page ) : void { | |
| 64 | 64 | $this->getLogger()->info( "Starting vote on $page" ); | 
| 65 | 65 | |
| 66 | 66 | $content = $page->getContent(); | 
| @@ -99,12 +99,12 @@ discard block | ||
| 99 | 99 | * @see SimpleUpdates::updateVotazioni() | 
| 100 | 100 | * @see OpenUpdates::addToVotazioni() | 
| 101 | 101 | */ | 
| 102 | -	protected function updateVotazioni( array $pages ) : void { | |
| 102 | +	protected function updateVotazioni ( array $pages ) : void { | |
| 103 | 103 | $votePage = $this->getPage( $this->getOpt( 'vote-page-title' ) ); | 
| 104 | 104 | |
| 105 | - $users = []; | |
| 105 | + $users = [ ]; | |
| 106 | 106 |  		foreach ( $pages as $page ) { | 
| 107 | - $users[] = $this->getUser( $page->getUserName() ); | |
| 107 | + $users[ ] = $this->getUser( $page->getUserName() ); | |
| 108 | 108 | } | 
| 109 | 109 | $usersReg = RegexUtils::regexFromArray( '!', ...$users ); | 
| 110 | 110 | |
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | * @param PageRiconferma $page | 
| 139 | 139 | * @see \BotRiconferme\Task\Subtask\ClosePages::updateBasePage() | 
| 140 | 140 | */ | 
| 141 | -	protected function updateBasePage( PageRiconferma $page ) : void { | |
| 141 | +	protected function updateBasePage ( PageRiconferma $page ) : void { | |
| 142 | 142 | $this->getLogger()->info( "Updating base page for $page" ); | 
| 143 | 143 | |
| 144 | 144 |  		if ( $page->getNum() === 1 ) { | 
| @@ -165,7 +165,7 @@ discard block | ||
| 165 | 165 | * @see SimpleUpdates::updateNews() | 
| 166 | 166 | * @see OpenUpdates::addToNews() | 
| 167 | 167 | */ | 
| 168 | -	protected function updateNews( int $amount ) : void { | |
| 168 | +	protected function updateNews ( int $amount ) : void { | |
| 169 | 169 | $this->getLogger()->info( "Turning $amount pages into votes" ); | 
| 170 | 170 | $newsPage = $this->getPage( $this->getOpt( 'news-page-title' ) ); | 
| 171 | 171 | |
| @@ -180,8 +180,8 @@ discard block | ||
| 180 | 180 | throw new TaskException( 'Param "voto" not found in news page' ); | 
| 181 | 181 | } | 
| 182 | 182 | |
| 183 | - $newTac = ( (int)$newsPage->getMatch( $regTac )[2] - $amount ) ?: ''; | |
| 184 | - $newVot = ( (int)$newsPage->getMatch( $regVot )[2] + $amount ) ?: ''; | |
| 183 | + $newTac = ( (int)$newsPage->getMatch( $regTac )[ 2 ] - $amount ) ?: ''; | |
| 184 | + $newVot = ( (int)$newsPage->getMatch( $regVot )[ 2 ] + $amount ) ?: ''; | |
| 185 | 185 | |
| 186 | 186 |  		$newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); | 
| 187 | 187 |  		$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; | 
| 4 | 4 | |
| @@ -65,14 +65,14 @@ discard block | ||
| 65 | 65 | /** | 
| 66 | 66 | * @return bool | 
| 67 | 67 | */ | 
| 68 | -	public static function isCLI() : bool { | |
| 68 | +	public static function isCLI () : bool { | |
| 69 | 69 | return PHP_SAPI === 'cli'; | 
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | 72 | /** | 
| 73 | 73 | * Populate options and check for required ones | 
| 74 | 74 | */ | 
| 75 | -	public function __construct() { | |
| 75 | +	public function __construct () { | |
| 76 | 76 | $opts = getopt( self::SHORT_OPTS, self::LONG_OPTS ); | 
| 77 | 77 | $this->checkRequiredOpts( $opts ); | 
| 78 | 78 | $this->checkConflictingOpts( $opts ); | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | /** | 
| 84 | 84 | * @param array $opts | 
| 85 | 85 | */ | 
| 86 | -	private function checkRequiredOpts( array $opts ) : void { | |
| 86 | +	private function checkRequiredOpts ( array $opts ) : void { | |
| 87 | 87 | $missingOpts = array_diff( self::REQUIRED_OPTS, array_keys( $opts ) ); | 
| 88 | 88 |  		if ( $missingOpts ) { | 
| 89 | 89 | exit( 'Required options missing: ' . implode( ', ', $missingOpts ) ); | 
| @@ -105,13 +105,13 @@ discard block | ||
| 105 | 105 | /** | 
| 106 | 106 | * @param array $opts | 
| 107 | 107 | */ | 
| 108 | -	private function checkConflictingOpts( array $opts ) : void { | |
| 109 | - $this->checkNotBothSet( $opts,'password', 'use-password-file' ); | |
| 108 | +	private function checkConflictingOpts ( array $opts ) : void { | |
| 109 | + $this->checkNotBothSet( $opts, 'password', 'use-password-file' ); | |
| 110 | 110 |  		if ( array_key_exists( 'use-password-file', $opts ) && !file_exists( self::PASSWORD_FILE ) ) { | 
| 111 | 111 |  			exit( 'Please create the password file (' . self::PASSWORD_FILE . ')' ); | 
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | - $this->checkNotBothSet( $opts,'private-password', 'use-private-password-file' ); | |
| 114 | + $this->checkNotBothSet( $opts, 'private-password', 'use-private-password-file' ); | |
| 115 | 115 |  		if ( array_key_exists( 'use-private-password-file', $opts ) && !file_exists( self::PRIVATE_PASSWORD_FILE ) ) { | 
| 116 | 116 |  			exit( 'Please create the private-password file (' . self::PRIVATE_PASSWORD_FILE . ')' ); | 
| 117 | 117 | } | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 | * @param string $first | 
| 127 | 127 | * @param string $second | 
| 128 | 128 | */ | 
| 129 | -	private function checkNotBothSet( array $opts, string $first, string $second ) : void { | |
| 129 | +	private function checkNotBothSet ( array $opts, string $first, string $second ) : void { | |
| 130 | 130 |  		if ( array_key_exists( $first, $opts ) && array_key_exists( $second, $opts ) ) { | 
| 131 | 131 | exit( "Can only use one of '$first' and '$second'" ); | 
| 132 | 132 | } | 
| @@ -135,16 +135,16 @@ discard block | ||
| 135 | 135 | /** | 
| 136 | 136 | * @param array &$opts | 
| 137 | 137 | */ | 
| 138 | -	private function canonicalize( array &$opts ) : void { | |
| 138 | +	private function canonicalize ( array &$opts ) : void { | |
| 139 | 139 |  		if ( array_key_exists( 'use-password-file', $opts ) ) { | 
| 140 | 140 | $pw = trim( file_get_contents( self::PASSWORD_FILE ) ); | 
| 141 | - $opts['password'] = $pw; | |
| 142 | - unset( $opts['use-password-file'] ); | |
| 141 | + $opts[ 'password' ] = $pw; | |
| 142 | + unset( $opts[ 'use-password-file' ] ); | |
| 143 | 143 | } | 
| 144 | 144 |  		if ( array_key_exists( 'use-private-password-file', $opts ) ) { | 
| 145 | 145 | $pw = trim( file_get_contents( self::PRIVATE_PASSWORD_FILE ) ); | 
| 146 | - $opts['private-password'] = $pw; | |
| 147 | - unset( $opts['use-private-password-file'] ); | |
| 146 | + $opts[ 'private-password' ] = $pw; | |
| 147 | + unset( $opts[ 'use-private-password-file' ] ); | |
| 148 | 148 | } | 
| 149 | 149 | } | 
| 150 | 150 | |
| @@ -153,14 +153,14 @@ discard block | ||
| 153 | 153 | * @param mixed|null $default | 
| 154 | 154 | * @return mixed | 
| 155 | 155 | */ | 
| 156 | -	public function getOpt( string $opt, $default = null ) { | |
| 157 | - return $this->opts[$opt] ?? $default; | |
| 156 | +	public function getOpt ( string $opt, $default = null ) { | |
| 157 | + return $this->opts[ $opt ] ?? $default; | |
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | 160 | /** | 
| 161 | 161 | * @return array Either [ 'task' => taskname ] or [ 'subtask' => subtaskname ] | 
| 162 | 162 | */ | 
| 163 | -	public function getTaskOpt() : array { | |
| 163 | +	public function getTaskOpt () : array { | |
| 164 | 164 | return array_intersect_key( | 
| 165 | 165 | $this->opts, | 
| 166 | 166 | [ 'task' => true, 'subtask' => true ] | 
| @@ -170,7 +170,7 @@ discard block | ||
| 170 | 170 | /** | 
| 171 | 171 | * @return string|null | 
| 172 | 172 | */ | 
| 173 | -	public function getURL() : ?string { | |
| 173 | +	public function getURL () : ?string { | |
| 174 | 174 | return $this->getOpt( 'force-url' ); | 
| 175 | 175 | } | 
| 176 | 176 | } |