@@ -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 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @private Use self::get() |
| 16 | 16 | * @param Wiki $wiki |
| 17 | 17 | */ |
| 18 | - public function __construct( Wiki $wiki ) { |
|
| 18 | + public function __construct ( Wiki $wiki ) { |
|
| 19 | 19 | parent::__construct( Config::getInstance()->get( 'list-title' ), $wiki ); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param Wiki $wiki |
| 26 | 26 | * @return self |
| 27 | 27 | */ |
| 28 | - public static function get( Wiki $wiki ) : self { |
|
| 28 | + public static function get ( Wiki $wiki ) : self { |
|
| 29 | 29 | static $instance = null; |
| 30 | 30 | if ( $instance === null ) { |
| 31 | 31 | $instance = new self( $wiki ); |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | * @param string[] $groups |
| 38 | 38 | * @return int|null |
| 39 | 39 | */ |
| 40 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
| 40 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
| 41 | 41 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
| 42 | 42 | return null; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // A one-time override takes precedence |
| 46 | 46 | if ( array_key_exists( 'override', $groups ) ) { |
| 47 | - $date = $groups['override']; |
|
| 47 | + $date = $groups[ 'override' ]; |
|
| 48 | 48 | } else { |
| 49 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
| 49 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
| 50 | 50 | } |
| 51 | 51 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
| 52 | 52 | } |
@@ -57,17 +57,15 @@ discard block |
||
| 57 | 57 | * @param array $groups |
| 58 | 58 | * @return int |
| 59 | 59 | */ |
| 60 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
| 61 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
| 62 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
| 63 | - 0; |
|
| 64 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
| 65 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
| 66 | - 0; |
|
| 60 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
| 61 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 62 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 63 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 64 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 67 | 65 | |
| 68 | 66 | $timestamp = max( $bureaucrat, $checkuser ); |
| 69 | 67 | if ( $timestamp === 0 ) { |
| 70 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
| 68 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 71 | 69 | } |
| 72 | 70 | return $timestamp; |
| 73 | 71 | } |
@@ -77,17 +75,17 @@ discard block |
||
| 77 | 75 | * |
| 78 | 76 | * @return array[] |
| 79 | 77 | */ |
| 80 | - public function getAdminsList() : array { |
|
| 78 | + public function getAdminsList () : array { |
|
| 81 | 79 | return json_decode( $this->getContent(), true ); |
| 82 | 80 | } |
| 83 | 81 | |
| 84 | 82 | /** |
| 85 | 83 | * @inheritDoc |
| 86 | 84 | */ |
| 87 | - public function edit( array $params ) { |
|
| 85 | + public function edit ( array $params ) { |
|
| 88 | 86 | parent::edit( $params ); |
| 89 | 87 | if ( array_key_exists( 'text', $params ) ) { |
| 90 | - $this->content = $params['text']; |
|
| 88 | + $this->content = $params[ 'text' ]; |
|
| 91 | 89 | } |
| 92 | 90 | } |
| 93 | 91 | } |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @param string $name |
| 20 | 20 | * @param Wiki $wiki |
| 21 | 21 | */ |
| 22 | - public function __construct( string $name, Wiki $wiki ) { |
|
| 22 | + public function __construct ( string $name, Wiki $wiki ) { |
|
| 23 | 23 | parent::__construct( $wiki ); |
| 24 | 24 | $this->name = $name; |
| 25 | 25 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public function getName() : string { |
|
| 30 | + public function getName () : string { |
|
| 31 | 31 | return $this->name; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return string[] |
| 38 | 38 | */ |
| 39 | - public function getGroups() : array { |
|
| 39 | + public function getGroups () : array { |
|
| 40 | 40 | return array_keys( array_diff_key( $this->getUserInfo(), PageBotList::NON_GROUP_KEYS ) ); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string[] |
| 47 | 47 | */ |
| 48 | - public function getUserInfo() : array { |
|
| 48 | + public function getUserInfo () : array { |
|
| 49 | 49 | if ( $this->groups === null ) { |
| 50 | 50 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
| 51 | 51 | $this->groups = $usersList[ $this->name ]; |
@@ -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() ); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @inheritDoc |
| 70 | 70 | */ |
| 71 | - public function getRegex() : string { |
|
| 71 | + public function getRegex () : string { |
|
| 72 | 72 | return str_replace( ' ', '[ _]', preg_quote( $this->name ) ); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return string[] |
| 79 | 79 | */ |
| 80 | - public function getAliases() : array { |
|
| 80 | + public function getAliases () : array { |
|
| 81 | 81 | if ( $this->aliases === null ) { |
| 82 | 82 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
| 83 | 83 | $this->aliases = $usersList[ $this->name ]; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public function __toString() { |
|
| 91 | + public function __toString () { |
|
| 92 | 92 | return $this->name; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -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 | |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | /** @var string */ |
| 31 | 31 | protected $method = 'GET'; |
| 32 | 32 | /** @var string[] */ |
| 33 | - protected $newCookies = []; |
|
| 33 | + protected $newCookies = [ ]; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Use self::newFromParams, which will provide the right class to use |
| 37 | 37 | * |
| 38 | 38 | * @param array $params |
| 39 | 39 | */ |
| 40 | - protected function __construct( array $params ) { |
|
| 40 | + protected function __construct ( array $params ) { |
|
| 41 | 41 | $this->params = [ 'format' => 'json' ] + $params; |
| 42 | 42 | $this->url = DEFAULT_URL; |
| 43 | 43 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param array $params |
| 49 | 49 | * @return self |
| 50 | 50 | */ |
| 51 | - public static function newFromParams( array $params ) : self { |
|
| 51 | + public static function newFromParams ( array $params ) : self { |
|
| 52 | 52 | if ( extension_loaded( 'curl' ) ) { |
| 53 | 53 | $ret = new CurlRequest( $params ); |
| 54 | 54 | } else { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return self For chaining |
| 64 | 64 | */ |
| 65 | - public function setPost() : self { |
|
| 65 | + public function setPost () : self { |
|
| 66 | 66 | $this->method = 'POST'; |
| 67 | 67 | return $this; |
| 68 | 68 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string $url |
| 74 | 74 | * @return self for chaining |
| 75 | 75 | */ |
| 76 | - public function setUrl( string $url ) : self { |
|
| 76 | + public function setUrl ( string $url ) : self { |
|
| 77 | 77 | $this->url = $url; |
| 78 | 78 | return $this; |
| 79 | 79 | } |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * @todo Return an iterable object which automatically continues the query only if the last |
| 86 | 86 | * entry available is reached. |
| 87 | 87 | */ |
| 88 | - public function execute() : \stdClass { |
|
| 88 | + public function execute () : \stdClass { |
|
| 89 | 89 | $curParams = $this->params; |
| 90 | - $sets = []; |
|
| 90 | + $sets = [ ]; |
|
| 91 | 91 | do { |
| 92 | 92 | $res = $this->makeRequestInternal( $curParams ); |
| 93 | 93 | |
| 94 | 94 | $this->handleErrorAndWarnings( $res ); |
| 95 | - $sets[] = $res; |
|
| 95 | + $sets[ ] = $res; |
|
| 96 | 96 | |
| 97 | 97 | $finished = true; |
| 98 | 98 | if ( isset( $res->continue ) ) { |
@@ -110,9 +110,9 @@ discard block |
||
| 110 | 110 | * @param array $params |
| 111 | 111 | * @return \stdClass |
| 112 | 112 | */ |
| 113 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 113 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
| 114 | 114 | if ( $this->method === 'POST' ) { |
| 115 | - $params['maxlag'] = self::MAXLAG; |
|
| 115 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
| 116 | 116 | } |
| 117 | 117 | $params = http_build_query( $params ); |
| 118 | 118 | |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | * @param string $params |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 131 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * After a request, set cookies for the next ones |
| 135 | 135 | * |
| 136 | 136 | * @param array $cookies |
| 137 | 137 | */ |
| 138 | - protected function setCookies( array $cookies ) { |
|
| 138 | + protected function setCookies ( array $cookies ) { |
|
| 139 | 139 | foreach ( $cookies as $cookie ) { |
| 140 | 140 | $bits = explode( ';', $cookie ); |
| 141 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 141 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
| 142 | 142 | self::$cookiesToSet[ $name ] = $value; |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param \stdClass $res |
| 150 | 150 | * @return APIRequestException |
| 151 | 151 | */ |
| 152 | - private function getException( \stdClass $res ) : APIRequestException { |
|
| 152 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
| 153 | 153 | switch ( $res->error->code ) { |
| 154 | 154 | case 'missingtitle': |
| 155 | 155 | $ex = new MissingPageException; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @param \stdClass $res |
| 173 | 173 | * @throws APIRequestException |
| 174 | 174 | */ |
| 175 | - protected function handleErrorAndWarnings( \stdClass $res ) { |
|
| 175 | + protected function handleErrorAndWarnings ( \stdClass $res ) { |
|
| 176 | 176 | if ( isset( $res->error ) ) { |
| 177 | 177 | throw $this->getException( $res ); |
| 178 | 178 | } elseif ( isset( $res->warnings ) ) { |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param \stdClass[] $sets |
| 189 | 189 | * @return \stdClass |
| 190 | 190 | */ |
| 191 | - private function mergeSets( array $sets ) : \stdClass { |
|
| 191 | + private function mergeSets ( array $sets ) : \stdClass { |
|
| 192 | 192 | // Use the first set as template |
| 193 | 193 | $ret = array_shift( $sets ); |
| 194 | 194 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param array|\stdClass $second |
| 206 | 206 | * @return array|\stdClass array |
| 207 | 207 | */ |
| 208 | - private function recursiveMerge( $first, $second ) { |
|
| 208 | + private function recursiveMerge ( $first, $second ) { |
|
| 209 | 209 | $ret = $first; |
| 210 | 210 | if ( is_array( $second ) ) { |
| 211 | 211 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -223,14 +223,14 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return array |
| 225 | 225 | */ |
| 226 | - protected function getHeaders() :array { |
|
| 226 | + protected function getHeaders () :array { |
|
| 227 | 227 | $ret = self::HEADERS; |
| 228 | 228 | if ( self::$cookiesToSet ) { |
| 229 | - $cookies = []; |
|
| 229 | + $cookies = [ ]; |
|
| 230 | 230 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
| 231 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 231 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
| 232 | 232 | } |
| 233 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 233 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 234 | 234 | } |
| 235 | 235 | return $ret; |
| 236 | 236 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @param array $headers |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | - protected function buildHeadersString( array $headers ) : string { |
|
| 244 | + protected function buildHeadersString ( array $headers ) : string { |
|
| 245 | 245 | $ret = ''; |
| 246 | 246 | foreach ( $headers as $header ) { |
| 247 | 247 | $ret .= "$header\r\n"; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task\Subtask; |
| 4 | 4 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * @inheritDoc |
| 18 | 18 | */ |
| 19 | - public function runInternal() : int { |
|
| 19 | + public function runInternal () : int { |
|
| 20 | 20 | $pages = $this->getDataProvider()->getPagesToClose(); |
| 21 | 21 | |
| 22 | 22 | if ( !$pages ) { |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | * @param PageRiconferma[] $pages |
| 39 | 39 | * @see OpenUpdates::addToVotazioni() |
| 40 | 40 | */ |
| 41 | - protected function updateVotazioni( array $pages ) { |
|
| 41 | + protected function updateVotazioni ( array $pages ) { |
|
| 42 | 42 | $this->getLogger()->info( |
| 43 | 43 | 'Updating votazioni: ' . implode( ', ', $pages ) |
| 44 | 44 | ); |
| 45 | 45 | $votePage = $this->getPage( $this->getOpt( 'vote-page-title' ) ); |
| 46 | 46 | |
| 47 | - $users = []; |
|
| 47 | + $users = [ ]; |
|
| 48 | 48 | foreach ( $pages as $page ) { |
| 49 | - $users[] = $page->getUser(); |
|
| 49 | + $users[ ] = $page->getUser(); |
|
| 50 | 50 | } |
| 51 | 51 | $usersReg = Element::regexFromArray( $users ); |
| 52 | 52 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param array $pages |
| 68 | 68 | * @see OpenUpdates::addToNews() |
| 69 | 69 | */ |
| 70 | - protected function updateNews( array $pages ) { |
|
| 70 | + protected function updateNews ( array $pages ) { |
|
| 71 | 71 | $simpleAmount = $voteAmount = 0; |
| 72 | 72 | foreach ( $pages as $page ) { |
| 73 | 73 | if ( $page->isVote() ) { |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
| 88 | 88 | $voteMatches = $newsPage->getMatch( $voteReg ); |
| 89 | 89 | |
| 90 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
| 91 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
| 90 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
| 91 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
| 92 | 92 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); |
| 93 | 93 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
| 94 | 94 | |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param bool[] $outcomes |
| 108 | 108 | */ |
| 109 | - protected function updateAdminList( array $outcomes ) { |
|
| 109 | + protected function updateAdminList ( array $outcomes ) { |
|
| 110 | 110 | $this->getLogger()->info( 'Updating admin list' ); |
| 111 | 111 | $adminsPage = $this->getPage( $this->getOpt( 'admins-list-title' ) ); |
| 112 | 112 | $newContent = $adminsPage->getContent(); |
| 113 | 113 | |
| 114 | - $riconfNames = $removeNames = []; |
|
| 114 | + $riconfNames = $removeNames = [ ]; |
|
| 115 | 115 | foreach ( $outcomes as $username => $confirmed ) { |
| 116 | 116 | $user = new User( $username, $this->getWiki() ); |
| 117 | 117 | $userReg = $user->getRegex(); |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | '${1}' . date( 'Ymd' ) . '|' . $nextDate . '$2', |
| 124 | 124 | $newContent |
| 125 | 125 | ); |
| 126 | - $riconfNames[] = $username; |
|
| 126 | + $riconfNames[ ] = $username; |
|
| 127 | 127 | } else { |
| 128 | 128 | $newContent = preg_replace( $reg, '', $newContent ); |
| 129 | - $removeNames[] = $username; |
|
| 129 | + $removeNames[ ] = $username; |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | * @param User $user |
| 150 | 150 | * @return int |
| 151 | 151 | */ |
| 152 | - private function getNextTs( User $user ) : int { |
|
| 152 | + private function getNextTs ( User $user ) : int { |
|
| 153 | 153 | $userInfo = $user->getUserInfo(); |
| 154 | - if ( isset( $userInfo['override-perm'] ) ) { |
|
| 154 | + if ( isset( $userInfo[ 'override-perm' ] ) ) { |
|
| 155 | 155 | $date = \DateTime::createFromFormat( |
| 156 | 156 | 'd/m/Y', |
| 157 | - $userInfo['override-perm'] . '/' . date( 'Y' ) |
|
| 157 | + $userInfo[ 'override-perm' ] . '/' . date( 'Y' ) |
|
| 158 | 158 | ); |
| 159 | 159 | if ( $date < new \DateTime ) { |
| 160 | 160 | $date->modify( '+1 year' ); |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | } else { |
| 164 | 164 | $ts = PageBotList::getValidFlagTimestamp( $userInfo ); |
| 165 | 165 | $res = strtotime( date( 'Y', strtotime( '+1 year' ) ) . date( '-m-d', $ts ) ); |
| 166 | - if ( isset( $userInfo['override'] ) ) { |
|
| 167 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); |
|
| 166 | + if ( isset( $userInfo[ 'override' ] ) ) { |
|
| 167 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); |
|
| 168 | 168 | if ( $date > new \DateTime ) { |
| 169 | 169 | $res = $date->getTimestamp(); |
| 170 | 170 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | /** |
| 177 | 177 | * @param bool[] $outcomes |
| 178 | 178 | */ |
| 179 | - protected function updateCUList( array $outcomes ) { |
|
| 179 | + protected function updateCUList ( array $outcomes ) { |
|
| 180 | 180 | $this->getLogger()->info( 'Updating CU list.' ); |
| 181 | 181 | $cuList = $this->getPage( $this->getOpt( 'cu-list-title' ) ); |
| 182 | 182 | $newContent = $cuList->getContent(); |
| 183 | 183 | |
| 184 | - $riconfNames = $removeNames = []; |
|
| 184 | + $riconfNames = $removeNames = [ ]; |
|
| 185 | 185 | foreach ( $outcomes as $user => $confirmed ) { |
| 186 | 186 | $userReg = ( new User( $user, $this->getWiki() ) )->getRegex(); |
| 187 | 187 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
| 188 | 188 | if ( $confirmed ) { |
| 189 | 189 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
| 190 | - $riconfNames[] = $user; |
|
| 190 | + $riconfNames[ ] = $user; |
|
| 191 | 191 | } else { |
| 192 | 192 | $newContent = preg_replace( $reg, '', $newContent ); |
| 193 | - $removeNames[] = $user; |
|
| 193 | + $removeNames[ ] = $user; |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | * @param PageRiconferma[] $pages |
| 215 | 215 | * @return bool[] |
| 216 | 216 | */ |
| 217 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
| 218 | - $ret = []; |
|
| 217 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
| 218 | + $ret = [ ]; |
|
| 219 | 219 | foreach ( $pages as $page ) { |
| 220 | 220 | $user = $page->getUser(); |
| 221 | 221 | 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\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 = PageBotList::get( $this->getWiki() ); |
| 33 | 33 | $this->botList = $pageBotList->getAdminsList(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - protected function getActualAdmins() : array { |
|
| 57 | + protected function getActualAdmins () : array { |
|
| 58 | 58 | $params = [ |
| 59 | 59 | 'action' => 'query', |
| 60 | 60 | 'list' => 'allusers', |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param \stdClass $data |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 75 | - $ret = []; |
|
| 74 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 75 | + $ret = [ ]; |
|
| 76 | 76 | $blacklist = $this->getOpt( 'exclude-admins' ); |
| 77 | 77 | foreach ( $data->query->allusers as $u ) { |
| 78 | 78 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return array[] |
| 91 | 91 | */ |
| 92 | - protected function getMissingGroups() : array { |
|
| 93 | - $missing = []; |
|
| 92 | + protected function getMissingGroups () : array { |
|
| 93 | + $missing = [ ]; |
|
| 94 | 94 | foreach ( $this->actualList as $adm => $groups ) { |
| 95 | - $curMissing = array_diff( $groups, array_keys( $this->botList[$adm] ?? [] ) ); |
|
| 95 | + $curMissing = array_diff( $groups, array_keys( $this->botList[ $adm ] ?? [ ] ) ); |
|
| 96 | 96 | |
| 97 | 97 | foreach ( $curMissing as $group ) { |
| 98 | 98 | try { |
| 99 | 99 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 100 | 100 | } catch ( TaskException $e ) { |
| 101 | - $this->errors[] = $e->getMessage(); |
|
| 101 | + $this->errors[ ] = $e->getMessage(); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @return string |
| 114 | 114 | * @throws TaskException |
| 115 | 115 | */ |
| 116 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 116 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 117 | 117 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 118 | 118 | |
| 119 | 119 | $url = DEFAULT_URL; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param string $group |
| 150 | 150 | * @return string|null |
| 151 | 151 | */ |
| 152 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 152 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 153 | 153 | $ts = null; |
| 154 | 154 | foreach ( $data->query->logevents as $entry ) { |
| 155 | 155 | if ( isset( $entry->params ) ) { |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return array[] |
| 170 | 170 | */ |
| 171 | - protected function getExtraGroups() : array { |
|
| 172 | - $extra = []; |
|
| 171 | + protected function getExtraGroups () : array { |
|
| 172 | + $extra = [ ]; |
|
| 173 | 173 | foreach ( $this->botList as $name => $groups ) { |
| 174 | 174 | $groups = array_diff_key( $groups, PageBotList::NON_GROUP_KEYS ); |
| 175 | 175 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param string[] $names |
| 188 | 188 | * @return string[] [ new_name => old_name ] |
| 189 | 189 | */ |
| 190 | - protected function checkRenamedUsers( array $names ) : array { |
|
| 190 | + protected function checkRenamedUsers ( array $names ) : array { |
|
| 191 | 191 | $titles = array_map( function ( $x ) { |
| 192 | 192 | return "Utente:$x"; |
| 193 | 193 | }, $names ); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $data = RequestBase::newFromParams( $params )->execute(); |
| 205 | - $ret = []; |
|
| 205 | + $ret = [ ]; |
|
| 206 | 206 | foreach ( $data->query->logevents as $entry ) { |
| 207 | 207 | $time = strtotime( $entry->timestamp ); |
| 208 | 208 | // 1 month is arbitrary |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | * @param array[] $extra |
| 222 | 222 | * @return array[] |
| 223 | 223 | */ |
| 224 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 224 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 225 | 225 | $newContent = $this->botList; |
| 226 | 226 | $renameMap = $this->checkRenamedUsers( array_keys( $extra ) ); |
| 227 | - $removed = []; |
|
| 227 | + $removed = [ ]; |
|
| 228 | 228 | foreach ( $newContent as $user => $groups ) { |
| 229 | 229 | if ( isset( $missing[ $user ] ) ) { |
| 230 | 230 | $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $newContent[ $user ] = $newGroups; |
| 236 | 236 | } else { |
| 237 | 237 | unset( $newContent[ $user ] ); |
| 238 | - $removed[] = $user; |
|
| 238 | + $removed[ ] = $user; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -244,15 +244,15 @@ discard block |
||
| 244 | 244 | $newContent = array_filter( array_merge( $newContent, $missing ) ); |
| 245 | 245 | |
| 246 | 246 | foreach ( $removed as $oldName ) { |
| 247 | - if ( array_key_exists( $oldName, $renameMap ) && array_key_exists( $renameMap[$oldName], $newContent ) ) { |
|
| 247 | + if ( array_key_exists( $oldName, $renameMap ) && array_key_exists( $renameMap[ $oldName ], $newContent ) ) { |
|
| 248 | 248 | $newName = $renameMap[ $oldName ]; |
| 249 | 249 | // This user was renamed! Add this name as alias... If they're still listed! |
| 250 | 250 | if ( array_key_exists( 'aliases', $newContent[ $newName ] ) ) { |
| 251 | - if ( !in_array( $oldName, $newContent[ $newName ]['aliases'] ) ) { |
|
| 252 | - $newContent[ $newName ]['aliases'][] = $oldName; |
|
| 251 | + if ( !in_array( $oldName, $newContent[ $newName ][ 'aliases' ] ) ) { |
|
| 252 | + $newContent[ $newName ][ 'aliases' ][ ] = $oldName; |
|
| 253 | 253 | } |
| 254 | 254 | } else { |
| 255 | - $newContent[ $newName ]['aliases'] = [ $oldName ]; |
|
| 255 | + $newContent[ $newName ][ 'aliases' ] = [ $oldName ]; |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | } |
@@ -269,21 +269,21 @@ discard block |
||
| 269 | 269 | * @param array[] $newContent |
| 270 | 270 | * @return array[] |
| 271 | 271 | */ |
| 272 | - protected function removeOverrides( array $newContent ) : array { |
|
| 273 | - $removed = []; |
|
| 272 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 273 | + $removed = [ ]; |
|
| 274 | 274 | foreach ( $newContent as $user => $groups ) { |
| 275 | - if ( !isset( $groups['override'] ) ) { |
|
| 275 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 276 | 276 | continue; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $flagTS = PageBotList::getValidFlagTimestamp( $groups ); |
| 280 | 280 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 281 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 281 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 282 | 282 | $delay = 60 * 60 * 24 * 3; |
| 283 | 283 | |
| 284 | 284 | if ( time() > $usualTS + $delay && time() > $overrideTS + $delay ) { |
| 285 | 285 | unset( $newContent[ $user ][ 'override' ] ); |
| 286 | - $removed[] = $user; |
|
| 286 | + $removed[ ] = $user; |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |