@@ -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,9 +11,9 @@ discard block |
||
| 11 | 11 | class PageRiconferma extends Page { |
| 12 | 12 | // Sections of the page, value = section number. Loaded in self::defineSections |
| 13 | 13 | private $supportSection; |
| 14 | - private $opposeSection ; |
|
| 14 | + private $opposeSection; |
|
| 15 | 15 | /** @var array Counts of votes for each section */ |
| 16 | - private $sectionCounts = []; |
|
| 16 | + private $sectionCounts = [ ]; |
|
| 17 | 17 | |
| 18 | 18 | // Possible outcomes of a vote |
| 19 | 19 | const OUTCOME_OK = 0; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * because they can vary depending on whether the page is a vote, which is relatively |
| 32 | 32 | * expensive to know since it requires parsing the content of the page. |
| 33 | 33 | */ |
| 34 | - private function defineSections() { |
|
| 34 | + private function defineSections () { |
|
| 35 | 35 | $this->supportSection = $this->isVote() ? 3 : 0; |
| 36 | 36 | $this->opposeSection = $this->isVote() ? 4 : 3; |
| 37 | 37 | } |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return User |
| 43 | 43 | */ |
| 44 | - public function getUser() : User { |
|
| 45 | - $name = explode( '/', $this->title )[2]; |
|
| 44 | + public function getUser () : User { |
|
| 45 | + $name = explode( '/', $this->title )[ 2 ]; |
|
| 46 | 46 | return new User( $name ); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return int |
| 53 | 53 | */ |
| 54 | - public function getNum() : int { |
|
| 54 | + public function getNum () : int { |
|
| 55 | 55 | $bits = explode( '/', $this->getTitle() ); |
| 56 | 56 | return intval( end( $bits ) ); |
| 57 | 57 | } |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function getUserNum() : string { |
|
| 65 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
| 64 | + public function getUserNum () : string { |
|
| 65 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return string |
| 72 | 72 | */ |
| 73 | - public function getBaseTitle() : string { |
|
| 73 | + public function getBaseTitle () : string { |
|
| 74 | 74 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal Phan bug |
| 75 | 75 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
| 76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return int |
| 82 | 82 | */ |
| 83 | - public function getOpposingCount() : int { |
|
| 83 | + public function getOpposingCount () : int { |
|
| 84 | 84 | $this->defineSections(); |
| 85 | 85 | return $this->getCountForSection( $this->opposeSection ); |
| 86 | 86 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return int |
| 92 | 92 | * @throws \BadMethodCallException |
| 93 | 93 | */ |
| 94 | - public function getSupportCount() : int { |
|
| 94 | + public function getSupportCount () : int { |
|
| 95 | 95 | if ( !$this->isVote() ) { |
| 96 | 96 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
| 97 | 97 | } |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | * @param int $secNum |
| 106 | 106 | * @return int |
| 107 | 107 | */ |
| 108 | - protected function getCountForSection( int $secNum ) : int { |
|
| 108 | + protected function getCountForSection ( int $secNum ) : int { |
|
| 109 | 109 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
| 110 | 110 | $content = $this->controller->getPageContent( $this->title, $secNum ); |
| 111 | 111 | // Let's hope that this is good enough... |
| 112 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *]|\.\.\.$)/m", $content ); |
|
| 112 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *]|\.\.\.$)/m", $content ); |
|
| 113 | 113 | } |
| 114 | - return $this->sectionCounts[$secNum]; |
|
| 114 | + return $this->sectionCounts[ $secNum ]; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return int |
| 121 | 121 | */ |
| 122 | - protected function getQuorum() : int { |
|
| 122 | + protected function getQuorum () : int { |
|
| 123 | 123 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
| 124 | - return intval( $this->getMatch( $reg )[1] ); |
|
| 124 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return bool |
| 131 | 131 | */ |
| 132 | - public function hasOpposition() : bool { |
|
| 132 | + public function hasOpposition () : bool { |
|
| 133 | 133 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return int One of the OUTCOME_* constants |
| 140 | 140 | */ |
| 141 | - public function getOutcome() : int { |
|
| 141 | + public function getOutcome () : int { |
|
| 142 | 142 | if ( !$this->isVote() ) { |
| 143 | 143 | return self::OUTCOME_OK; |
| 144 | 144 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @throws \BadMethodCallException |
| 162 | 162 | * @throws \LogicException |
| 163 | 163 | */ |
| 164 | - public function getOutcomeText() : string { |
|
| 164 | + public function getOutcomeText () : string { |
|
| 165 | 165 | if ( !$this->isVote() ) { |
| 166 | 166 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
| 167 | 167 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @return bool |
| 197 | 197 | */ |
| 198 | - public function isVote() : bool { |
|
| 198 | + public function isVote () : bool { |
|
| 199 | 199 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
| 200 | 200 | return !$this->matches( $sectionReg ); |
| 201 | 201 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return int |
| 207 | 207 | */ |
| 208 | - public function getCreationTimestamp() : int { |
|
| 208 | + public function getCreationTimestamp () : int { |
|
| 209 | 209 | return $this->controller->getPageCreationTS( $this->title ); |
| 210 | 210 | } |
| 211 | 211 | /** |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return int |
| 215 | 215 | */ |
| 216 | - public function getEndTimestamp() : int { |
|
| 216 | + public function getEndTimestamp () : int { |
|
| 217 | 217 | if ( $this->isVote() ) { |
| 218 | 218 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
| 219 | 219 | list( , $hours, $day ) = $this->getMatch( $reg ); |