@@ -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 | |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | /** @var array[] */ |
| 16 | 16 | private $allUsers; |
| 17 | 17 | /** @var PageRiconferma[] */ |
| 18 | - private $createdPages = []; |
|
| 18 | + private $createdPages = [ ]; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Get the full content of the JSON users list |
| 22 | 22 | * |
| 23 | 23 | * @return array[] |
| 24 | 24 | */ |
| 25 | - public function getUsersList() : array { |
|
| 25 | + public function getUsersList () : array { |
|
| 26 | 26 | if ( $this->allUsers === null ) { |
| 27 | 27 | $this->getLogger()->debug( 'Retrieving users list' ); |
| 28 | 28 | $this->allUsers = PageBotList::get()->getAdminsList(); |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return array[] |
| 38 | 38 | */ |
| 39 | - public function getUsersToProcess() : array { |
|
| 39 | + public function getUsersToProcess () : array { |
|
| 40 | 40 | if ( $this->processUsers === null ) { |
| 41 | - $this->processUsers = []; |
|
| 41 | + $this->processUsers = [ ]; |
|
| 42 | 42 | foreach ( $this->getUsersList() as $user => $groups ) { |
| 43 | 43 | $timestamp = $this->getValidTimestamp( $groups ); |
| 44 | 44 | |
@@ -60,17 +60,15 @@ discard block |
||
| 60 | 60 | * @param array $groups |
| 61 | 61 | * @return int |
| 62 | 62 | */ |
| 63 | - private function getValidTimestamp( array $groups ) : int { |
|
| 64 | - if ( isset( $groups['override'] ) ) { |
|
| 65 | - return $groups['override']; |
|
| 63 | + private function getValidTimestamp ( array $groups ) : int { |
|
| 64 | + if ( isset( $groups[ 'override' ] ) ) { |
|
| 65 | + return $groups[ 'override' ]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $checkuser = isset( $groups[ 'checkuser' ] ) ? |
| 69 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 70 | - 0; |
|
| 69 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 71 | 70 | $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
| 72 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 73 | - 0; |
|
| 71 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 74 | 72 | |
| 75 | 73 | $timestamp = max( $bureaucrat, $checkuser ); |
| 76 | 74 | if ( $timestamp === 0 ) { |
@@ -84,7 +82,7 @@ discard block |
||
| 84 | 82 | * |
| 85 | 83 | * @return PageRiconferma[] |
| 86 | 84 | */ |
| 87 | - public function getOpenPages() : array { |
|
| 85 | + public function getOpenPages () : array { |
|
| 88 | 86 | static $list = null; |
| 89 | 87 | if ( $list === null ) { |
| 90 | 88 | $baseTitle = $this->getConfig()->get( 'main-page-title' ); |
@@ -98,10 +96,10 @@ discard block |
||
| 98 | 96 | |
| 99 | 97 | $res = RequestBase::newFromParams( $params )->execute(); |
| 100 | 98 | $pages = $res->query->pages; |
| 101 | - $list = []; |
|
| 99 | + $list = [ ]; |
|
| 102 | 100 | foreach ( reset( $pages )->templates as $page ) { |
| 103 | 101 | if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) { |
| 104 | - $list[] = new PageRiconferma( $page->title ); |
|
| 102 | + $list[ ] = new PageRiconferma( $page->title ); |
|
| 105 | 103 | } |
| 106 | 104 | } |
| 107 | 105 | } |
@@ -114,14 +112,14 @@ discard block |
||
| 114 | 112 | * |
| 115 | 113 | * @return PageRiconferma[] |
| 116 | 114 | */ |
| 117 | - public function getPagesToClose() : array { |
|
| 115 | + public function getPagesToClose () : array { |
|
| 118 | 116 | static $list = null; |
| 119 | 117 | if ( $list === null ) { |
| 120 | 118 | $allPages = $this->getOpenPages(); |
| 121 | - $list = []; |
|
| 119 | + $list = [ ]; |
|
| 122 | 120 | foreach ( $allPages as $page ) { |
| 123 | 121 | if ( time() > $page->getEndTimestamp() ) { |
| 124 | - $list[] = $page; |
|
| 122 | + $list[ ] = $page; |
|
| 125 | 123 | } |
| 126 | 124 | } |
| 127 | 125 | } |
@@ -133,21 +131,21 @@ discard block |
||
| 133 | 131 | * |
| 134 | 132 | * @param string $name |
| 135 | 133 | */ |
| 136 | - public function removeUser( string $name ) { |
|
| 134 | + public function removeUser ( string $name ) { |
|
| 137 | 135 | unset( $this->processUsers[ $name ] ); |
| 138 | 136 | } |
| 139 | 137 | |
| 140 | 138 | /** |
| 141 | 139 | * @return PageRiconferma[] |
| 142 | 140 | */ |
| 143 | - public function getCreatedPages() : array { |
|
| 141 | + public function getCreatedPages () : array { |
|
| 144 | 142 | return $this->createdPages; |
| 145 | 143 | } |
| 146 | 144 | |
| 147 | 145 | /** |
| 148 | 146 | * @param PageRiconferma $page |
| 149 | 147 | */ |
| 150 | - public function addCreatedPages( PageRiconferma $page ) { |
|
| 151 | - $this->createdPages[] = $page; |
|
| 148 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
| 149 | + $this->createdPages[ ] = $page; |
|
| 152 | 150 | } |
| 153 | 151 | } |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @param string $key |
| 16 | 16 | */ |
| 17 | - public function __construct( string $key ) { |
|
| 17 | + public function __construct ( string $key ) { |
|
| 18 | 18 | $this->key = $key; |
| 19 | 19 | $this->value = Config::getInstance()->getWikiMessage( $key ); |
| 20 | 20 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param array $args |
| 24 | 24 | * @return self |
| 25 | 25 | */ |
| 26 | - public function params( array $args ) : self { |
|
| 26 | + public function params ( array $args ) : self { |
|
| 27 | 27 | $this->value = strtr( $this->value, $args ); |
| 28 | 28 | return $this; |
| 29 | 29 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function text() : string { |
|
| 34 | + public function text () : string { |
|
| 35 | 35 | $this->parsePlurals(); |
| 36 | 36 | return $this->value; |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * Replace {{$plur|<amount>|sing|plur}} |
| 41 | 41 | */ |
| 42 | - protected function parsePlurals() { |
|
| 42 | + protected function parsePlurals () { |
|
| 43 | 43 | $reg = '!\{\{$plur|(?P<amount>\d+)|(?P<sing>[^}|]+)|(?P<plur>[^|}]+)}}!'; |
| 44 | 44 | |
| 45 | 45 | if ( preg_match( $reg, $this->value ) === false ) { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $this->value = preg_replace_callback( |
| 49 | 49 | $reg, |
| 50 | 50 | function ( $matches ) { |
| 51 | - return intval( $matches['amount'] ) > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
| 51 | + return intval( $matches[ 'amount' ] ) > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
| 52 | 52 | }, |
| 53 | 53 | $this->value |
| 54 | 54 | ); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param int $timestamp |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
| 63 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
| 64 | 64 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 65 | 65 | $timeString = strftime( '%e %B alle %R', $timestamp ); |
| 66 | 66 | // Remove the left space if day has a single digit |
@@ -78,16 +78,16 @@ discard block |
||
| 78 | 78 | * @return int |
| 79 | 79 | * @todo Is there a better way? |
| 80 | 80 | */ |
| 81 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
| 81 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
| 82 | 82 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
| 83 | 83 | $bits = strptime( $timeString, '%e %m %Y alle %H:%M' ); |
| 84 | 84 | $timestamp = mktime( |
| 85 | - $bits['tm_hour'], |
|
| 86 | - $bits['tm_min'], |
|
| 85 | + $bits[ 'tm_hour' ], |
|
| 86 | + $bits[ 'tm_min' ], |
|
| 87 | 87 | 0, |
| 88 | - $bits['tm_mon'] + 1, |
|
| 89 | - $bits['tm_mday'], |
|
| 90 | - $bits['tm_year'] + 1900 |
|
| 88 | + $bits[ 'tm_mon' ] + 1, |
|
| 89 | + $bits[ 'tm_mday' ], |
|
| 90 | + $bits[ 'tm_year' ] + 1900 |
|
| 91 | 91 | ); |
| 92 | 92 | setlocale( LC_TIME, $oldLoc ); |
| 93 | 93 | |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | * @param string $emptyText |
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 105 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
| 106 | 106 | if ( count( $data ) > 1 ) { |
| 107 | 107 | $last = array_pop( $data ); |
| 108 | 108 | $ret = implode( ', ', $data ) . " e $last"; |
| 109 | 109 | } elseif ( $data ) { |
| 110 | - $ret = $data[0]; |
|
| 110 | + $ret = $data[ 0 ]; |
|
| 111 | 111 | } else { |
| 112 | 112 | $ret = $emptyText; |
| 113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | return $ret; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function __toString() { |
|
| 118 | + public function __toString () { |
|
| 119 | 119 | return $this->text(); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -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 | $this->botList = $this->getDataProvider()->getUsersList(); |
| 33 | 33 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | /** |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - protected function getActualAdmins() : array { |
|
| 59 | + protected function getActualAdmins () : array { |
|
| 60 | 60 | $this->getLogger()->debug( 'Retrieving admins - API' ); |
| 61 | 61 | $params = [ |
| 62 | 62 | 'action' => 'query', |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @param \stdClass $data |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 78 | - $ret = []; |
|
| 77 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 78 | + $ret = [ ]; |
|
| 79 | 79 | $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
| 80 | 80 | foreach ( $data->query->allusers as $u ) { |
| 81 | 81 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return array[] |
| 94 | 94 | */ |
| 95 | - protected function getMissingGroups() : array { |
|
| 96 | - $missing = []; |
|
| 95 | + protected function getMissingGroups () : array { |
|
| 96 | + $missing = [ ]; |
|
| 97 | 97 | foreach ( $this->actualList as $adm => $groups ) { |
| 98 | - $groupsList = []; |
|
| 98 | + $groupsList = [ ]; |
|
| 99 | 99 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 100 | 100 | $groupsList = $groups; |
| 101 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 101 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 102 | 102 | // Only some groups are missing |
| 103 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 103 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | foreach ( $groupsList as $group ) { |
| 107 | 107 | try { |
| 108 | 108 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 109 | 109 | } catch ( TaskException $e ) { |
| 110 | - $this->errors[] = $e->getMessage(); |
|
| 110 | + $this->errors[ ] = $e->getMessage(); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return string |
| 123 | 123 | * @throws TaskException |
| 124 | 124 | */ |
| 125 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 125 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 126 | 126 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 127 | 127 | |
| 128 | 128 | $url = DEFAULT_URL; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $group |
| 158 | 158 | * @return string|null |
| 159 | 159 | */ |
| 160 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 160 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 161 | 161 | $ts = null; |
| 162 | 162 | foreach ( $data->query->logevents as $entry ) { |
| 163 | 163 | if ( !isset( $entry->params ) ) { |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return array[] |
| 181 | 181 | */ |
| 182 | - protected function getExtraGroups() : array { |
|
| 183 | - $extra = []; |
|
| 182 | + protected function getExtraGroups () : array { |
|
| 183 | + $extra = [ ]; |
|
| 184 | 184 | foreach ( $this->botList as $name => $groups ) { |
| 185 | 185 | $trueGroups = array_diff_key( $groups, [ 'override' => true ] ); |
| 186 | 186 | if ( !isset( $this->actualList[ $name ] ) ) { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @param array[] $extra |
| 200 | 200 | * @return array[] |
| 201 | 201 | */ |
| 202 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 202 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 203 | 203 | $newContent = $this->botList; |
| 204 | 204 | foreach ( $newContent as $user => $groups ) { |
| 205 | 205 | if ( isset( $missing[ $user ] ) ) { |