| @@ -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 ); | 
| @@ -135,7 +135,7 @@ discard block | ||
| 135 | 135 | * @phan-param array<int|string|bool> $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()->executeSingle(); | 
| @@ -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', | 
| @@ -222,7 +222,7 @@ discard block | ||
| 222 | 222 | * @param string $title | 
| 223 | 223 | * @return int | 
| 224 | 224 | */ | 
| 225 | -	public function getPageCreationTS( string $title ) : int { | |
| 225 | +	public function getPageCreationTS ( string $title ) : int { | |
| 226 | 226 | $params = [ | 
| 227 | 227 | 'action' => 'query', | 
| 228 | 228 | 'prop' => 'revisions', | 
| @@ -234,7 +234,7 @@ discard block | ||
| 234 | 234 | ]; | 
| 235 | 235 | |
| 236 | 236 | $page = $this->buildRequest( $params )->executeAsQuery()->current(); | 
| 237 | - return strtotime( $page->revisions[0]->timestamp ); | |
| 237 | + return strtotime( $page->revisions[ 0 ]->timestamp ); | |
| 238 | 238 | } | 
| 239 | 239 | |
| 240 | 240 | /** | 
| @@ -243,7 +243,7 @@ discard block | ||
| 243 | 243 | * @param string $title | 
| 244 | 244 | * @param string $reason | 
| 245 | 245 | */ | 
| 246 | -	public function protectPage( string $title, string $reason ) : void { | |
| 246 | +	public function protectPage ( string $title, string $reason ) : void { | |
| 247 | 247 | $fullTitle = $this->pagePrefix . $title; | 
| 248 | 248 | $this->logger->info( "Protecting page $fullTitle" ); | 
| 249 | 249 | $this->login(); | 
| @@ -266,7 +266,7 @@ discard block | ||
| 266 | 266 | * @param string $username | 
| 267 | 267 | * @param string $reason | 
| 268 | 268 | */ | 
| 269 | -	public function blockUser( string $username, string $reason ) : void { | |
| 269 | +	public function blockUser ( string $username, string $reason ) : void { | |
| 270 | 270 | $this->logger->info( "Blocking user $username" ); | 
| 271 | 271 | $this->login(); | 
| 272 | 272 | |
| @@ -293,7 +293,7 @@ discard block | ||
| 293 | 293 | * @phan-param array<int|string|bool> $params | 
| 294 | 294 | * @return RequestBase | 
| 295 | 295 | */ | 
| 296 | -	private function buildRequest( array $params ) : RequestBase { | |
| 296 | +	private function buildRequest ( array $params ) : RequestBase { | |
| 297 | 297 | return $this->requestFactory->newFromParams( $params ); | 
| 298 | 298 | } | 
| 299 | 299 | } | 
| @@ -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 | |
| @@ -19,7 +19,7 @@ discard block | ||
| 19 | 19 | * @param string $listTitle | 
| 20 | 20 | * @param Wiki $wiki | 
| 21 | 21 | */ | 
| 22 | -	public function __construct( string $listTitle, Wiki $wiki ) { | |
| 22 | +	public function __construct ( string $listTitle, Wiki $wiki ) { | |
| 23 | 23 | parent::__construct( $listTitle, $wiki ); | 
| 24 | 24 | } | 
| 25 | 25 | |
| @@ -30,7 +30,7 @@ discard block | ||
| 30 | 30 | * @param string $listTitle | 
| 31 | 31 | * @return self | 
| 32 | 32 | */ | 
| 33 | -	public static function get( Wiki $wiki, string $listTitle ) : self { | |
| 33 | +	public static function get ( Wiki $wiki, string $listTitle ) : self { | |
| 34 | 34 | static $instance = null; | 
| 35 | 35 |  		if ( $instance === null ) { | 
| 36 | 36 | $instance = new self( $listTitle, $wiki ); | 
| @@ -42,7 +42,7 @@ discard block | ||
| 42 | 42 | * @param UserInfo $ui | 
| 43 | 43 | * @return int|null | 
| 44 | 44 | */ | 
| 45 | -	public function getOverrideTimestamp( UserInfo $ui ) : ?int { | |
| 45 | +	public function getOverrideTimestamp ( UserInfo $ui ) : ?int { | |
| 46 | 46 | $info = $ui->getInfo(); | 
| 47 | 47 |  		if ( !array_intersect_key( $info, [ 'override-perm' => true, 'override' => true ] ) ) { | 
| 48 | 48 | return null; | 
| @@ -50,9 +50,9 @@ discard block | ||
| 50 | 50 | |
| 51 | 51 | // A one-time override takes precedence | 
| 52 | 52 |  		if ( array_key_exists( 'override', $info ) ) { | 
| 53 | - $date = $info['override']; | |
| 53 | + $date = $info[ 'override' ]; | |
| 54 | 54 |  		} else { | 
| 55 | - $date = $info['override-prem'] . '/' . date( 'Y' ); | |
| 55 | + $date = $info[ 'override-prem' ] . '/' . date( 'Y' ); | |
| 56 | 56 | } | 
| 57 | 57 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); | 
| 58 | 58 | } | 
| @@ -64,17 +64,17 @@ discard block | ||
| 64 | 64 | * @return int | 
| 65 | 65 | * @suppress PhanPluginComparisonObjectOrdering DateTime objects can be compared (phan issue #2907) | 
| 66 | 66 | */ | 
| 67 | -	public function getNextTimestamp( string $user ) : int { | |
| 67 | +	public function getNextTimestamp ( string $user ) : int { | |
| 68 | 68 | $userInfo = $this->getUserInfo( $user )->getInfo(); | 
| 69 | -		if ( isset( $userInfo['override-perm'] ) ) { | |
| 69 | +		if ( isset( $userInfo[ 'override-perm' ] ) ) { | |
| 70 | 70 | $date = \DateTime::createFromFormat( | 
| 71 | 71 | 'd/m/Y', | 
| 72 | - $userInfo['override-perm'] . '/' . date( 'Y' ) | |
| 72 | + $userInfo[ 'override-perm' ] . '/' . date( 'Y' ) | |
| 73 | 73 | ); | 
| 74 | 74 |  		} else { | 
| 75 | 75 | $date = null; | 
| 76 | -			if ( isset( $userInfo['override'] ) ) { | |
| 77 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); | |
| 76 | +			if ( isset( $userInfo[ 'override' ] ) ) { | |
| 77 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); | |
| 78 | 78 | } | 
| 79 | 79 |  			if ( !$date || $date <= new \DateTime ) { | 
| 80 | 80 | $ts = self::getValidFlagTimestamp( $userInfo ); | 
| @@ -94,17 +94,15 @@ discard block | ||
| 94 | 94 | * @param string[] $groups | 
| 95 | 95 | * @return int | 
| 96 | 96 | */ | 
| 97 | -	public static function getValidFlagTimestamp( array $groups ): int { | |
| 98 | - $checkuser = isset( $groups['checkuser'] ) ? | |
| 99 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : | |
| 100 | - 0; | |
| 101 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? | |
| 102 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : | |
| 103 | - 0; | |
| 97 | +	public static function getValidFlagTimestamp ( array $groups ): int { | |
| 98 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? | |
| 99 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; | |
| 100 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? | |
| 101 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; | |
| 104 | 102 | |
| 105 | 103 | $timestamp = max( $bureaucrat, $checkuser ); | 
| 106 | 104 |  		if ( $timestamp === 0 ) { | 
| 107 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); | |
| 105 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); | |
| 108 | 106 | } | 
| 109 | 107 | return $timestamp; | 
| 110 | 108 | } | 
| @@ -118,14 +116,14 @@ discard block | ||
| 118 | 116 | * @param string[] $groups | 
| 119 | 117 | * @return bool | 
| 120 | 118 | */ | 
| 121 | -	public static function isOverrideExpired( array $groups ) : bool { | |
| 122 | -		if ( !isset( $groups['override'] ) ) { | |
| 119 | +	public static function isOverrideExpired ( array $groups ) : bool { | |
| 120 | +		if ( !isset( $groups[ 'override' ] ) ) { | |
| 123 | 121 | return false; | 
| 124 | 122 | } | 
| 125 | 123 | |
| 126 | 124 | $flagTS = self::getValidFlagTimestamp( $groups ); | 
| 127 | 125 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); | 
| 128 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); | |
| 126 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); | |
| 129 | 127 | $delay = 60 * 60 * 24 * 3; | 
| 130 | 128 | |
| 131 | 129 | return time() > $usualTS + $delay && time() > $overrideTS + $delay; | 
| @@ -136,9 +134,9 @@ discard block | ||
| 136 | 134 | * | 
| 137 | 135 | * @return UserInfo[] | 
| 138 | 136 | */ | 
| 139 | -	public function getAdminsList() : array { | |
| 137 | +	public function getAdminsList () : array { | |
| 140 | 138 |  		if ( $this->adminsList === null ) { | 
| 141 | - $this->adminsList = []; | |
| 139 | + $this->adminsList = [ ]; | |
| 142 | 140 |  			foreach ( $this->getDecodedContent() as $user => $info ) { | 
| 143 | 141 | $this->adminsList[ $user ] = new UserInfo( $user, $info ); | 
| 144 | 142 | } | 
| @@ -150,8 +148,8 @@ discard block | ||
| 150 | 148 | * @param string $user | 
| 151 | 149 | * @return UserInfo | 
| 152 | 150 | */ | 
| 153 | -	public function getUserInfo( string $user ) : UserInfo { | |
| 154 | - return $this->getAdminsList()[$user]; | |
| 151 | +	public function getUserInfo ( string $user ) : UserInfo { | |
| 152 | + return $this->getAdminsList()[ $user ]; | |
| 155 | 153 | } | 
| 156 | 154 | |
| 157 | 155 | /** | 
| @@ -159,7 +157,7 @@ discard block | ||
| 159 | 157 | * | 
| 160 | 158 | * @return string[][] | 
| 161 | 159 | */ | 
| 162 | -	public function getDecodedContent() : array { | |
| 160 | +	public function getDecodedContent () : array { | |
| 163 | 161 | return json_decode( $this->getContent(), true ); | 
| 164 | 162 | } | 
| 165 | 163 | } | 
| @@ -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 | } | 
| @@ -53,18 +53,18 @@ discard block | ||
| 53 | 53 | * @phan-param array<int|string|bool> $params | 
| 54 | 54 | * @throws \LogicException | 
| 55 | 55 | */ | 
| 56 | -	public function edit( array $params ) : void { | |
| 56 | +	public function edit ( array $params ) : void { | |
| 57 | 57 | $params = [ | 
| 58 | 58 | 'title' => $this->getTitle() | 
| 59 | 59 | ] + $params; | 
| 60 | 60 | |
| 61 | 61 | $this->wiki->editPage( $params ); | 
| 62 | -		if ( isset( $params['text'] ) ) { | |
| 63 | - $this->content = $params['text']; | |
| 64 | -		} elseif ( isset( $params['appendtext'] ) ) { | |
| 65 | - $this->content .= $params['appendtext']; | |
| 66 | -		} elseif ( isset( $params['prependtext'] ) ) { | |
| 67 | - $this->content = $params['prependtext'] . $this->content; | |
| 62 | +		if ( isset( $params[ 'text' ] ) ) { | |
| 63 | + $this->content = $params[ 'text' ]; | |
| 64 | +		} elseif ( isset( $params[ 'appendtext' ] ) ) { | |
| 65 | + $this->content .= $params[ 'appendtext' ]; | |
| 66 | +		} elseif ( isset( $params[ 'prependtext' ] ) ) { | |
| 67 | + $this->content = $params[ 'prependtext' ] . $this->content; | |
| 68 | 68 |  		} else { | 
| 69 | 69 | throw new \LogicException( | 
| 70 | 70 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) | 
| @@ -77,7 +77,7 @@ discard block | ||
| 77 | 77 | * | 
| 78 | 78 | * @return bool | 
| 79 | 79 | */ | 
| 80 | -	public function exists() : bool { | |
| 80 | +	public function exists () : bool { | |
| 81 | 81 | $pages = $this->wiki->getRequestFactory()->newFromParams( [ | 
| 82 | 82 | 'action' => 'query', | 
| 83 | 83 | 'titles' => $this->getTitle() | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 | * @param string $regex | 
| 92 | 92 | * @return bool | 
| 93 | 93 | */ | 
| 94 | -	public function matches( string $regex ) : bool { | |
| 94 | +	public function matches ( string $regex ) : bool { | |
| 95 | 95 | return (bool)preg_match( $regex, $this->getContent() ); | 
| 96 | 96 | } | 
| 97 | 97 | |
| @@ -103,8 +103,8 @@ discard block | ||
| 103 | 103 | * @return string[] | 
| 104 | 104 | * @throws MissingMatchException | 
| 105 | 105 | */ | 
| 106 | -	public function getMatch( string $regex ) : array { | |
| 107 | - $ret = []; | |
| 106 | +	public function getMatch ( string $regex ) : array { | |
| 107 | + $ret = [ ]; | |
| 108 | 108 |  		if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { | 
| 109 | 109 | throw new MissingMatchException( "The content of $this does not match the given regex $regex" ); | 
| 110 | 110 | } | 
| @@ -116,7 +116,7 @@ discard block | ||
| 116 | 116 | * | 
| 117 | 117 | * @inheritDoc | 
| 118 | 118 | */ | 
| 119 | -	public function getRegex( string $delimiter = '/' ) : string { | |
| 119 | +	public function getRegex ( string $delimiter = '/' ) : string { | |
| 120 | 120 | return str_replace( ' ', '[ _]', preg_quote( $this->title, $delimiter ) ); | 
| 121 | 121 | } | 
| 122 | 122 | |
| @@ -125,7 +125,7 @@ discard block | ||
| 125 | 125 | * | 
| 126 | 126 | * @return string | 
| 127 | 127 | */ | 
| 128 | -	public function __toString() : string { | |
| 128 | +	public function __toString () : string { | |
| 129 | 129 | return $this->getTitle(); | 
| 130 | 130 | } | 
| 131 | 131 | } | 
| @@ -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 int[] 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\Wiki; | 
| 4 | 4 | |
| @@ -22,7 +22,7 @@ discard block | ||
| 22 | 22 | * @param UserInfo $ui | 
| 23 | 23 | * @param Wiki $wiki | 
| 24 | 24 | */ | 
| 25 | -	public function __construct( UserInfo $ui, Wiki $wiki ) { | |
| 25 | +	public function __construct ( UserInfo $ui, Wiki $wiki ) { | |
| 26 | 26 | $this->wiki = $wiki; | 
| 27 | 27 | $this->name = $ui->getName(); | 
| 28 | 28 | $this->ui = $ui; | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | /** | 
| 32 | 32 | * @return string | 
| 33 | 33 | */ | 
| 34 | -	public function getName() : string { | |
| 34 | +	public function getName () : string { | |
| 35 | 35 | return $this->name; | 
| 36 | 36 | } | 
| 37 | 37 | |
| @@ -40,7 +40,7 @@ discard block | ||
| 40 | 40 | * | 
| 41 | 41 | * @return string[] | 
| 42 | 42 | */ | 
| 43 | -	public function getGroups() : array { | |
| 43 | +	public function getGroups () : array { | |
| 44 | 44 | return $this->ui->extractGroups(); | 
| 45 | 45 | } | 
| 46 | 46 | |
| @@ -49,7 +49,7 @@ discard block | ||
| 49 | 49 | * | 
| 50 | 50 | * @return string[] [ group => date ] | 
| 51 | 51 | */ | 
| 52 | -	public function getGroupsWithDates() : array { | |
| 52 | +	public function getGroupsWithDates () : array { | |
| 53 | 53 | return $this->ui->extractGroupsWithDates(); | 
| 54 | 54 | } | 
| 55 | 55 | |
| @@ -59,7 +59,7 @@ discard block | ||
| 59 | 59 | * @param string $groupName | 
| 60 | 60 | * @return bool | 
| 61 | 61 | */ | 
| 62 | -	public function inGroup( string $groupName ) : bool { | |
| 62 | +	public function inGroup ( string $groupName ) : bool { | |
| 63 | 63 | return in_array( $groupName, $this->getGroups(), true ); | 
| 64 | 64 | } | 
| 65 | 65 | |
| @@ -68,9 +68,9 @@ discard block | ||
| 68 | 68 | * | 
| 69 | 69 | * @inheritDoc | 
| 70 | 70 | */ | 
| 71 | -	public function getRegex( string $delimiter = '/' ) : string { | |
| 71 | +	public function getRegex ( string $delimiter = '/' ) : string { | |
| 72 | 72 | $bits = $this->getAliases(); | 
| 73 | - $bits[] = $this->name; | |
| 73 | + $bits[ ] = $this->name; | |
| 74 | 74 |  		$regexify = static function ( string $el ) use ( $delimiter ) : string { | 
| 75 | 75 | return str_replace( ' ', '[ _]', preg_quote( $el, $delimiter ) ); | 
| 76 | 76 | }; | 
| @@ -82,14 +82,14 @@ discard block | ||
| 82 | 82 | * | 
| 83 | 83 | * @return string[] | 
| 84 | 84 | */ | 
| 85 | -	public function getAliases() : array { | |
| 85 | +	public function getAliases () : array { | |
| 86 | 86 | return $this->ui->getAliases(); | 
| 87 | 87 | } | 
| 88 | 88 | |
| 89 | 89 | /** | 
| 90 | 90 | * @return Page | 
| 91 | 91 | */ | 
| 92 | -	public function getTalkPage() : Page { | |
| 92 | +	public function getTalkPage () : Page { | |
| 93 | 93 |  		return new Page( "User talk:{$this->name}", $this->wiki ); | 
| 94 | 94 | } | 
| 95 | 95 | |
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | * Get the default base page, e.g. WP:A/Riconferma annuale/XXX | 
| 98 | 98 | * @return Page | 
| 99 | 99 | */ | 
| 100 | -	public function getBasePage() : Page { | |
| 100 | +	public function getBasePage () : Page { | |
| 101 | 101 | $prefix = Config::getInstance()->get( 'main-page-title' ); | 
| 102 | 102 | return new Page( "$prefix/$this", $this->wiki ); | 
| 103 | 103 | } | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | * @throws MissingPageException | 
| 110 | 110 | * @return Page | 
| 111 | 111 | */ | 
| 112 | -	public function getExistingBasePage() : Page { | |
| 112 | +	public function getExistingBasePage () : Page { | |
| 113 | 113 | $basePage = $this->getBasePage(); | 
| 114 | 114 |  		if ( !$basePage->exists() ) { | 
| 115 | 115 | $basePage = null; | 
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | /** | 
| 134 | 134 | * @return string | 
| 135 | 135 | */ | 
| 136 | -	public function __toString() { | |
| 136 | +	public function __toString () { | |
| 137 | 137 | return $this->name; | 
| 138 | 138 | } | 
| 139 | 139 | } | 
| @@ -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 | |
| @@ -21,7 +21,7 @@ discard block | ||
| 21 | 21 | * @param array $info | 
| 22 | 22 | * @phan-param array<string,string|string[]> $info | 
| 23 | 23 | */ | 
| 24 | -	public function __construct( string $name, array $info ) { | |
| 24 | +	public function __construct ( string $name, array $info ) { | |
| 25 | 25 | $this->name = $name; | 
| 26 | 26 | $this->info = $info; | 
| 27 | 27 | } | 
| @@ -29,7 +29,7 @@ discard block | ||
| 29 | 29 | /** | 
| 30 | 30 | * @return string | 
| 31 | 31 | */ | 
| 32 | -	public function getName() : string { | |
| 32 | +	public function getName () : string { | |
| 33 | 33 | return $this->name; | 
| 34 | 34 | } | 
| 35 | 35 | |
| @@ -37,28 +37,28 @@ discard block | ||
| 37 | 37 | * @return array | 
| 38 | 38 | * @phan-return array<string,string|string[]> | 
| 39 | 39 | */ | 
| 40 | -	public function getInfo() : array { | |
| 40 | +	public function getInfo () : array { | |
| 41 | 41 | return $this->info; | 
| 42 | 42 | } | 
| 43 | 43 | |
| 44 | 44 | /** | 
| 45 | 45 | * @return string[] | 
| 46 | 46 | */ | 
| 47 | -	public function extractGroups() : array { | |
| 47 | +	public function extractGroups () : array { | |
| 48 | 48 | return array_keys( $this->extractGroupsWithDates() ); | 
| 49 | 49 | } | 
| 50 | 50 | |
| 51 | 51 | /** | 
| 52 | 52 | * @return string[] | 
| 53 | 53 | */ | 
| 54 | -	public function extractGroupsWithDates() : array { | |
| 54 | +	public function extractGroupsWithDates () : array { | |
| 55 | 55 | return array_intersect_key( $this->getInfo(), array_fill_keys( self::GROUP_KEYS, 1 ) ); | 
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | 58 | /** | 
| 59 | 59 | * @return string[] | 
| 60 | 60 | */ | 
| 61 | -	public function getAliases() : array { | |
| 62 | - return $this->getInfo()['aliases'] ?? []; | |
| 61 | +	public function getAliases () : array { | |
| 62 | + return $this->getInfo()[ 'aliases' ] ?? [ ]; | |
| 63 | 63 | } | 
| 64 | 64 | } | 
| @@ -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(); | 
| @@ -55,7 +55,7 @@ discard block | ||
| 55 | 55 | * @return string[][] | 
| 56 | 56 | * @phan-return array<string,string[]> | 
| 57 | 57 | */ | 
| 58 | -	protected function getActualAdmins() : array { | |
| 58 | +	protected function getActualAdmins () : array { | |
| 59 | 59 | $params = [ | 
| 60 | 60 | 'action' => 'query', | 
| 61 | 61 | 'list' => 'allusers', | 
| @@ -73,8 +73,8 @@ discard block | ||
| 73 | 73 | * @return string[][] | 
| 74 | 74 | * @phan-return array<string,string[]> | 
| 75 | 75 | */ | 
| 76 | -	protected function extractAdmins( Generator $data ) : array { | |
| 77 | - $ret = []; | |
| 76 | +	protected function extractAdmins ( Generator $data ) : array { | |
| 77 | + $ret = [ ]; | |
| 78 | 78 | $blacklist = $this->getOpt( 'exclude-admins' ); | 
| 79 | 79 |  		foreach ( $data as $u ) { | 
| 80 | 80 |  			if ( in_array( $u->name, $blacklist, true ) ) { | 
| @@ -91,16 +91,16 @@ discard block | ||
| 91 | 91 | * | 
| 92 | 92 | * @return string[][] | 
| 93 | 93 | */ | 
| 94 | -	protected function getMissingGroups() : array { | |
| 95 | - $missing = []; | |
| 94 | +	protected function getMissingGroups () : array { | |
| 95 | + $missing = [ ]; | |
| 96 | 96 |  		foreach ( $this->actualList as $adm => $groups ) { | 
| 97 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); | |
| 97 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); | |
| 98 | 98 | |
| 99 | 99 |  			foreach ( $curMissing as $group ) { | 
| 100 | 100 |  				try { | 
| 101 | 101 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); | 
| 102 | 102 |  				} catch ( TaskException $e ) { | 
| 103 | - $this->errors[] = $e->getMessage(); | |
| 103 | + $this->errors[ ] = $e->getMessage(); | |
| 104 | 104 | } | 
| 105 | 105 | } | 
| 106 | 106 | } | 
| @@ -115,7 +115,7 @@ discard block | ||
| 115 | 115 | * @return string | 
| 116 | 116 | * @throws TaskException | 
| 117 | 117 | */ | 
| 118 | -	protected function getFlagDate( string $admin, string $group ) : string { | |
| 118 | +	protected function getFlagDate ( string $admin, string $group ) : string { | |
| 119 | 119 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); | 
| 120 | 120 | |
| 121 | 121 | $wiki = $this->getWiki(); | 
| @@ -150,7 +150,7 @@ discard block | ||
| 150 | 150 | * @param string $group | 
| 151 | 151 | * @return string|null | 
| 152 | 152 | */ | 
| 153 | -	private function extractTimestamp( Generator $data, string $group ) : ?string { | |
| 153 | +	private function extractTimestamp ( Generator $data, string $group ) : ?string { | |
| 154 | 154 | $ts = null; | 
| 155 | 155 |  		foreach ( $data as $entry ) { | 
| 156 | 156 | if ( | 
| @@ -169,8 +169,8 @@ discard block | ||
| 169 | 169 | * | 
| 170 | 170 | * @return string[][] | 
| 171 | 171 | */ | 
| 172 | -	protected function getExtraGroups() : array { | |
| 173 | - $extra = []; | |
| 172 | +	protected function getExtraGroups () : array { | |
| 173 | + $extra = [ ]; | |
| 174 | 174 |  		foreach ( $this->botList as $name => $groups ) { | 
| 175 | 175 | $groups = array_diff_key( $groups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ); | 
| 176 | 176 |  			if ( !isset( $this->actualList[ $name ] ) ) { | 
| @@ -186,7 +186,7 @@ discard block | ||
| 186 | 186 | * @param string[] $names | 
| 187 | 187 | * @return Generator | 
| 188 | 188 | */ | 
| 189 | -	private function getRenameEntries( array $names ) : Generator { | |
| 189 | +	private function getRenameEntries ( array $names ) : Generator { | |
| 190 | 190 |  		$titles = array_map( static function ( string $x ) : string { | 
| 191 | 191 | return "Utente:$x"; | 
| 192 | 192 | }, $names ); | 
| @@ -210,14 +210,14 @@ discard block | ||
| 210 | 210 | * @param string[] $names | 
| 211 | 211 | * @return string[] [ old_name => new_name ] | 
| 212 | 212 | */ | 
| 213 | -	protected function getRenamedUsers( array $names ) : array { | |
| 213 | +	protected function getRenamedUsers ( array $names ) : array { | |
| 214 | 214 |  		if ( !$names ) { | 
| 215 | - return []; | |
| 215 | + return [ ]; | |
| 216 | 216 | } | 
| 217 | 217 | $this->getLogger()->info( 'Checking rename for ' . implode( ', ', $names ) ); | 
| 218 | 218 | |
| 219 | 219 | $data = $this->getRenameEntries( $names ); | 
| 220 | - $ret = []; | |
| 220 | + $ret = [ ]; | |
| 221 | 221 |  		foreach ( $data as $entry ) { | 
| 222 | 222 | // 1 month is arbitrary | 
| 223 | 223 |  			if ( strtotime( $entry->timestamp ) > strtotime( '-1 month' ) ) { | 
| @@ -235,18 +235,18 @@ discard block | ||
| 235 | 235 | * @param string[][] &$newContent | 
| 236 | 236 | * @param string[][] $removed | 
| 237 | 237 | */ | 
| 238 | -	private function handleRenames( array &$newContent, array $removed ) : void { | |
| 238 | +	private function handleRenames ( array &$newContent, array $removed ) : void { | |
| 239 | 239 | $renameMap = $this->getRenamedUsers( array_keys( $removed ) ); | 
| 240 | 240 |  		foreach ( $removed as $oldName => $info ) { | 
| 241 | 241 | if ( | 
| 242 | 242 | array_key_exists( $oldName, $renameMap ) && | 
| 243 | - array_key_exists( $renameMap[$oldName], $newContent ) | |
| 243 | + array_key_exists( $renameMap[ $oldName ], $newContent ) | |
| 244 | 244 |  			) { | 
| 245 | 245 | // This user was renamed! Add this name as alias, if they're still listed | 
| 246 | 246 | $newName = $renameMap[ $oldName ]; | 
| 247 | 247 | $this->getLogger()->info( "Found rename $oldName -> $newName" ); | 
| 248 | - $aliases = array_unique( array_merge( $newContent[ $newName ]['aliases'], [ $oldName ] ) ); | |
| 249 | - $newContent[ $newName ]['aliases'] = $aliases; | |
| 248 | + $aliases = array_unique( array_merge( $newContent[ $newName ][ 'aliases' ], [ $oldName ] ) ); | |
| 249 | + $newContent[ $newName ][ 'aliases' ] = $aliases; | |
| 250 | 250 | // Transfer overrides to the new name. | 
| 251 | 251 | $overrides = array_diff_key( $info, [ 'override' => 1, 'override-perm' => 1 ] ); | 
| 252 | 252 | $newContent[ $newName ] = array_merge( $newContent[ $newName ], $overrides ); | 
| @@ -260,12 +260,12 @@ discard block | ||
| 260 | 260 | * @param string[][] $extra | 
| 261 | 261 | * @return string[][] Removed users | 
| 262 | 262 | */ | 
| 263 | - private function handleExtraAndMissing( | |
| 263 | + private function handleExtraAndMissing ( | |
| 264 | 264 | array &$newContent, | 
| 265 | 265 | array $missing, | 
| 266 | 266 | array $extra | 
| 267 | 267 |  	) : array { | 
| 268 | - $removed = []; | |
| 268 | + $removed = [ ]; | |
| 269 | 269 |  		foreach ( $newContent as $user => $groups ) { | 
| 270 | 270 |  			if ( isset( $missing[ $user ] ) ) { | 
| 271 | 271 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); | 
| @@ -275,7 +275,7 @@ discard block | ||
| 275 | 275 |  				if ( array_diff_key( $newGroups, array_fill_keys( PageBotList::NON_GROUP_KEYS, 1 ) ) ) { | 
| 276 | 276 | $newContent[ $user ] = $newGroups; | 
| 277 | 277 |  				} else { | 
| 278 | - $removed[$user] = $newContent[$user]; | |
| 278 | + $removed[ $user ] = $newContent[ $user ]; | |
| 279 | 279 | unset( $newContent[ $user ] ); | 
| 280 | 280 | } | 
| 281 | 281 | } | 
| @@ -292,7 +292,7 @@ discard block | ||
| 292 | 292 | * @param string[][] $extra | 
| 293 | 293 | * @return array[] | 
| 294 | 294 | */ | 
| 295 | -	protected function getNewContent( array $missing, array $extra ) : array { | |
| 295 | +	protected function getNewContent ( array $missing, array $extra ) : array { | |
| 296 | 296 | $newContent = $this->botList; | 
| 297 | 297 | |
| 298 | 298 | $removed = $this->handleExtraAndMissing( $newContent, $missing, $extra ); | 
| @@ -311,12 +311,12 @@ discard block | ||
| 311 | 311 | * | 
| 312 | 312 | * @param array[] &$newContent | 
| 313 | 313 | */ | 
| 314 | -	protected function removeOverrides( array &$newContent ) : void { | |
| 315 | - $removed = []; | |
| 314 | +	protected function removeOverrides ( array &$newContent ) : void { | |
| 315 | + $removed = [ ]; | |
| 316 | 316 |  		foreach ( $newContent as $user => $groups ) { | 
| 317 | 317 |  			if ( PageBotList::isOverrideExpired( $groups ) ) { | 
| 318 | 318 | unset( $newContent[ $user ][ 'override' ] ); | 
| 319 | - $removed[] = $user; | |
| 319 | + $removed[ ] = $user; | |
| 320 | 320 | } | 
| 321 | 321 | } | 
| 322 | 322 | |
| @@ -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 | |
| @@ -14,7 +14,7 @@ discard block | ||
| 14 | 14 | /** | 
| 15 | 15 | * @inheritDoc | 
| 16 | 16 | */ | 
| 17 | -	public function runInternal() : int { | |
| 17 | +	public function runInternal () : int { | |
| 18 | 18 | $pages = $this->getDataProvider()->getPagesToClose(); | 
| 19 | 19 | |
| 20 | 20 |  		if ( !$pages ) { | 
| @@ -36,15 +36,15 @@ discard block | ||
| 36 | 36 | * @param PageRiconferma[] $pages | 
| 37 | 37 | * @see OpenUpdates::addToVotazioni() | 
| 38 | 38 | */ | 
| 39 | -	protected function updateVotazioni( array $pages ) : void { | |
| 39 | +	protected function updateVotazioni ( array $pages ) : void { | |
| 40 | 40 | $this->getLogger()->info( | 
| 41 | 41 | 'Updating votazioni: ' . implode( ', ', $pages ) | 
| 42 | 42 | ); | 
| 43 | 43 | $votePage = $this->getPage( $this->getOpt( 'vote-page-title' ) ); | 
| 44 | 44 | |
| 45 | - $users = []; | |
| 45 | + $users = [ ]; | |
| 46 | 46 |  		foreach ( $pages as $page ) { | 
| 47 | - $users[] = $this->getUser( $page->getUserName() ); | |
| 47 | + $users[ ] = $this->getUser( $page->getUserName() ); | |
| 48 | 48 | } | 
| 49 | 49 | $usersReg = RegexUtils::regexFromArray( '!', ...$users ); | 
| 50 | 50 | |
| @@ -65,7 +65,7 @@ discard block | ||
| 65 | 65 | * @param PageRiconferma[] $pages | 
| 66 | 66 | * @see OpenUpdates::addToNews() | 
| 67 | 67 | */ | 
| 68 | -	protected function updateNews( array $pages ) : void { | |
| 68 | +	protected function updateNews ( array $pages ) : void { | |
| 69 | 69 | $simpleAmount = $voteAmount = 0; | 
| 70 | 70 |  		foreach ( $pages as $page ) { | 
| 71 | 71 |  			if ( $page->isVote() ) { | 
| @@ -85,8 +85,8 @@ discard block | ||
| 85 | 85 | $simpleMatches = $newsPage->getMatch( $simpleReg ); | 
| 86 | 86 | $voteMatches = $newsPage->getMatch( $voteReg ); | 
| 87 | 87 | |
| 88 | - $newSimp = ( (int)$simpleMatches[2] - $simpleAmount ) ?: ''; | |
| 89 | - $newVote = ( (int)$voteMatches[2] - $voteAmount ) ?: ''; | |
| 88 | + $newSimp = ( (int)$simpleMatches[ 2 ] - $simpleAmount ) ?: ''; | |
| 89 | + $newVote = ( (int)$voteMatches[ 2 ] - $voteAmount ) ?: ''; | |
| 90 | 90 |  		$newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); | 
| 91 | 91 |  		$newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); | 
| 92 | 92 | |
| @@ -104,12 +104,12 @@ discard block | ||
| 104 | 104 | * | 
| 105 | 105 | * @param bool[] $outcomes | 
| 106 | 106 | */ | 
| 107 | -	protected function updateAdminList( array $outcomes ) : void { | |
| 107 | +	protected function updateAdminList ( array $outcomes ) : void { | |
| 108 | 108 | $this->getLogger()->info( 'Updating admin list' ); | 
| 109 | 109 | $adminsPage = $this->getPage( $this->getOpt( 'admins-list-title' ) ); | 
| 110 | 110 | $newContent = $adminsPage->getContent(); | 
| 111 | 111 | |
| 112 | - $riconfNames = $removeNames = []; | |
| 112 | + $riconfNames = $removeNames = [ ]; | |
| 113 | 113 |  		foreach ( $outcomes as $username => $confirmed ) { | 
| 114 | 114 | $user = $this->getUser( $username ); | 
| 115 | 115 | $userReg = $user->getRegex( '!' ); | 
| @@ -124,10 +124,10 @@ discard block | ||
| 124 | 124 |  					'${1}{{subst:#timel:Ymd}}|' . $nextDate . '$2', | 
| 125 | 125 | $newContent | 
| 126 | 126 | ); | 
| 127 | - $riconfNames[] = $username; | |
| 127 | + $riconfNames[ ] = $username; | |
| 128 | 128 |  			} else { | 
| 129 | 129 | $newContent = preg_replace( $reg, '', $newContent ); | 
| 130 | - $removeNames[] = $username; | |
| 130 | + $removeNames[ ] = $username; | |
| 131 | 131 | } | 
| 132 | 132 | } | 
| 133 | 133 | |
| @@ -147,21 +147,21 @@ discard block | ||
| 147 | 147 | /** | 
| 148 | 148 | * @param bool[] $outcomes | 
| 149 | 149 | */ | 
| 150 | -	protected function updateCUList( array $outcomes ) : void { | |
| 150 | +	protected function updateCUList ( array $outcomes ) : void { | |
| 151 | 151 | $this->getLogger()->info( 'Updating CU list.' ); | 
| 152 | 152 | $cuList = $this->getPage( $this->getOpt( 'cu-list-title' ) ); | 
| 153 | 153 | $newContent = $cuList->getContent(); | 
| 154 | 154 | |
| 155 | - $riconfNames = $removeNames = []; | |
| 155 | + $riconfNames = $removeNames = [ ]; | |
| 156 | 156 |  		foreach ( $outcomes as $user => $confirmed ) { | 
| 157 | 157 | $userReg = $this->getUser( $user )->getRegex( '!' ); | 
| 158 | 158 |  			$reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; | 
| 159 | 159 |  			if ( $confirmed ) { | 
| 160 | 160 |  				$newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); | 
| 161 | - $riconfNames[] = $user; | |
| 161 | + $riconfNames[ ] = $user; | |
| 162 | 162 |  			} else { | 
| 163 | 163 | $newContent = preg_replace( $reg, '', $newContent ); | 
| 164 | - $removeNames[] = $user; | |
| 164 | + $removeNames[ ] = $user; | |
| 165 | 165 | } | 
| 166 | 166 | } | 
| 167 | 167 | |
| @@ -185,8 +185,8 @@ discard block | ||
| 185 | 185 | * @param PageRiconferma[] $pages | 
| 186 | 186 | * @return bool[] | 
| 187 | 187 | */ | 
| 188 | -	private function getGroupOutcomes( string $group, array $pages ) : array { | |
| 189 | - $ret = []; | |
| 188 | +	private function getGroupOutcomes ( string $group, array $pages ) : array { | |
| 189 | + $ret = [ ]; | |
| 190 | 190 |  		foreach ( $pages as $page ) { | 
| 191 | 191 | $user = $this->getUser( $page->getUserName() ); | 
| 192 | 192 |  			if ( $user->inGroup( $group ) ) { | 
| @@ -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 | |
| @@ -39,7 +39,7 @@ discard block | ||
| 39 | 39 | /** @var string */ | 
| 40 | 40 | protected $method = self::METHOD_GET; | 
| 41 | 41 | /** @var string[] */ | 
| 42 | - protected $newCookies = []; | |
| 42 | + protected $newCookies = [ ]; | |
| 43 | 43 | |
| 44 | 44 | /** | 
| 45 | 45 | * @private Use RequestFactory | 
| @@ -48,7 +48,7 @@ discard block | ||
| 48 | 48 | * @phan-param array<int|string|bool> $params | 
| 49 | 49 | * @param string $domain | 
| 50 | 50 | */ | 
| 51 | -	public function __construct( array $params, string $domain ) { | |
| 51 | +	public function __construct ( array $params, string $domain ) { | |
| 52 | 52 | $this->params = [ 'format' => 'json' ] + $params; | 
| 53 | 53 | $this->url = $domain; | 
| 54 | 54 | } | 
| @@ -58,7 +58,7 @@ discard block | ||
| 58 | 58 | * | 
| 59 | 59 | * @return self For chaining | 
| 60 | 60 | */ | 
| 61 | -	public function setPost() : self { | |
| 61 | +	public function setPost () : self { | |
| 62 | 62 | $this->method = self::METHOD_POST; | 
| 63 | 63 | return $this; | 
| 64 | 64 | } | 
| @@ -67,12 +67,12 @@ discard block | ||
| 67 | 67 | * Execute a query request | 
| 68 | 68 | * @return Generator | 
| 69 | 69 | */ | 
| 70 | -	public function executeAsQuery() : Generator { | |
| 71 | -		if ( ( $this->params['action'] ?? false ) !== 'query' ) { | |
| 70 | +	public function executeAsQuery () : Generator { | |
| 71 | +		if ( ( $this->params[ 'action' ] ?? false ) !== 'query' ) { | |
| 72 | 72 | throw new BadMethodCallException( 'Not an ApiQuery!' ); | 
| 73 | 73 | } | 
| 74 | 74 | // TODO Is this always correct? | 
| 75 | - $key = $this->params['list'] ?? 'pages'; | |
| 75 | + $key = $this->params[ 'list' ] ?? 'pages'; | |
| 76 | 76 | $curParams = $this->params; | 
| 77 | 77 | $lim = $this->parseLimit(); | 
| 78 | 78 |  		do { | 
| @@ -101,7 +101,7 @@ discard block | ||
| 101 | 101 | * Execute a request that doesn't need any continuation. | 
| 102 | 102 | * @return stdClass | 
| 103 | 103 | */ | 
| 104 | -	public function executeSingle() : stdClass { | |
| 104 | +	public function executeSingle () : stdClass { | |
| 105 | 105 | $curParams = $this->params; | 
| 106 | 106 | $res = $this->makeRequestInternal( $curParams ); | 
| 107 | 107 | $this->handleErrorAndWarnings( $res ); | 
| @@ -111,7 +111,7 @@ discard block | ||
| 111 | 111 | /** | 
| 112 | 112 | * @return int | 
| 113 | 113 | */ | 
| 114 | -	private function parseLimit() : int { | |
| 114 | +	private function parseLimit () : int { | |
| 115 | 115 |  		foreach ( $this->params as $name => $val ) { | 
| 116 | 116 |  			if ( substr( $name, -strlen( 'limit' ) ) === 'limit' ) { | 
| 117 | 117 | return $val === 'max' ? -1 : (int)$val; | 
| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 | * @param string $resKey | 
| 129 | 129 | * @return int|null | 
| 130 | 130 | */ | 
| 131 | -	private function countQueryResults( stdClass $res, string $resKey ) : ?int { | |
| 131 | +	private function countQueryResults ( stdClass $res, string $resKey ) : ?int { | |
| 132 | 132 |  		if ( !isset( $res->query->$resKey ) ) { | 
| 133 | 133 | return null; | 
| 134 | 134 | } | 
| @@ -156,9 +156,9 @@ discard block | ||
| 156 | 156 | * @phan-param array<int|string|bool> $params | 
| 157 | 157 | * @return stdClass | 
| 158 | 158 | */ | 
| 159 | -	private function makeRequestInternal( array $params ) : stdClass { | |
| 159 | +	private function makeRequestInternal ( array $params ) : stdClass { | |
| 160 | 160 |  		if ( $this->method === self::METHOD_POST ) { | 
| 161 | - $params['maxlag'] = self::MAXLAG; | |
| 161 | + $params[ 'maxlag' ] = self::MAXLAG; | |
| 162 | 162 | } | 
| 163 | 163 | $query = http_build_query( $params ); | 
| 164 | 164 | |
| @@ -174,17 +174,17 @@ discard block | ||
| 174 | 174 | * @param string $params | 
| 175 | 175 | * @return string | 
| 176 | 176 | */ | 
| 177 | - abstract protected function reallyMakeRequest( string $params ) : string; | |
| 177 | + abstract protected function reallyMakeRequest ( string $params ) : string; | |
| 178 | 178 | |
| 179 | 179 | /** | 
| 180 | 180 | * After a request, set cookies for the next ones | 
| 181 | 181 | * | 
| 182 | 182 | * @param string[] $cookies | 
| 183 | 183 | */ | 
| 184 | -	protected function setCookies( array $cookies ) : void { | |
| 184 | +	protected function setCookies ( array $cookies ) : void { | |
| 185 | 185 |  		foreach ( $cookies as $cookie ) { | 
| 186 | 186 | $bits = explode( ';', $cookie ); | 
| 187 | - [ $name, $value ] = explode( '=', $bits[0] ); | |
| 187 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); | |
| 188 | 188 | self::$cookiesToSet[ $name ] = $value; | 
| 189 | 189 | } | 
| 190 | 190 | } | 
| @@ -195,7 +195,7 @@ discard block | ||
| 195 | 195 | * @param stdClass $res | 
| 196 | 196 | * @return APIRequestException | 
| 197 | 197 | */ | 
| 198 | -	private function getException( stdClass $res ) : APIRequestException { | |
| 198 | +	private function getException ( stdClass $res ) : APIRequestException { | |
| 199 | 199 |  		switch ( $res->error->code ) { | 
| 200 | 200 | case 'missingtitle': | 
| 201 | 201 | $ex = new MissingPageException; | 
| @@ -221,7 +221,7 @@ discard block | ||
| 221 | 221 | * @param stdClass $res | 
| 222 | 222 | * @throws APIRequestException | 
| 223 | 223 | */ | 
| 224 | -	protected function handleErrorAndWarnings( stdClass $res ) : void { | |
| 224 | +	protected function handleErrorAndWarnings ( stdClass $res ) : void { | |
| 225 | 225 |  		if ( isset( $res->error ) ) { | 
| 226 | 226 | throw $this->getException( $res ); | 
| 227 | 227 | } | 
| @@ -237,14 +237,14 @@ discard block | ||
| 237 | 237 | * | 
| 238 | 238 | * @return string[] | 
| 239 | 239 | */ | 
| 240 | -	protected function getHeaders() : array { | |
| 240 | +	protected function getHeaders () : array { | |
| 241 | 241 | $ret = self::HEADERS; | 
| 242 | 242 |  		if ( self::$cookiesToSet ) { | 
| 243 | - $cookies = []; | |
| 243 | + $cookies = [ ]; | |
| 244 | 244 |  			foreach ( self::$cookiesToSet as $cname => $cval ) { | 
| 245 | - $cookies[] = trim( "$cname=$cval" ); | |
| 245 | + $cookies[ ] = trim( "$cname=$cval" ); | |
| 246 | 246 | } | 
| 247 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); | |
| 247 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); | |
| 248 | 248 | } | 
| 249 | 249 | return $ret; | 
| 250 | 250 | } | 
| @@ -255,7 +255,7 @@ discard block | ||
| 255 | 255 | * @param string[] $headers | 
| 256 | 256 | * @return string | 
| 257 | 257 | */ | 
| 258 | -	protected function buildHeadersString( array $headers ) : string { | |
| 258 | +	protected function buildHeadersString ( array $headers ) : string { | |
| 259 | 259 | $ret = ''; | 
| 260 | 260 |  		foreach ( $headers as $header ) { | 
| 261 | 261 | $ret .= "$header\r\n"; |