@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace BotRiconferme\Request; |
4 | 4 | |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | /** @var string */ |
31 | 31 | protected $method = 'GET'; |
32 | 32 | /** @var string[] */ |
33 | - protected $newCookies = []; |
|
33 | + protected $newCookies = [ ]; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Use self::newFromParams, which will provide the right class to use |
37 | 37 | * |
38 | 38 | * @param array $params |
39 | 39 | */ |
40 | - protected function __construct( array $params ) { |
|
40 | + protected function __construct ( array $params ) { |
|
41 | 41 | $this->params = [ 'format' => 'json' ] + $params; |
42 | 42 | $this->url = DEFAULT_URL; |
43 | 43 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param array $params |
49 | 49 | * @return self |
50 | 50 | */ |
51 | - public static function newFromParams( array $params ) : self { |
|
51 | + public static function newFromParams ( array $params ) : self { |
|
52 | 52 | if ( extension_loaded( 'curl' ) ) { |
53 | 53 | $ret = new CurlRequest( $params ); |
54 | 54 | } else { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return self For chaining |
64 | 64 | */ |
65 | - public function setPost() : self { |
|
65 | + public function setPost () : self { |
|
66 | 66 | $this->method = 'POST'; |
67 | 67 | return $this; |
68 | 68 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string $url |
74 | 74 | * @return self for chaining |
75 | 75 | */ |
76 | - public function setUrl( string $url ) : self { |
|
76 | + public function setUrl ( string $url ) : self { |
|
77 | 77 | $this->url = $url; |
78 | 78 | return $this; |
79 | 79 | } |
@@ -83,14 +83,14 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return \stdClass |
85 | 85 | */ |
86 | - public function execute() : \stdClass { |
|
86 | + public function execute () : \stdClass { |
|
87 | 87 | $curParams = $this->params; |
88 | - $sets = []; |
|
88 | + $sets = [ ]; |
|
89 | 89 | do { |
90 | 90 | $res = $this->makeRequestInternal( $curParams ); |
91 | 91 | |
92 | 92 | $this->handleErrorAndWarnings( $res ); |
93 | - $sets[] = $res; |
|
93 | + $sets[ ] = $res; |
|
94 | 94 | |
95 | 95 | $finished = true; |
96 | 96 | if ( isset( $res->continue ) ) { |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | * @param array $params |
109 | 109 | * @return \stdClass |
110 | 110 | */ |
111 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
111 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
112 | 112 | if ( $this->method === 'POST' ) { |
113 | - $params['maxlag'] = self::MAXLAG; |
|
113 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
114 | 114 | } |
115 | 115 | $params = http_build_query( $params ); |
116 | 116 | |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | * @param string $params |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
129 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * After a request, set cookies for the next ones |
133 | 133 | * |
134 | 134 | * @param array $cookies |
135 | 135 | */ |
136 | - protected function setCookies( array $cookies ) { |
|
136 | + protected function setCookies ( array $cookies ) { |
|
137 | 137 | foreach ( $cookies as $cookie ) { |
138 | 138 | $bits = explode( ';', $cookie ); |
139 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
139 | + list( $name, $value ) = explode( '=', $bits[ 0 ] ); |
|
140 | 140 | self::$cookiesToSet[ $name ] = $value; |
141 | 141 | } |
142 | 142 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param \stdClass $res |
148 | 148 | * @return APIRequestException |
149 | 149 | */ |
150 | - private function getException( \stdClass $res ) : APIRequestException { |
|
150 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
151 | 151 | switch ( $res->error->code ) { |
152 | 152 | case 'missingtitle': |
153 | 153 | $ex = new MissingPageException; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param \stdClass $res |
171 | 171 | * @throws APIRequestException |
172 | 172 | */ |
173 | - protected function handleErrorAndWarnings( \stdClass $res ) { |
|
173 | + protected function handleErrorAndWarnings ( \stdClass $res ) { |
|
174 | 174 | if ( isset( $res->error ) ) { |
175 | 175 | throw $this->getException( $res ); |
176 | 176 | } elseif ( isset( $res->warnings ) ) { |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param \stdClass[] $sets |
187 | 187 | * @return \stdClass |
188 | 188 | */ |
189 | - private function mergeSets( array $sets ) : \stdClass { |
|
189 | + private function mergeSets ( array $sets ) : \stdClass { |
|
190 | 190 | // Use the first set as template |
191 | 191 | $ret = array_shift( $sets ); |
192 | 192 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param array|\stdClass $second |
204 | 204 | * @return array|\stdClass array |
205 | 205 | */ |
206 | - private function recursiveMerge( $first, $second ) { |
|
206 | + private function recursiveMerge ( $first, $second ) { |
|
207 | 207 | $ret = $first; |
208 | 208 | if ( is_array( $second ) ) { |
209 | 209 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - protected function getHeaders() :array { |
|
224 | + protected function getHeaders () :array { |
|
225 | 225 | $ret = self::HEADERS; |
226 | 226 | if ( self::$cookiesToSet ) { |
227 | - $cookies = []; |
|
227 | + $cookies = [ ]; |
|
228 | 228 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
229 | - $cookies[] = trim( "$cname=$cval" ); |
|
229 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
230 | 230 | } |
231 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
231 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
232 | 232 | } |
233 | 233 | return $ret; |
234 | 234 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param array $headers |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - protected function buildHeadersString( array $headers ) : string { |
|
242 | + protected function buildHeadersString ( array $headers ) : string { |
|
243 | 243 | $ret = ''; |
244 | 244 | foreach ( $headers as $header ) { |
245 | 245 | $ret .= "$header\r\n"; |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** @var Controller */ |
20 | 20 | private $controller; |
21 | 21 | |
22 | - public function __construct() { |
|
22 | + public function __construct () { |
|
23 | 23 | $this->setLogger( new Logger ); |
24 | 24 | $this->setConfig( Config::getInstance() ); |
25 | 25 | $this->setController( new Controller ); |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return LoggerInterface |
30 | 30 | */ |
31 | - protected function getLogger() : LoggerInterface { |
|
31 | + protected function getLogger () : LoggerInterface { |
|
32 | 32 | return $this->logger; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @inheritDoc |
37 | 37 | */ |
38 | - public function setLogger( LoggerInterface $logger ) { |
|
38 | + public function setLogger ( LoggerInterface $logger ) { |
|
39 | 39 | $this->logger = $logger; |
40 | 40 | } |
41 | 41 | |
@@ -45,35 +45,35 @@ discard block |
||
45 | 45 | * @param string $optname |
46 | 46 | * @return mixed |
47 | 47 | */ |
48 | - protected function getOpt( string $optname ) { |
|
48 | + protected function getOpt ( string $optname ) { |
|
49 | 49 | return $this->getConfig()->get( $optname ); |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return Config |
54 | 54 | */ |
55 | - protected function getConfig() : Config { |
|
55 | + protected function getConfig () : Config { |
|
56 | 56 | return $this->config; |
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @param Config $cfg |
61 | 61 | */ |
62 | - protected function setConfig( Config $cfg ) { |
|
62 | + protected function setConfig ( Config $cfg ) { |
|
63 | 63 | $this->config = $cfg; |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @return Controller |
68 | 68 | */ |
69 | - protected function getController() : Controller { |
|
69 | + protected function getController () : Controller { |
|
70 | 70 | return $this->controller; |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @param Controller $controller |
75 | 75 | */ |
76 | - protected function setController( Controller $controller ) { |
|
76 | + protected function setController ( Controller $controller ) { |
|
77 | 77 | $this->controller = $controller; |
78 | 78 | } |
79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param string $key |
84 | 84 | * @return Message |
85 | 85 | */ |
86 | - protected function msg( string $key ) : Message { |
|
86 | + protected function msg ( string $key ) : Message { |
|
87 | 87 | return new Message( $key ); |
88 | 88 | } |
89 | 89 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param string $key |
30 | 30 | */ |
31 | - public function __construct( string $key ) { |
|
31 | + public function __construct ( string $key ) { |
|
32 | 32 | $this->key = $key; |
33 | 33 | $this->value = Config::getInstance()->getWikiMessage( $key ); |
34 | 34 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param array $args |
38 | 38 | * @return self |
39 | 39 | */ |
40 | - public function params( array $args ) : self { |
|
40 | + public function params ( array $args ) : self { |
|
41 | 41 | $this->value = strtr( $this->value, $args ); |
42 | 42 | return $this; |
43 | 43 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @return string |
47 | 47 | */ |
48 | - public function text() : string { |
|
48 | + public function text () : string { |
|
49 | 49 | $this->parsePlurals(); |
50 | 50 | return $this->value; |
51 | 51 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * Replace {{$plur|<amount>|sing|plur}} |
55 | 55 | */ |
56 | - protected function parsePlurals() { |
|
56 | + protected function parsePlurals () { |
|
57 | 57 | $reg = '!\{\{\$plur\|(?P<amount>\d+)\|(?P<sing>[^}|]+)\|(?P<plur>[^|}]+)}}!'; |
58 | 58 | |
59 | 59 | if ( preg_match( $reg, $this->value ) === 0 ) { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this->value = preg_replace_callback( |
63 | 63 | $reg, |
64 | 64 | function ( $matches ) { |
65 | - return intval( $matches['amount'] ) > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
65 | + return intval( $matches[ 'amount' ] ) > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
66 | 66 | }, |
67 | 67 | $this->value |
68 | 68 | ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param int $timestamp |
75 | 75 | * @return string |
76 | 76 | */ |
77 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
77 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
78 | 78 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
79 | 79 | $timeString = strftime( '%e %B alle %R', $timestamp ); |
80 | 80 | // Remove the left space if day has a single digit |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param string $timeString Full format, e.g. "15 aprile 2019 18:27" |
92 | 92 | * @return int |
93 | 93 | */ |
94 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
94 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
95 | 95 | $englishTime = str_ireplace( |
96 | 96 | array_values( self::MONTHS ), |
97 | 97 | array_keys( self::MONTHS ), |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | * @param string $emptyText |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
112 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
113 | 113 | if ( count( $data ) > 1 ) { |
114 | 114 | $last = array_pop( $data ); |
115 | 115 | $ret = implode( ', ', $data ) . " e $last"; |
116 | 116 | } elseif ( $data ) { |
117 | - $ret = (string)$data[0]; |
|
117 | + $ret = (string)$data[ 0 ]; |
|
118 | 118 | } else { |
119 | 119 | $ret = $emptyText; |
120 | 120 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return $ret; |
123 | 123 | } |
124 | 124 | |
125 | - public function __toString() { |
|
125 | + public function __toString () { |
|
126 | 126 | return $this->text(); |
127 | 127 | } |
128 | 128 | } |
@@ -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 ( $this->shouldAddUser( $groups ) ) { |
29 | 29 | $this->processUsers[ $user ] = $groups; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param string[] $groups |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - private function shouldAddUser( array $groups ) : bool { |
|
43 | + private function shouldAddUser ( array $groups ) : bool { |
|
44 | 44 | $override = true; |
45 | 45 | $timestamp = PageBotList::getOverrideTimestamp( $groups ); |
46 | 46 | |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return PageRiconferma[] |
61 | 61 | */ |
62 | - public function getOpenPages() : array { |
|
62 | + public function getOpenPages () : array { |
|
63 | 63 | static $list = null; |
64 | 64 | if ( $list === null ) { |
65 | - $list = []; |
|
65 | + $list = [ ]; |
|
66 | 66 | $mainTitle = $this->getOpt( 'main-page-title' ); |
67 | 67 | $params = [ |
68 | 68 | 'action' => 'query', |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
77 | 77 | foreach ( reset( $pages )->templates as $page ) { |
78 | 78 | if ( preg_match( "!$titleReg\/[^\/]+\/\d!", $page->title ) ) { |
79 | - $list[] = new PageRiconferma( $page->title ); |
|
79 | + $list[ ] = new PageRiconferma( $page->title ); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return PageRiconferma[] |
91 | 91 | */ |
92 | - public function getPagesToClose() : array { |
|
92 | + public function getPagesToClose () : array { |
|
93 | 93 | static $list = null; |
94 | 94 | if ( $list === null ) { |
95 | - $list = []; |
|
95 | + $list = [ ]; |
|
96 | 96 | foreach ( $this->getOpenPages() as $page ) { |
97 | 97 | if ( time() > $page->getEndTimestamp() ) { |
98 | - $list[] = $page; |
|
98 | + $list[ ] = $page; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param string $name |
109 | 109 | */ |
110 | - public function removeUser( string $name ) { |
|
110 | + public function removeUser ( string $name ) { |
|
111 | 111 | unset( $this->processUsers[ $name ] ); |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @return PageRiconferma[] |
116 | 116 | */ |
117 | - public function getCreatedPages() : array { |
|
117 | + public function getCreatedPages () : array { |
|
118 | 118 | return $this->createdPages; |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @param PageRiconferma $page |
123 | 123 | */ |
124 | - public function addCreatedPages( PageRiconferma $page ) { |
|
125 | - $this->createdPages[] = $page; |
|
124 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
125 | + $this->createdPages[ ] = $page; |
|
126 | 126 | } |
127 | 127 | } |
@@ -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\Subtask; |
4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @inheritDoc |
16 | 16 | */ |
17 | - public function runInternal() : int { |
|
17 | + public function runInternal () : int { |
|
18 | 18 | $users = $this->getDataProvider()->getUsersToProcess(); |
19 | 19 | |
20 | 20 | if ( !$users ) { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param string $user |
35 | 35 | * @param array $groups |
36 | 36 | */ |
37 | - protected function processUser( string $user, array $groups ) { |
|
37 | + protected function processUser ( string $user, array $groups ) { |
|
38 | 38 | try { |
39 | 39 | $num = $this->getLastPageNum( $user ) + 1; |
40 | 40 | } catch ( TaskException $e ) { |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @return int |
67 | 67 | * @throws TaskException |
68 | 68 | */ |
69 | - protected function getLastPageNum( string $user ) : int { |
|
69 | + protected function getLastPageNum ( string $user ) : int { |
|
70 | 70 | $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
71 | - $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[1]; |
|
71 | + $unprefixedTitle = explode( ':', $this->getOpt( 'main-page-title' ), 2 )[ 1 ]; |
|
72 | 72 | $params = [ |
73 | 73 | 'action' => 'query', |
74 | 74 | 'list' => 'allpages', |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | * @param string $user |
104 | 104 | * @param array $groups |
105 | 105 | */ |
106 | - protected function createPage( string $title, string $user, array $groups ) { |
|
106 | + protected function createPage ( string $title, string $user, array $groups ) { |
|
107 | 107 | $this->getLogger()->info( "Creating page $title" ); |
108 | 108 | $textParams = [ |
109 | 109 | '$user' => $user, |
110 | - '$date' => $groups['sysop'], |
|
111 | - '$burocrate' => $groups['bureaucrat'] ?? '', |
|
112 | - '$checkuser' => $groups['checkuser'] ?? '' |
|
110 | + '$date' => $groups[ 'sysop' ], |
|
111 | + '$burocrate' => $groups[ 'bureaucrat' ] ?? '', |
|
112 | + '$checkuser' => $groups[ 'checkuser' ] ?? '' |
|
113 | 113 | ]; |
114 | 114 | |
115 | 115 | $params = [ |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param string $title |
128 | 128 | * @param string $newText |
129 | 129 | */ |
130 | - protected function createBasePage( string $title, string $newText ) { |
|
130 | + protected function createBasePage ( string $title, string $newText ) { |
|
131 | 131 | $this->getLogger()->info( "Creating base page $title" ); |
132 | 132 | |
133 | 133 | $params = [ |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $title |
145 | 145 | * @param string $newText |
146 | 146 | */ |
147 | - protected function updateBasePage( string $title, string $newText ) { |
|
147 | + protected function updateBasePage ( string $title, string $newText ) { |
|
148 | 148 | $this->getLogger()->info( "Updating base page $title" ); |
149 | 149 | |
150 | 150 | $params = [ |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | private $supportSection; |
14 | 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; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * because they can vary depending on whether the page is a vote, which is relatively |
33 | 33 | * expensive to know since it requires parsing the content of the page. |
34 | 34 | */ |
35 | - private function defineSections() { |
|
35 | + private function defineSections () { |
|
36 | 36 | $this->supportSection = $this->isVote() ? 3 : 0; |
37 | 37 | $this->opposeSection = $this->isVote() ? 4 : 3; |
38 | 38 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return User |
44 | 44 | */ |
45 | - public function getUser() : User { |
|
46 | - $name = explode( '/', $this->title )[2]; |
|
45 | + public function getUser () : User { |
|
46 | + $name = explode( '/', $this->title )[ 2 ]; |
|
47 | 47 | return new User( $name ); |
48 | 48 | } |
49 | 49 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return int |
54 | 54 | */ |
55 | - public function getNum() : int { |
|
55 | + public function getNum () : int { |
|
56 | 56 | $bits = explode( '/', $this->getTitle() ); |
57 | 57 | return intval( end( $bits ) ); |
58 | 58 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public function getUserNum() : string { |
|
66 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
65 | + public function getUserNum () : string { |
|
66 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - public function getBaseTitle() : string { |
|
74 | + public function getBaseTitle () : string { |
|
75 | 75 | // @phan-suppress-next-line PhanTypeMismatchArgumentInternal Phan bug |
76 | 76 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
77 | 77 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return int |
83 | 83 | */ |
84 | - public function getOpposingCount() : int { |
|
84 | + public function getOpposingCount () : int { |
|
85 | 85 | $this->defineSections(); |
86 | 86 | return $this->getCountForSection( $this->opposeSection ); |
87 | 87 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @return int |
93 | 93 | * @throws \BadMethodCallException |
94 | 94 | */ |
95 | - public function getSupportCount() : int { |
|
95 | + public function getSupportCount () : int { |
|
96 | 96 | if ( !$this->isVote() ) { |
97 | 97 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
98 | 98 | } |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | * @param int $secNum |
107 | 107 | * @return int |
108 | 108 | */ |
109 | - protected function getCountForSection( int $secNum ) : int { |
|
109 | + protected function getCountForSection ( int $secNum ) : int { |
|
110 | 110 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
111 | 111 | $content = $this->controller->getPageContent( $this->title, $secNum ); |
112 | 112 | // Let's hope that this is good enough... |
113 | - $this->sectionCounts[$secNum] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
113 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^\# *(?![# *:]|\.\.\.$)/m", $content ); |
|
114 | 114 | } |
115 | - return $this->sectionCounts[$secNum]; |
|
115 | + return $this->sectionCounts[ $secNum ]; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return int |
122 | 122 | */ |
123 | - protected function getQuorum() : int { |
|
123 | + protected function getQuorum () : int { |
|
124 | 124 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
125 | - return intval( $this->getMatch( $reg )[1] ); |
|
125 | + return intval( $this->getMatch( $reg )[ 1 ] ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return bool |
132 | 132 | */ |
133 | - public function hasOpposition() : bool { |
|
133 | + public function hasOpposition () : bool { |
|
134 | 134 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
135 | 135 | } |
136 | 136 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return int One of the OUTCOME_* constants |
141 | 141 | */ |
142 | - public function getOutcome() : int { |
|
142 | + public function getOutcome () : int { |
|
143 | 143 | if ( !$this->isVote() ) { |
144 | 144 | return self::OUTCOME_OK; |
145 | 145 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @throws \BadMethodCallException |
163 | 163 | * @throws \LogicException |
164 | 164 | */ |
165 | - public function getOutcomeText() : string { |
|
165 | + public function getOutcomeText () : string { |
|
166 | 166 | if ( !$this->isVote() ) { |
167 | 167 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
168 | 168 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return bool |
198 | 198 | */ |
199 | - public function isVote() : bool { |
|
199 | + public function isVote () : bool { |
|
200 | 200 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
201 | 201 | return !$this->matches( $sectionReg ); |
202 | 202 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return int |
208 | 208 | */ |
209 | - public function getCreationTimestamp() : int { |
|
209 | + public function getCreationTimestamp () : int { |
|
210 | 210 | return $this->controller->getPageCreationTS( $this->title ); |
211 | 211 | } |
212 | 212 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return int |
217 | 217 | */ |
218 | - public function getEndTimestamp() : int { |
|
218 | + public function getEndTimestamp () : int { |
|
219 | 219 | if ( $this->isVote() ) { |
220 | 220 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
221 | 221 | list( , $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 string $domain The site where the page lives, if different from default |
24 | 24 | */ |
25 | - public function __construct( string $title, string $domain = DEFAULT_URL ) { |
|
25 | + public function __construct ( string $title, string $domain = DEFAULT_URL ) { |
|
26 | 26 | $this->title = $title; |
27 | 27 | $this->controller = new Controller( $domain ); |
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->controller->getPageContent( $this->title, $section ); |
46 | 46 | } |
@@ -53,18 +53,18 @@ discard block |
||
53 | 53 | * @param array $params |
54 | 54 | * @throws \LogicException |
55 | 55 | */ |
56 | - public function edit( array $params ) { |
|
56 | + public function edit ( array $params ) { |
|
57 | 57 | $params = [ |
58 | 58 | 'title' => $this->getTitle() |
59 | 59 | ] + $params; |
60 | 60 | |
61 | 61 | $this->controller->editPage( $params ); |
62 | - if ( isset( $params['text'] ) ) { |
|
63 | - $this->content = $params['text']; |
|
64 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
65 | - $this->content .= $params['appendtext']; |
|
66 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
67 | - $this->content = $params['prependtext'] . $this->content; |
|
62 | + if ( isset( $params[ 'text' ] ) ) { |
|
63 | + $this->content = $params[ 'text' ]; |
|
64 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
65 | + $this->content .= $params[ 'appendtext' ]; |
|
66 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
67 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
68 | 68 | } else { |
69 | 69 | throw new \LogicException( |
70 | 70 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | - public function exists() : bool { |
|
80 | + public function exists () : bool { |
|
81 | 81 | $res = RequestBase::newFromParams( [ |
82 | 82 | 'action' => 'query', |
83 | 83 | '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 \Exception |
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 \Exception( 'The content does not match the given regex' ); |
111 | 111 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @inheritDoc |
119 | 119 | */ |
120 | - public function getRegex() : string { |
|
120 | + public function getRegex () : string { |
|
121 | 121 | return str_replace( ' ', '[ _]', preg_quote( $this->title ) ); |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public function __toString() { |
|
129 | + public function __toString () { |
|
130 | 130 | return $this->getTitle(); |
131 | 131 | } |
132 | 132 | } |
@@ -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\Subtask; |
4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @inheritDoc |
16 | 16 | */ |
17 | - public function runInternal() : int { |
|
17 | + public function runInternal () : int { |
|
18 | 18 | $pages = $this->getDataProvider()->getCreatedPages(); |
19 | 19 | |
20 | 20 | if ( !$pages ) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param PageRiconferma[] $pages |
38 | 38 | */ |
39 | - protected function addToMainPage( array $pages ) { |
|
39 | + protected function addToMainPage ( array $pages ) { |
|
40 | 40 | $this->getLogger()->info( |
41 | 41 | 'Adding the following to main: ' . implode( ', ', $pages ) |
42 | 42 | ); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param PageRiconferma[] $pages |
71 | 71 | */ |
72 | - protected function addToVotazioni( array $pages ) { |
|
72 | + protected function addToVotazioni ( array $pages ) { |
|
73 | 73 | $this->getLogger()->info( |
74 | 74 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
75 | 75 | ); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param int $amount |
107 | 107 | * @throws TaskException |
108 | 108 | */ |
109 | - protected function addToNews( int $amount ) { |
|
109 | + protected function addToNews ( int $amount ) { |
|
110 | 110 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
111 | 111 | $newsPage = new Page( $this->getOpt( 'news-page-title' ) ); |
112 | 112 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | throw new TaskException( 'Param not found in news page' ); |
120 | 120 | } |
121 | 121 | |
122 | - $newNum = (int)$matches[2] + $amount; |
|
122 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
123 | 123 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
124 | 124 | |
125 | 125 | $summary = $this->msg( 'news-page-summary' ) |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @inheritDoc |
16 | 16 | */ |
17 | - public function runInternal() : int { |
|
17 | + public function runInternal () : int { |
|
18 | 18 | $orderedList = [ |
19 | 19 | 'create-pages', |
20 | 20 | 'open-updates', |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @inheritDoc |
34 | 34 | */ |
35 | - protected function getSubtasksMap() : array { |
|
35 | + protected function getSubtasksMap () : array { |
|
36 | 36 | return [ |
37 | 37 | 'create-pages' => CreatePages::class, |
38 | 38 | 'open-updates' => OpenUpdates::class, |