@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Page; |
| 4 | 4 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | - public function getUser() : string { |
|
| 28 | - return explode( '/', $this->title )[2]; |
|
| 27 | + public function getUser () : string { |
|
| 28 | + return explode( '/', $this->title )[ 2 ]; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return int |
| 35 | 35 | */ |
| 36 | - public function getNum() : int { |
|
| 36 | + public function getNum () : int { |
|
| 37 | 37 | $bits = explode( '/', $this->getTitle() ); |
| 38 | 38 | return intval( end( $bits ) ); |
| 39 | 39 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public function getUserNum() : string { |
|
| 47 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
| 46 | + public function getUserNum () : string { |
|
| 47 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
| 55 | - public function getBaseTitle() : string { |
|
| 55 | + public function getBaseTitle () : string { |
|
| 56 | 56 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal Phan bug |
| 57 | 57 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return int |
| 64 | 64 | */ |
| 65 | - public function getOpposingCount() : int { |
|
| 65 | + public function getOpposingCount () : int { |
|
| 66 | 66 | return $this->getCountForSection( self::SECTION_OPPOSE ); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return int |
| 73 | 73 | */ |
| 74 | - public function getSupportCount() : int { |
|
| 74 | + public function getSupportCount () : int { |
|
| 75 | 75 | return $this->getCountForSection( self::SECTION_SUPPORT ); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param int $secNum |
| 82 | 82 | * @return int |
| 83 | 83 | */ |
| 84 | - protected function getCountForSection( int $secNum ) : int { |
|
| 84 | + protected function getCountForSection ( int $secNum ) : int { |
|
| 85 | 85 | $content = $this->controller->getPageContent( $this->title, $secNum ); |
| 86 | 86 | // Let's hope that this is good enough... |
| 87 | 87 | return substr_count( $content, "\n\# *(?![#*])" ); |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return int |
| 94 | 94 | */ |
| 95 | - protected function getQuorum() : int { |
|
| 95 | + protected function getQuorum () : int { |
|
| 96 | 96 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
| 97 | - $matches = []; |
|
| 97 | + $matches = [ ]; |
|
| 98 | 98 | preg_match( $reg, $this->getContent(), $matches ); |
| 99 | - return intval( $matches[1] ); |
|
| 99 | + return intval( $matches[ 1 ] ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return bool |
| 106 | 106 | */ |
| 107 | - public function hasOpposition() : bool { |
|
| 107 | + public function hasOpposition () : bool { |
|
| 108 | 108 | return $this->getOpposingCount() >= 15; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return int One of the OUTCOME_* constants |
| 115 | 115 | * @throws \BadMethodCallException |
| 116 | 116 | */ |
| 117 | - public function getOutcome() : int { |
|
| 117 | + public function getOutcome () : int { |
|
| 118 | 118 | if ( !$this->isVote() ) { |
| 119 | 119 | throw new \BadMethodCallException( 'Cannot get outcome for a non-vote page.' ); |
| 120 | 120 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @throws \BadMethodCallException |
| 135 | 135 | * @throws \LogicException |
| 136 | 136 | */ |
| 137 | - public function getOutcomeText() : string { |
|
| 137 | + public function getOutcomeText () : string { |
|
| 138 | 138 | if ( !$this->isVote() ) { |
| 139 | 139 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
| 140 | 140 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return bool |
| 170 | 170 | */ |
| 171 | - public function isVote() : bool { |
|
| 171 | + public function isVote () : bool { |
|
| 172 | 172 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
| 173 | 173 | return preg_match( $sectionReg, $this->getContent() ) === false; |
| 174 | 174 | } |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return int |
| 180 | 180 | */ |
| 181 | - public function getEndTimestamp() : int { |
|
| 181 | + public function getEndTimestamp () : int { |
|
| 182 | 182 | if ( $this->isVote() ) { |
| 183 | - $matches = []; |
|
| 183 | + $matches = [ ]; |
|
| 184 | 184 | $reg = "!La votazione ha inizio il.+ e ha termine.+ '''([^']+)''' alle ore '''([^']+)'''!"; |
| 185 | 185 | preg_match( $reg, $this->getContent(), $matches ); |
| 186 | 186 | list( , $day, $hours ) = $matches; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Page; |
| 4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @private Use self::get() |
| 14 | 14 | */ |
| 15 | - public function __construct() { |
|
| 15 | + public function __construct () { |
|
| 16 | 16 | parent::__construct( Config::getInstance()->get( 'list-title' ) ); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return self |
| 23 | 23 | */ |
| 24 | - public static function get() : self { |
|
| 24 | + public static function get () : self { |
|
| 25 | 25 | static $instance = null; |
| 26 | 26 | if ( $instance = null ) { |
| 27 | 27 | $instance = new self; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @return array[] |
| 36 | 36 | */ |
| 37 | - public function getAdminsList() : array { |
|
| 37 | + public function getAdminsList () : array { |
|
| 38 | 38 | return json_decode( $this->getContent(), true ); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Page; |
| 4 | 4 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param string $title |
| 21 | 21 | * @param string $domain The site where the page lives, if different from default |
| 22 | 22 | */ |
| 23 | - public function __construct( string $title, string $domain = DEFAULT_URL ) { |
|
| 23 | + public function __construct ( string $title, string $domain = DEFAULT_URL ) { |
|
| 24 | 24 | $this->title = $title; |
| 25 | 25 | $this->controller = new WikiController( $domain ); |
| 26 | 26 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function getTitle() : string { |
|
| 31 | + public function getTitle () : string { |
|
| 32 | 32 | return $this->title; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param int|null $section A section number to retrieve the content of that section |
| 39 | 39 | * @return string |
| 40 | 40 | */ |
| 41 | - public function getContent( int $section = null ) : string { |
|
| 41 | + public function getContent ( int $section = null ) : string { |
|
| 42 | 42 | if ( $this->content === null ) { |
| 43 | 43 | $this->content = $this->controller->getPageContent( $this->title, $section ); |
| 44 | 44 | } |
@@ -50,16 +50,16 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param array $params |
| 52 | 52 | */ |
| 53 | - public function edit( array $params ) { |
|
| 53 | + public function edit ( array $params ) { |
|
| 54 | 54 | $params = [ |
| 55 | 55 | 'title' => $this->getTitle() |
| 56 | 56 | ] + $params; |
| 57 | 57 | |
| 58 | 58 | $this->controller->editPage( $params ); |
| 59 | - if ( isset( $params['text'] ) ) { |
|
| 60 | - $this->content = $params['text']; |
|
| 61 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
| 62 | - $this->content .= $params['appendtext']; |
|
| 59 | + if ( isset( $params[ 'text' ] ) ) { |
|
| 60 | + $this->content = $params[ 'text' ]; |
|
| 61 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
| 62 | + $this->content .= $params[ 'appendtext' ]; |
|
| 63 | 63 | } else { |
| 64 | 64 | // Clear the cache anyway |
| 65 | 65 | ( new Logger )->warning( 'Resetting content cache. Params: ' . var_export( $params, true ) ); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | - public function __toString() { |
|
| 75 | + public function __toString () { |
|
| 76 | 76 | return $this->getTitle(); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -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,13 +60,11 @@ discard block |
||
| 60 | 60 | * @param array $groups |
| 61 | 61 | * @return int |
| 62 | 62 | */ |
| 63 | - private function getValidTimestamp( array $groups ) : int { |
|
| 63 | + private function getValidTimestamp ( array $groups ) : int { |
|
| 64 | 64 | $checkuser = isset( $groups[ 'checkuser' ] ) ? |
| 65 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 66 | - 0; |
|
| 65 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 67 | 66 | $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
| 68 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 69 | - 0; |
|
| 67 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 70 | 68 | |
| 71 | 69 | $timestamp = max( $bureaucrat, $checkuser ); |
| 72 | 70 | if ( $timestamp === 0 ) { |
@@ -80,7 +78,7 @@ discard block |
||
| 80 | 78 | * |
| 81 | 79 | * @return PageRiconferma[] |
| 82 | 80 | */ |
| 83 | - public function getOpenPages() : array { |
|
| 81 | + public function getOpenPages () : array { |
|
| 84 | 82 | static $list = null; |
| 85 | 83 | if ( $list === null ) { |
| 86 | 84 | $baseTitle = $this->getConfig()->get( 'ric-main-page' ); |
@@ -94,10 +92,10 @@ discard block |
||
| 94 | 92 | |
| 95 | 93 | $res = RequestBase::newFromParams( $params )->execute(); |
| 96 | 94 | $pages = $res->query->pages; |
| 97 | - $list = []; |
|
| 95 | + $list = [ ]; |
|
| 98 | 96 | foreach ( reset( $pages )->templates as $page ) { |
| 99 | 97 | if ( preg_match( "!$baseTitle\/[^\/]+\/\d!", $page->title ) !== false ) { |
| 100 | - $list[] = new PageRiconferma( $page->title ); |
|
| 98 | + $list[ ] = new PageRiconferma( $page->title ); |
|
| 101 | 99 | } |
| 102 | 100 | } |
| 103 | 101 | } |
@@ -110,14 +108,14 @@ discard block |
||
| 110 | 108 | * |
| 111 | 109 | * @return PageRiconferma[] |
| 112 | 110 | */ |
| 113 | - public function getPagesToClose() : array { |
|
| 111 | + public function getPagesToClose () : array { |
|
| 114 | 112 | static $list = null; |
| 115 | 113 | if ( $list === null ) { |
| 116 | 114 | $allPages = $this->getOpenPages(); |
| 117 | - $list = []; |
|
| 115 | + $list = [ ]; |
|
| 118 | 116 | foreach ( $allPages as $page ) { |
| 119 | 117 | if ( time() > $page->getEndTimestamp() ) { |
| 120 | - $list[] = $page; |
|
| 118 | + $list[ ] = $page; |
|
| 121 | 119 | } |
| 122 | 120 | } |
| 123 | 121 | } |
@@ -129,21 +127,21 @@ discard block |
||
| 129 | 127 | * |
| 130 | 128 | * @param string $name |
| 131 | 129 | */ |
| 132 | - public function removeUser( string $name ) { |
|
| 130 | + public function removeUser ( string $name ) { |
|
| 133 | 131 | unset( $this->processUsers[ $name ] ); |
| 134 | 132 | } |
| 135 | 133 | |
| 136 | 134 | /** |
| 137 | 135 | * @return PageRiconferma[] |
| 138 | 136 | */ |
| 139 | - public function getCreatedPages() : array { |
|
| 137 | + public function getCreatedPages () : array { |
|
| 140 | 138 | return $this->createdPages; |
| 141 | 139 | } |
| 142 | 140 | |
| 143 | 141 | /** |
| 144 | 142 | * @param PageRiconferma $page |
| 145 | 143 | */ |
| 146 | - public function addCreatedPages( PageRiconferma $page ) { |
|
| 147 | - $this->createdPages[] = $page; |
|
| 144 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
| 145 | + $this->createdPages[ ] = $page; |
|
| 148 | 146 | } |
| 149 | 147 | } |
@@ -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 run() : TaskResult { |
|
| 30 | + public function run () : TaskResult { |
|
| 31 | 31 | $this->getLogger()->info( 'Starting task UpdateList' ); |
| 32 | 32 | $this->actualList = $this->getActualAdmins(); |
| 33 | 33 | $this->botList = $this->getDataProvider()->getUsersList(); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | - protected function getActualAdmins() : array { |
|
| 70 | + protected function getActualAdmins () : array { |
|
| 71 | 71 | $this->getLogger()->debug( 'Retrieving admins - API' ); |
| 72 | 72 | $params = [ |
| 73 | 73 | 'action' => 'query', |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @param \stdClass $data |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | - protected function extractAdmins( \stdClass $data ) : array { |
|
| 89 | - $ret = []; |
|
| 88 | + protected function extractAdmins ( \stdClass $data ) : array { |
|
| 89 | + $ret = [ ]; |
|
| 90 | 90 | $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
| 91 | 91 | foreach ( $data->query->allusers as $u ) { |
| 92 | 92 | if ( in_array( $u->name, $blacklist ) ) { |
@@ -103,22 +103,22 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array[] |
| 105 | 105 | */ |
| 106 | - protected function getMissingGroups() : array { |
|
| 107 | - $missing = []; |
|
| 106 | + protected function getMissingGroups () : array { |
|
| 107 | + $missing = [ ]; |
|
| 108 | 108 | foreach ( $this->actualList as $adm => $groups ) { |
| 109 | - $groupsList = []; |
|
| 109 | + $groupsList = [ ]; |
|
| 110 | 110 | if ( !isset( $this->botList[ $adm ] ) ) { |
| 111 | 111 | $groupsList = $groups; |
| 112 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 112 | + } elseif ( count( $groups ) > count( $this->botList[ $adm ] ) ) { |
|
| 113 | 113 | // Only some groups are missing |
| 114 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 114 | + $groupsList = array_diff_key( $groups, $this->botList[ $adm ] ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | foreach ( $groupsList as $group ) { |
| 118 | 118 | try { |
| 119 | 119 | $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
| 120 | 120 | } catch ( TaskException $e ) { |
| 121 | - $this->errors[] = $e->getMessage(); |
|
| 121 | + $this->errors[ ] = $e->getMessage(); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | * @throws TaskException |
| 135 | 135 | */ |
| 136 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 136 | + protected function getFlagDate ( string $admin, string $group ) : string { |
|
| 137 | 137 | $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
| 138 | 138 | |
| 139 | 139 | $url = DEFAULT_URL; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @param string $group |
| 169 | 169 | * @return string|null |
| 170 | 170 | */ |
| 171 | - private function extractTimestamp( \stdClass $data, string $group ) : ?string { |
|
| 171 | + private function extractTimestamp ( \stdClass $data, string $group ) : ?string { |
|
| 172 | 172 | $ts = null; |
| 173 | 173 | foreach ( $data->query->logevents as $entry ) { |
| 174 | 174 | if ( !isset( $entry->params ) ) { |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @return array[] |
| 192 | 192 | */ |
| 193 | - protected function getExtraGroups() : array { |
|
| 194 | - $extra = []; |
|
| 193 | + protected function getExtraGroups () : array { |
|
| 194 | + $extra = [ ]; |
|
| 195 | 195 | foreach ( $this->botList as $name => $groups ) { |
| 196 | 196 | if ( !isset( $this->actualList[ $name ] ) ) { |
| 197 | 197 | $extra[ $name ] = $groups; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param array[] $extra |
| 210 | 210 | * @return array[] |
| 211 | 211 | */ |
| 212 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 212 | + protected function getNewContent ( array $missing, array $extra ) : array { |
|
| 213 | 213 | $newContent = $this->botList; |
| 214 | 214 | foreach ( $newContent as $user => $groups ) { |
| 215 | 215 | if ( isset( $missing[ $user ] ) ) { |