@@ -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 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param MessageProvider $mp |
| 71 | 71 | * @param PageBotList $pbl |
| 72 | 72 | */ |
| 73 | - public function __construct( |
|
| 73 | + public function __construct ( |
|
| 74 | 74 | LoggerInterface $logger, |
| 75 | 75 | WikiGroup $wikiGroup, |
| 76 | 76 | MessageProvider $mp, |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param string[] $tasks Only used in MODE_TASK and MODE_SUBTASK |
| 96 | 96 | * @return TaskResult |
| 97 | 97 | */ |
| 98 | - public function run( string $mode, array $tasks = [] ) : TaskResult { |
|
| 98 | + public function run ( string $mode, array $tasks = [ ] ) : TaskResult { |
|
| 99 | 99 | if ( $mode === self::MODE_COMPLETE ) { |
| 100 | 100 | $tasks = self::FULL_RUN_ORDERED; |
| 101 | 101 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @param string[] $tasks |
| 112 | 112 | * @return TaskResult |
| 113 | 113 | */ |
| 114 | - private function runTasks( array $tasks ) : TaskResult { |
|
| 114 | + private function runTasks ( array $tasks ) : TaskResult { |
|
| 115 | 115 | $res = new TaskResult( TaskResult::STATUS_GOOD ); |
| 116 | 116 | do { |
| 117 | 117 | $res->merge( $this->runTask( current( $tasks ) ) ); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param string $name |
| 127 | 127 | * @return TaskResult |
| 128 | 128 | */ |
| 129 | - protected function runTask( string $name ) : TaskResult { |
|
| 129 | + protected function runTask ( string $name ) : TaskResult { |
|
| 130 | 130 | if ( !isset( self::TASKS_MAP[ $name ] ) ) { |
| 131 | 131 | throw new \InvalidArgumentException( "'$name' is not a valid task." ); |
| 132 | 132 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param string[] $subtasks |
| 141 | 141 | * @return TaskResult |
| 142 | 142 | */ |
| 143 | - private function runSubtasks( array $subtasks ) : TaskResult { |
|
| 143 | + private function runSubtasks ( array $subtasks ) : TaskResult { |
|
| 144 | 144 | $res = new TaskResult( TaskResult::STATUS_GOOD ); |
| 145 | 145 | do { |
| 146 | 146 | $res->merge( $this->runSubtask( current( $subtasks ) ) ); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param string $name |
| 156 | 156 | * @return TaskResult |
| 157 | 157 | */ |
| 158 | - protected function runSubtask( string $name ) : TaskResult { |
|
| 158 | + protected function runSubtask ( string $name ) : TaskResult { |
|
| 159 | 159 | if ( !isset( self::SUBTASKS_MAP[ $name ] ) ) { |
| 160 | 160 | throw new \InvalidArgumentException( "'$name' is not a valid subtask." ); |
| 161 | 161 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param string $name |
| 171 | 171 | * @return Task |
| 172 | 172 | */ |
| 173 | - private function getTaskInstance( string $name ) : Task { |
|
| 173 | + private function getTaskInstance ( string $name ) : Task { |
|
| 174 | 174 | $class = self::TASKS_MAP[ $name ]; |
| 175 | 175 | return new $class( |
| 176 | 176 | $this->logger, |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param string $class |
| 188 | 188 | * @return Subtask |
| 189 | 189 | */ |
| 190 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
| 190 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
| 191 | 191 | return new $class( |
| 192 | 192 | $this->logger, |
| 193 | 193 | $this->wikiGroup, |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Utils; |
| 4 | 4 | |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | * @param IRegexable ...$elements |
| 11 | 11 | * @return string |
| 12 | 12 | */ |
| 13 | - public static function regexFromArray( |
|
| 13 | + public static function regexFromArray ( |
|
| 14 | 14 | string $delimiter = '/', |
| 15 | 15 | IRegexable ...$elements |
| 16 | 16 | ) : string { |
| 17 | - $bits = []; |
|
| 17 | + $bits = [ ]; |
|
| 18 | 18 | foreach ( $elements as $el ) { |
| 19 | - $bits[] = $el->getRegex( $delimiter ); |
|
| 19 | + $bits[ ] = $el->getRegex( $delimiter ); |
|
| 20 | 20 | } |
| 21 | 21 | return '(?:' . implode( '|', $bits ) . ')'; |
| 22 | 22 | } |
@@ -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 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class TaskBase extends ContextSource { |
| 19 | 19 | /** @var string[] */ |
| 20 | - protected $errors = []; |
|
| 20 | + protected $errors = [ ]; |
|
| 21 | 21 | /** @var TaskDataProvider */ |
| 22 | 22 | protected $dataProvider; |
| 23 | 23 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param MessageProvider $mp |
| 31 | 31 | * @param PageBotList $pbl |
| 32 | 32 | */ |
| 33 | - final public function __construct( |
|
| 33 | + final public function __construct ( |
|
| 34 | 34 | LoggerInterface $logger, |
| 35 | 35 | WikiGroup $wikiGroup, |
| 36 | 36 | TaskDataProvider $dataProvider, |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return TaskResult |
| 48 | 48 | */ |
| 49 | - final public function run() : TaskResult { |
|
| 49 | + final public function run () : TaskResult { |
|
| 50 | 50 | $class = ( new ReflectionClass( $this ) )->getShortName(); |
| 51 | 51 | $opName = $this->getOperationName(); |
| 52 | 52 | $this->getLogger()->info( "Starting $opName $class" ); |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return int One of the STATUS_* constants |
| 79 | 79 | */ |
| 80 | - abstract protected function runInternal() : int; |
|
| 80 | + abstract protected function runInternal () : int; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * How this operation should be called in logs |
| 84 | 84 | * |
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | - abstract public function getOperationName() : string; |
|
| 87 | + abstract public function getOperationName () : string; |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * @return TaskDataProvider |
| 91 | 91 | */ |
| 92 | - protected function getDataProvider() : TaskDataProvider { |
|
| 92 | + protected function getDataProvider () : TaskDataProvider { |
|
| 93 | 93 | return $this->dataProvider; |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -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 | |
@@ -15,13 +15,13 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return string[] |
| 17 | 17 | */ |
| 18 | - abstract protected function getSubtasksMap() : array; |
|
| 18 | + abstract protected function getSubtasksMap () : array; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @param string $subtask Defined in self::SUBTASKS_MAP |
| 22 | 22 | * @return TaskResult |
| 23 | 23 | */ |
| 24 | - protected function runSubtask( string $subtask ) : TaskResult { |
|
| 24 | + protected function runSubtask ( string $subtask ) : TaskResult { |
|
| 25 | 25 | $map = $this->getSubtasksMap(); |
| 26 | 26 | if ( !isset( $map[ $subtask ] ) ) { |
| 27 | 27 | throw new InvalidArgumentException( "'$subtask' is not a valid task." ); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | /** |
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - final public function getOperationName(): string { |
|
| 37 | + final public function getOperationName (): string { |
|
| 38 | 38 | return 'task'; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param string $class |
| 45 | 45 | * @return Subtask |
| 46 | 46 | */ |
| 47 | - private function getSubtaskInstance( string $class ) : Subtask { |
|
| 47 | + private function getSubtaskInstance ( string $class ) : Subtask { |
|
| 48 | 48 | return new $class( |
| 49 | 49 | $this->getLogger(), |
| 50 | 50 | $this->getWikiGroup(), |
@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** @var int|null */ |
| 17 | 17 | private $opposeSection; |
| 18 | 18 | /** @var int[] Counts of votes for each section */ |
| 19 | - private $sectionCounts = []; |
|
| 19 | + private $sectionCounts = [ ]; |
|
| 20 | 20 | |
| 21 | 21 | // Possible outcomes of a vote |
| 22 | 22 | public const OUTCOME_OK = 0; |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * because they can vary depending on whether the page is a vote, which is relatively |
| 36 | 36 | * expensive to know since it requires parsing the content of the page. |
| 37 | 37 | */ |
| 38 | - private function defineSections() : void { |
|
| 38 | + private function defineSections () : void { |
|
| 39 | 39 | $this->supportSection = $this->isVote() ? 3 : 0; |
| 40 | 40 | $this->opposeSection = $this->isVote() ? 4 : 3; |
| 41 | 41 | } |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | - public function getUserName() : string { |
|
| 49 | - return explode( '/', $this->title )[2]; |
|
| 48 | + public function getUserName () : string { |
|
| 49 | + return explode( '/', $this->title )[ 2 ]; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return int |
| 56 | 56 | */ |
| 57 | - public function getNum() : int { |
|
| 57 | + public function getNum () : int { |
|
| 58 | 58 | $bits = explode( '/', $this->getTitle() ); |
| 59 | 59 | return (int)end( $bits ); |
| 60 | 60 | } |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - public function getUserNum() : string { |
|
| 68 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
| 67 | + public function getUserNum () : string { |
|
| 68 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return int |
| 75 | 75 | */ |
| 76 | - public function getOpposingCount() : int { |
|
| 76 | + public function getOpposingCount () : int { |
|
| 77 | 77 | $this->defineSections(); |
| 78 | 78 | return $this->getCountForSection( $this->opposeSection ); |
| 79 | 79 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @return int |
| 85 | 85 | * @throws BadMethodCallException |
| 86 | 86 | */ |
| 87 | - public function getSupportCount() : int { |
|
| 87 | + public function getSupportCount () : int { |
|
| 88 | 88 | if ( !$this->isVote() ) { |
| 89 | 89 | throw new BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
| 90 | 90 | } |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @param int $secNum |
| 99 | 99 | * @return int |
| 100 | 100 | */ |
| 101 | - protected function getCountForSection( int $secNum ) : int { |
|
| 101 | + protected function getCountForSection ( int $secNum ) : int { |
|
| 102 | 102 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
| 103 | 103 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
| 104 | 104 | // Let's hope that this is good enough... |
| 105 | - $this->sectionCounts[$secNum] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 105 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
| 106 | 106 | } |
| 107 | - return $this->sectionCounts[$secNum]; |
|
| 107 | + return $this->sectionCounts[ $secNum ]; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return int |
| 114 | 114 | */ |
| 115 | - protected function getQuorum() : int { |
|
| 115 | + protected function getQuorum () : int { |
|
| 116 | 116 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
| 117 | - return (int)$this->getMatch( $reg )[1]; |
|
| 117 | + return (int)$this->getMatch( $reg )[ 1 ]; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return bool |
| 124 | 124 | */ |
| 125 | - public function hasOpposition() : bool { |
|
| 125 | + public function hasOpposition () : bool { |
|
| 126 | 126 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return int One of the OUTCOME_* constants |
| 133 | 133 | */ |
| 134 | - public function getOutcome() : int { |
|
| 134 | + public function getOutcome () : int { |
|
| 135 | 135 | if ( !$this->isVote() ) { |
| 136 | 136 | return self::OUTCOME_OK; |
| 137 | 137 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @throws BadMethodCallException |
| 155 | 155 | * @throws \LogicException |
| 156 | 156 | */ |
| 157 | - public function getOutcomeText() : string { |
|
| 157 | + public function getOutcomeText () : string { |
|
| 158 | 158 | if ( !$this->isVote() ) { |
| 159 | 159 | throw new BadMethodCallException( 'No need for an outcome text.' ); |
| 160 | 160 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @return bool |
| 190 | 190 | */ |
| 191 | - public function isVote() : bool { |
|
| 191 | + public function isVote () : bool { |
|
| 192 | 192 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
| 193 | 193 | return !$this->matches( $sectionReg ); |
| 194 | 194 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return int |
| 200 | 200 | */ |
| 201 | - public function getCreationTimestamp() : int { |
|
| 201 | + public function getCreationTimestamp () : int { |
|
| 202 | 202 | return $this->wiki->getPageCreationTS( $this->title ); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return int |
| 209 | 209 | */ |
| 210 | - public function getEndTimestamp() : int { |
|
| 210 | + public function getEndTimestamp () : int { |
|
| 211 | 211 | if ( $this->isVote() ) { |
| 212 | 212 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
| 213 | 213 | [ , $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\Page; |
| 4 | 4 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string $title |
| 23 | 23 | * @param Wiki $wiki For the site where the page lives |
| 24 | 24 | */ |
| 25 | - public function __construct( string $title, Wiki $wiki ) { |
|
| 25 | + public function __construct ( string $title, Wiki $wiki ) { |
|
| 26 | 26 | $this->wiki = $wiki; |
| 27 | 27 | $this->title = $title; |
| 28 | 28 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function getTitle() : string { |
|
| 33 | + public function getTitle () : string { |
|
| 34 | 34 | return $this->title; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param int|null $section A section number to retrieve the content of that section |
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | - public function getContent( int $section = null ) : string { |
|
| 43 | + public function getContent ( int $section = null ) : string { |
|
| 44 | 44 | if ( $this->content === null ) { |
| 45 | 45 | $this->content = $this->wiki->getPageContent( $this->title, $section ); |
| 46 | 46 | } |
@@ -54,18 +54,18 @@ discard block |
||
| 54 | 54 | * @phan-param array<int|string|bool> $params |
| 55 | 55 | * @throws LogicException |
| 56 | 56 | */ |
| 57 | - public function edit( array $params ) : void { |
|
| 57 | + public function edit ( array $params ) : void { |
|
| 58 | 58 | $params = [ |
| 59 | 59 | 'title' => $this->getTitle() |
| 60 | 60 | ] + $params; |
| 61 | 61 | |
| 62 | 62 | $this->wiki->editPage( $params ); |
| 63 | - if ( isset( $params['text'] ) ) { |
|
| 64 | - $this->content = $params['text']; |
|
| 65 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
| 66 | - $this->content .= $params['appendtext']; |
|
| 67 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
| 68 | - $this->content = $params['prependtext'] . $this->content; |
|
| 63 | + if ( isset( $params[ 'text' ] ) ) { |
|
| 64 | + $this->content = $params[ 'text' ]; |
|
| 65 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
| 66 | + $this->content .= $params[ 'appendtext' ]; |
|
| 67 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
| 68 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
| 69 | 69 | } else { |
| 70 | 70 | throw new LogicException( |
| 71 | 71 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return bool |
| 80 | 80 | */ |
| 81 | - public function exists() : bool { |
|
| 81 | + public function exists () : bool { |
|
| 82 | 82 | $pages = $this->wiki->getRequestFactory()->newFromParams( [ |
| 83 | 83 | 'action' => 'query', |
| 84 | 84 | 'titles' => $this->getTitle() |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $regex |
| 93 | 93 | * @return bool |
| 94 | 94 | */ |
| 95 | - public function matches( string $regex ) : bool { |
|
| 95 | + public function matches ( string $regex ) : bool { |
|
| 96 | 96 | return (bool)preg_match( $regex, $this->getContent() ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @return string[] |
| 105 | 105 | * @throws MissingMatchException |
| 106 | 106 | */ |
| 107 | - public function getMatch( string $regex ) : array { |
|
| 108 | - $ret = []; |
|
| 107 | + public function getMatch ( string $regex ) : array { |
|
| 108 | + $ret = [ ]; |
|
| 109 | 109 | if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { |
| 110 | 110 | throw new MissingMatchException( "The content of $this does not match the given regex $regex" ); |
| 111 | 111 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @inheritDoc |
| 119 | 119 | */ |
| 120 | - public function getRegex( string $delimiter = '/' ) : string { |
|
| 120 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
| 121 | 121 | return str_replace( ' ', '[ _]', preg_quote( $this->title, $delimiter ) ); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return string |
| 128 | 128 | */ |
| 129 | - public function __toString() : string { |
|
| 129 | + public function __toString () : string { |
|
| 130 | 130 | return $this->getTitle(); |
| 131 | 131 | } |
| 132 | 132 | } |