@@ -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,16 +14,16 @@ discard block |
||
| 14 | 14 | /** @var array[] */ |
| 15 | 15 | private $processUsers; |
| 16 | 16 | /** @var PageRiconferma[] */ |
| 17 | - private $createdPages = []; |
|
| 17 | + private $createdPages = [ ]; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Get a list of users to execute tasks on. |
| 21 | 21 | * |
| 22 | 22 | * @return array[] |
| 23 | 23 | */ |
| 24 | - public function getUsersToProcess() : array { |
|
| 24 | + public function getUsersToProcess () : array { |
|
| 25 | 25 | if ( $this->processUsers === null ) { |
| 26 | - $this->processUsers = []; |
|
| 26 | + $this->processUsers = [ ]; |
|
| 27 | 27 | foreach ( PageBotList::get()->getAdminsList() as $user => $groups ) { |
| 28 | 28 | if ( array_intersect_key( $groups, [ 'override-perm', 'override' ] ) ) { |
| 29 | 29 | // A one-time override takes precedence |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return PageRiconferma[] |
| 53 | 53 | */ |
| 54 | - public function getOpenPages() : array { |
|
| 54 | + public function getOpenPages () : array { |
|
| 55 | 55 | static $list = null; |
| 56 | 56 | if ( $list === null ) { |
| 57 | 57 | $mainTitle = $this->getConfig()->get( 'main-page-title' ); |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
| 67 | 67 | $reg = ( new Page( $mainTitle ) )->getRegex(); |
| 68 | - $list = []; |
|
| 68 | + $list = [ ]; |
|
| 69 | 69 | foreach ( reset( $pages )->templates as $page ) { |
| 70 | 70 | if ( preg_match( "!$reg\/[^\/]+\/\d!", $page->title ) ) { |
| 71 | - $list[] = new PageRiconferma( $page->title ); |
|
| 71 | + $list[ ] = new PageRiconferma( $page->title ); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return PageRiconferma[] |
| 83 | 83 | */ |
| 84 | - public function getPagesToClose() : array { |
|
| 84 | + public function getPagesToClose () : array { |
|
| 85 | 85 | static $list = null; |
| 86 | 86 | if ( $list === null ) { |
| 87 | 87 | $allPages = $this->getOpenPages(); |
| 88 | - $list = []; |
|
| 88 | + $list = [ ]; |
|
| 89 | 89 | foreach ( $allPages as $page ) { |
| 90 | 90 | if ( time() > $page->getEndTimestamp() ) { |
| 91 | - $list[] = $page; |
|
| 91 | + $list[ ] = $page; |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @param string $name |
| 102 | 102 | */ |
| 103 | - public function removeUser( string $name ) { |
|
| 103 | + public function removeUser ( string $name ) { |
|
| 104 | 104 | unset( $this->processUsers[ $name ] ); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return PageRiconferma[] |
| 109 | 109 | */ |
| 110 | - public function getCreatedPages() : array { |
|
| 110 | + public function getCreatedPages () : array { |
|
| 111 | 111 | return $this->createdPages; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * @param PageRiconferma $page |
| 116 | 116 | */ |
| 117 | - public function addCreatedPages( PageRiconferma $page ) { |
|
| 118 | - $this->createdPages[] = $page; |
|
| 117 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
| 118 | + $this->createdPages[ ] = $page; |
|
| 119 | 119 | } |
| 120 | 120 | } |
@@ -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 = PageBotList::get()->getAdminsList(); |
| 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 | // These are not groups |
| 186 | 186 | unset( $groups[ 'override' ], $groups[ 'override-perm' ] ); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @param array[] $extra |
| 201 | 201 | * @return array[] |
| 202 | 202 | */ |
| 203 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 203 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 204 | 204 | $newContent = $this->botList; |
| 205 | 205 | foreach ( $newContent as $user => $groups ) { |
| 206 | 206 | if ( isset( $missing[ $user ] ) ) { |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * @param array[] $newContent |
| 226 | 226 | * @return array[] |
| 227 | 227 | */ |
| 228 | - protected function removeOverrides( array $newContent ) : array { |
|
| 229 | - $removed = []; |
|
| 228 | + protected function removeOverrides ( array $newContent ) : array { |
|
| 229 | + $removed = [ ]; |
|
| 230 | 230 | foreach ( $newContent as $user => $groups ) { |
| 231 | 231 | $ts = PageBotList::getValidTimestamp( $groups ); |
| 232 | 232 | if ( date( 'd/m', $ts ) === date( 'd/m', strtotime( '- 1 days' ) ) && |
| 233 | - isset( $newContent[ $user ]['override'] ) |
|
| 233 | + isset( $newContent[ $user ][ 'override' ] ) |
|
| 234 | 234 | ) { |
| 235 | 235 | unset( $newContent[ $user ][ 'override' ] ); |
| 236 | - $removed[] = $user; |
|
| 236 | + $removed[ ] = $user; |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
@@ -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 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @private Use self::get() |
| 13 | 13 | */ |
| 14 | - public function __construct() { |
|
| 14 | + public function __construct () { |
|
| 15 | 15 | parent::__construct( Config::getInstance()->get( 'list-title' ) ); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return self |
| 22 | 22 | */ |
| 23 | - public static function get() : self { |
|
| 23 | + public static function get () : self { |
|
| 24 | 24 | static $instance = null; |
| 25 | 25 | if ( $instance === null ) { |
| 26 | 26 | $instance = new self; |
@@ -34,17 +34,15 @@ discard block |
||
| 34 | 34 | * @param array $groups |
| 35 | 35 | * @return int |
| 36 | 36 | */ |
| 37 | - public static function getValidTimestamp( array $groups ): int { |
|
| 38 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
| 39 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
| 40 | - 0; |
|
| 41 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
| 42 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
| 43 | - 0; |
|
| 37 | + public static function getValidTimestamp ( array $groups ): int { |
|
| 38 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 39 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 40 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 41 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 44 | 42 | |
| 45 | 43 | $timestamp = max( $bureaucrat, $checkuser ); |
| 46 | 44 | if ( $timestamp === 0 ) { |
| 47 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
| 45 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 48 | 46 | } |
| 49 | 47 | return $timestamp; |
| 50 | 48 | } |
@@ -54,7 +52,7 @@ discard block |
||
| 54 | 52 | * |
| 55 | 53 | * @return array[] |
| 56 | 54 | */ |
| 57 | - public function getAdminsList() : array { |
|
| 55 | + public function getAdminsList () : array { |
|
| 58 | 56 | return json_decode( $this->getContent(), true ); |
| 59 | 57 | } |
| 60 | 58 | } |