@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** @var string */ |
33 | 33 | protected $method = self::METHOD_GET; |
34 | 34 | /** @var string[] */ |
35 | - protected $newCookies = []; |
|
35 | + protected $newCookies = [ ]; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @private Use RequestFactory |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param array $params |
41 | 41 | * @param string $domain |
42 | 42 | */ |
43 | - public function __construct( array $params, string $domain ) { |
|
43 | + public function __construct ( array $params, string $domain ) { |
|
44 | 44 | $this->params = [ 'format' => 'json' ] + $params; |
45 | 45 | $this->url = $domain; |
46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return self For chaining |
52 | 52 | */ |
53 | - public function setPost() : self { |
|
53 | + public function setPost () : self { |
|
54 | 54 | $this->method = self::METHOD_POST; |
55 | 55 | return $this; |
56 | 56 | } |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * @todo Return an iterable object which automatically continues the query only if the last |
63 | 63 | * entry available is reached. |
64 | 64 | */ |
65 | - public function execute() : \stdClass { |
|
65 | + public function execute () : \stdClass { |
|
66 | 66 | $curParams = $this->params; |
67 | - $sets = []; |
|
67 | + $sets = [ ]; |
|
68 | 68 | do { |
69 | 69 | $res = $this->makeRequestInternal( $curParams ); |
70 | 70 | |
71 | 71 | $this->handleErrorAndWarnings( $res ); |
72 | - $sets[] = $res; |
|
72 | + $sets[ ] = $res; |
|
73 | 73 | |
74 | 74 | $finished = true; |
75 | 75 | if ( isset( $res->continue ) ) { |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param array $params |
88 | 88 | * @return \stdClass |
89 | 89 | */ |
90 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
90 | + private function makeRequestInternal ( array $params ) : \stdClass { |
|
91 | 91 | if ( $this->method === self::METHOD_POST ) { |
92 | - $params['maxlag'] = self::MAXLAG; |
|
92 | + $params[ 'maxlag' ] = self::MAXLAG; |
|
93 | 93 | } |
94 | 94 | $query = http_build_query( $params ); |
95 | 95 | |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | * @param string $params |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
108 | + abstract protected function reallyMakeRequest ( string $params ) : string; |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * After a request, set cookies for the next ones |
112 | 112 | * |
113 | 113 | * @param array $cookies |
114 | 114 | */ |
115 | - protected function setCookies( array $cookies ) : void { |
|
115 | + protected function setCookies ( array $cookies ) : void { |
|
116 | 116 | foreach ( $cookies as $cookie ) { |
117 | 117 | $bits = explode( ';', $cookie ); |
118 | - [ $name, $value ] = explode( '=', $bits[0] ); |
|
118 | + [ $name, $value ] = explode( '=', $bits[ 0 ] ); |
|
119 | 119 | self::$cookiesToSet[ $name ] = $value; |
120 | 120 | } |
121 | 121 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param \stdClass $res |
127 | 127 | * @return APIRequestException |
128 | 128 | */ |
129 | - private function getException( \stdClass $res ) : APIRequestException { |
|
129 | + private function getException ( \stdClass $res ) : APIRequestException { |
|
130 | 130 | switch ( $res->error->code ) { |
131 | 131 | case 'missingtitle': |
132 | 132 | $ex = new MissingPageException; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param \stdClass $res |
150 | 150 | * @throws APIRequestException |
151 | 151 | */ |
152 | - protected function handleErrorAndWarnings( \stdClass $res ) : void { |
|
152 | + protected function handleErrorAndWarnings ( \stdClass $res ) : void { |
|
153 | 153 | if ( isset( $res->error ) ) { |
154 | 154 | throw $this->getException( $res ); |
155 | 155 | } elseif ( isset( $res->warnings ) ) { |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param \stdClass[] $sets |
166 | 166 | * @return \stdClass |
167 | 167 | */ |
168 | - private function mergeSets( array $sets ) : \stdClass { |
|
168 | + private function mergeSets ( array $sets ) : \stdClass { |
|
169 | 169 | // Use the first set as template |
170 | 170 | $ret = array_shift( $sets ); |
171 | 171 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @param array|\stdClass $second |
183 | 183 | * @return array|\stdClass array |
184 | 184 | */ |
185 | - private function recursiveMerge( $first, $second ) { |
|
185 | + private function recursiveMerge ( $first, $second ) { |
|
186 | 186 | $ret = $first; |
187 | 187 | if ( is_array( $second ) ) { |
188 | 188 | $ret = is_array( $first ) ? array_merge_recursive( $first, $second ) : $second; |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return array |
202 | 202 | */ |
203 | - protected function getHeaders() :array { |
|
203 | + protected function getHeaders () :array { |
|
204 | 204 | $ret = self::HEADERS; |
205 | 205 | if ( self::$cookiesToSet ) { |
206 | - $cookies = []; |
|
206 | + $cookies = [ ]; |
|
207 | 207 | foreach ( self::$cookiesToSet as $cname => $cval ) { |
208 | - $cookies[] = trim( "$cname=$cval" ); |
|
208 | + $cookies[ ] = trim( "$cname=$cval" ); |
|
209 | 209 | } |
210 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
210 | + $ret[ ] = 'Cookie: ' . implode( '; ', $cookies ); |
|
211 | 211 | } |
212 | 212 | return $ret; |
213 | 213 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param array $headers |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - protected function buildHeadersString( array $headers ) : string { |
|
221 | + protected function buildHeadersString ( array $headers ) : string { |
|
222 | 222 | $ret = ''; |
223 | 223 | foreach ( $headers as $header ) { |
224 | 224 | $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 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param MessageProvider $mp |
26 | 26 | * @param PageBotList $pbl |
27 | 27 | */ |
28 | - public function __construct( |
|
28 | + public function __construct ( |
|
29 | 29 | LoggerInterface $logger, |
30 | 30 | WikiGroup $wikiGroup, |
31 | 31 | MessageProvider $mp, |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $mode |
44 | 44 | * @param string|null $name |
45 | 45 | */ |
46 | - private function run( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) : void { |
|
46 | + private function run ( string $mode = TaskManager::MODE_COMPLETE, string $name = null ) : void { |
|
47 | 47 | $activity = $mode === TaskManager::MODE_COMPLETE ? TaskManager::MODE_COMPLETE : "$mode $name"; |
48 | 48 | $this->logger->info( "Running $activity" ); |
49 | 49 | $manager = new TaskManager( |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | $base = "Execution of $activity"; |
57 | 57 | if ( $res->isOK() ) { |
58 | 58 | $msg = $res->getStatus() === TaskResult::STATUS_NOTHING ? |
59 | - ': nothing to do' : |
|
60 | - ' completed successfully'; |
|
59 | + ': nothing to do' : ' completed successfully'; |
|
61 | 60 | $this->logger->info( $base . $msg ); |
62 | 61 | } else { |
63 | 62 | $this->logger->error( "$base failed.\n$res" ); |
@@ -67,7 +66,7 @@ discard block |
||
67 | 66 | /** |
68 | 67 | * Entry point for the whole process |
69 | 68 | */ |
70 | - public function runAll() : void { |
|
69 | + public function runAll () : void { |
|
71 | 70 | $this->run(); |
72 | 71 | } |
73 | 72 | |
@@ -76,7 +75,7 @@ discard block |
||
76 | 75 | * |
77 | 76 | * @param string $task |
78 | 77 | */ |
79 | - public function runTask( string $task ) : void { |
|
78 | + public function runTask ( string $task ) : void { |
|
80 | 79 | $this->run( TaskManager::MODE_TASK, $task ); |
81 | 80 | } |
82 | 81 | |
@@ -85,7 +84,7 @@ discard block |
||
85 | 84 | * |
86 | 85 | * @param string $subtask |
87 | 86 | */ |
88 | - public function runSubtask( string $subtask ) : void { |
|
87 | + public function runSubtask ( string $subtask ) : void { |
|
89 | 88 | $this->run( TaskManager::MODE_SUBTASK, $subtask ); |
90 | 89 | } |
91 | 90 | } |
@@ -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,7 +14,7 @@ discard block |
||
14 | 14 | /** @var User[]|null */ |
15 | 15 | private $processUsers; |
16 | 16 | /** @var PageRiconferma[] */ |
17 | - private $createdPages = []; |
|
17 | + private $createdPages = [ ]; |
|
18 | 18 | /** @var PageRiconferma[]|null */ |
19 | 19 | private $openPages; |
20 | 20 | /** @var PageRiconferma[]|null */ |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return User[] |
27 | 27 | */ |
28 | - public function getUsersToProcess() : array { |
|
28 | + public function getUsersToProcess () : array { |
|
29 | 29 | if ( $this->processUsers === null ) { |
30 | - $this->processUsers = []; |
|
30 | + $this->processUsers = [ ]; |
|
31 | 31 | foreach ( $this->getBotList()->getAdminsList() as $name => $userInfo ) { |
32 | 32 | if ( $this->shouldAddUser( $userInfo ) ) { |
33 | 33 | $this->processUsers[ $name ] = new User( $userInfo, $this->getWiki() ); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param UserInfo $ui |
45 | 45 | * @return bool |
46 | 46 | */ |
47 | - private function shouldAddUser( UserInfo $ui ) : bool { |
|
47 | + private function shouldAddUser ( UserInfo $ui ) : bool { |
|
48 | 48 | $timestamp = $this->getBotList()->getOverrideTimestamp( $ui ); |
49 | 49 | $override = $timestamp !== null; |
50 | 50 | |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return PageRiconferma[] |
64 | 64 | */ |
65 | - public function getOpenPages() : array { |
|
65 | + public function getOpenPages () : array { |
|
66 | 66 | if ( $this->openPages === null ) { |
67 | - $this->openPages = []; |
|
67 | + $this->openPages = [ ]; |
|
68 | 68 | $mainTitle = $this->getOpt( 'main-page-title' ); |
69 | 69 | $params = [ |
70 | 70 | 'action' => 'query', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $pages = $this->getRequestFactory()->newFromParams( $params )->execute()->query->pages; |
79 | 79 | foreach ( reset( $pages )->templates as $page ) { |
80 | 80 | if ( preg_match( "!$titleReg/[^/]+/\d!", $page->title ) ) { |
81 | - $this->openPages[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
81 | + $this->openPages[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return PageRiconferma[] |
93 | 93 | */ |
94 | - public function getPagesToClose() : array { |
|
94 | + public function getPagesToClose () : array { |
|
95 | 95 | if ( $this->pagesToClose === null ) { |
96 | - $this->pagesToClose = []; |
|
96 | + $this->pagesToClose = [ ]; |
|
97 | 97 | foreach ( $this->getOpenPages() as $page ) { |
98 | 98 | if ( time() > $page->getEndTimestamp() ) { |
99 | - $this->pagesToClose[] = $page; |
|
99 | + $this->pagesToClose[ ] = $page; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param string $name |
110 | 110 | */ |
111 | - public function removeUser( string $name ) : void { |
|
111 | + public function removeUser ( string $name ) : void { |
|
112 | 112 | unset( $this->processUsers[ $name ] ); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return PageRiconferma[] |
117 | 117 | */ |
118 | - public function getCreatedPages() : array { |
|
118 | + public function getCreatedPages () : array { |
|
119 | 119 | return $this->createdPages; |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param PageRiconferma $page |
124 | 124 | */ |
125 | - public function addCreatedPage( PageRiconferma $page ) : void { |
|
126 | - $this->createdPages[] = $page; |
|
125 | + public function addCreatedPage ( PageRiconferma $page ) : void { |
|
126 | + $this->createdPages[ ] = $page; |
|
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 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param MessageProvider $mp |
37 | 37 | * @param PageBotList $pbl |
38 | 38 | */ |
39 | - public function __construct( |
|
39 | + public function __construct ( |
|
40 | 40 | LoggerInterface $logger, |
41 | 41 | WikiGroup $wikiGroup, |
42 | 42 | MessageProvider $mp, |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @return LoggerInterface |
54 | 54 | */ |
55 | - protected function getLogger() : LoggerInterface { |
|
55 | + protected function getLogger () : LoggerInterface { |
|
56 | 56 | return $this->logger; |
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @inheritDoc |
61 | 61 | */ |
62 | - public function setLogger( LoggerInterface $logger ) : void { |
|
62 | + public function setLogger ( LoggerInterface $logger ) : void { |
|
63 | 63 | $this->logger = $logger; |
64 | 64 | } |
65 | 65 | |
@@ -69,21 +69,21 @@ discard block |
||
69 | 69 | * @param string $optname |
70 | 70 | * @return mixed |
71 | 71 | */ |
72 | - protected function getOpt( string $optname ) { |
|
72 | + protected function getOpt ( string $optname ) { |
|
73 | 73 | return $this->getConfig()->get( $optname ); |
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @return Config |
78 | 78 | */ |
79 | - protected function getConfig() : Config { |
|
79 | + protected function getConfig () : Config { |
|
80 | 80 | return $this->config; |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * @param Config $cfg |
85 | 85 | */ |
86 | - protected function setConfig( Config $cfg ) : void { |
|
86 | + protected function setConfig ( Config $cfg ) : void { |
|
87 | 87 | $this->config = $cfg; |
88 | 88 | } |
89 | 89 | |
@@ -91,35 +91,35 @@ discard block |
||
91 | 91 | * Shorthand |
92 | 92 | * @return Wiki |
93 | 93 | */ |
94 | - protected function getWiki() : Wiki { |
|
94 | + protected function getWiki () : Wiki { |
|
95 | 95 | return $this->getWikiGroup()->getMainWiki(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @return WikiGroup |
100 | 100 | */ |
101 | - protected function getWikiGroup() : WikiGroup { |
|
101 | + protected function getWikiGroup () : WikiGroup { |
|
102 | 102 | return $this->wikiGroup; |
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * @param WikiGroup $wikiGroup |
107 | 107 | */ |
108 | - protected function setWikiGroup( WikiGroup $wikiGroup ) : void { |
|
108 | + protected function setWikiGroup ( WikiGroup $wikiGroup ) : void { |
|
109 | 109 | $this->wikiGroup = $wikiGroup; |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * @return MessageProvider |
114 | 114 | */ |
115 | - protected function getMessageProvider() : MessageProvider { |
|
115 | + protected function getMessageProvider () : MessageProvider { |
|
116 | 116 | return $this->messageProvider; |
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @param MessageProvider $mp |
121 | 121 | */ |
122 | - protected function setMessageProvider( MessageProvider $mp ) : void { |
|
122 | + protected function setMessageProvider ( MessageProvider $mp ) : void { |
|
123 | 123 | $this->messageProvider = $mp; |
124 | 124 | } |
125 | 125 | |
@@ -129,21 +129,21 @@ discard block |
||
129 | 129 | * @param string $key |
130 | 130 | * @return Message |
131 | 131 | */ |
132 | - protected function msg( string $key ) : Message { |
|
132 | + protected function msg ( string $key ) : Message { |
|
133 | 133 | return $this->messageProvider->getMessage( $key ); |
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @return PageBotList |
138 | 138 | */ |
139 | - public function getBotList() : PageBotList { |
|
139 | + public function getBotList () : PageBotList { |
|
140 | 140 | return $this->pageBotList; |
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | 144 | * @return RequestFactory |
145 | 145 | */ |
146 | - public function getRequestFactory() : RequestFactory { |
|
146 | + public function getRequestFactory () : RequestFactory { |
|
147 | 147 | return $this->getWiki()->getRequestFactory(); |
148 | 148 | } |
149 | 149 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $title |
154 | 154 | * @return Page |
155 | 155 | */ |
156 | - protected function getPage( string $title ) : Page { |
|
156 | + protected function getPage ( string $title ) : Page { |
|
157 | 157 | return new Page( $title, $this->getWiki() ); |
158 | 158 | } |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string $name |
164 | 164 | * @return User |
165 | 165 | */ |
166 | - protected function getUser( string $name ) : User { |
|
166 | + protected function getUser ( string $name ) : User { |
|
167 | 167 | $ui = $this->getBotList()->getUserInfo( $name ); |
168 | 168 | return new User( $ui, $this->getWiki() ); |
169 | 169 | } |
@@ -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; |
4 | 4 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param string $name |
18 | 18 | * @param array $info |
19 | 19 | */ |
20 | - public function __construct( string $name, array $info ) { |
|
20 | + public function __construct ( string $name, array $info ) { |
|
21 | 21 | $this->name = $name; |
22 | 22 | $this->info = $info; |
23 | 23 | } |
@@ -25,35 +25,35 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public function getName() : string { |
|
28 | + public function getName () : string { |
|
29 | 29 | return $this->name; |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - public function getInfo() : array { |
|
35 | + public function getInfo () : array { |
|
36 | 36 | return $this->info; |
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @return array |
41 | 41 | */ |
42 | - public function extractGroups() : array { |
|
42 | + public function extractGroups () : array { |
|
43 | 43 | return array_keys( $this->extractGroupsWithDates() ); |
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return array |
48 | 48 | */ |
49 | - public function extractGroupsWithDates() : array { |
|
49 | + public function extractGroupsWithDates () : array { |
|
50 | 50 | return array_intersect_key( $this->getInfo(), array_fill_keys( self::GROUP_KEYS, 1 ) ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - public function getAliases() : array { |
|
57 | - return $this->getInfo()['aliases'] ?? []; |
|
56 | + public function getAliases () : array { |
|
57 | + return $this->getInfo()[ 'aliases' ] ?? [ ]; |
|
58 | 58 | } |
59 | 59 | } |
@@ -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 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | private $supportSection; |
13 | 13 | private $opposeSection; |
14 | 14 | /** @var array Counts of votes for each section */ |
15 | - private $sectionCounts = []; |
|
15 | + private $sectionCounts = [ ]; |
|
16 | 16 | |
17 | 17 | // Possible outcomes of a vote |
18 | 18 | public 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() : void { |
|
34 | + private function defineSections () : void { |
|
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 string |
43 | 43 | */ |
44 | - public function getUserName() : string { |
|
45 | - return explode( '/', $this->title )[2]; |
|
44 | + public function getUserName () : string { |
|
45 | + return explode( '/', $this->title )[ 2 ]; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return int |
52 | 52 | */ |
53 | - public function getNum() : int { |
|
53 | + public function getNum () : int { |
|
54 | 54 | $bits = explode( '/', $this->getTitle() ); |
55 | 55 | return (int)end( $bits ); |
56 | 56 | } |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function getUserNum() : string { |
|
64 | - return explode( '/', $this->getTitle(), 3 )[2]; |
|
63 | + public function getUserNum () : string { |
|
64 | + return explode( '/', $this->getTitle(), 3 )[ 2 ]; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return int |
71 | 71 | */ |
72 | - public function getOpposingCount() : int { |
|
72 | + public function getOpposingCount () : int { |
|
73 | 73 | $this->defineSections(); |
74 | 74 | return $this->getCountForSection( $this->opposeSection ); |
75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return int |
81 | 81 | * @throws \BadMethodCallException |
82 | 82 | */ |
83 | - public function getSupportCount() : int { |
|
83 | + public function getSupportCount () : int { |
|
84 | 84 | if ( !$this->isVote() ) { |
85 | 85 | throw new \BadMethodCallException( 'Cannot get support for a non-vote page.' ); |
86 | 86 | } |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | * @param int $secNum |
95 | 95 | * @return int |
96 | 96 | */ |
97 | - protected function getCountForSection( int $secNum ) : int { |
|
97 | + protected function getCountForSection ( int $secNum ) : int { |
|
98 | 98 | if ( !isset( $this->sectionCounts[ $secNum ] ) ) { |
99 | 99 | $content = $this->wiki->getPageContent( $this->title, $secNum ); |
100 | 100 | // Let's hope that this is good enough... |
101 | - $this->sectionCounts[$secNum] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
101 | + $this->sectionCounts[ $secNum ] = preg_match_all( "/^# *(?![# *:]|\.\.\.$)/m", $content ); |
|
102 | 102 | } |
103 | - return $this->sectionCounts[$secNum]; |
|
103 | + return $this->sectionCounts[ $secNum ]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return int |
110 | 110 | */ |
111 | - protected function getQuorum() : int { |
|
111 | + protected function getQuorum () : int { |
|
112 | 112 | $reg = "!soddisfare il \[\[[^|\]]+\|quorum]] di '''(\d+) voti'''!"; |
113 | - return (int)$this->getMatch( $reg )[1]; |
|
113 | + return (int)$this->getMatch( $reg )[ 1 ]; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public function hasOpposition() : bool { |
|
121 | + public function hasOpposition () : bool { |
|
122 | 122 | return $this->getOpposingCount() >= self::REQUIRED_OPPOSE; |
123 | 123 | } |
124 | 124 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @return int One of the OUTCOME_* constants |
129 | 129 | */ |
130 | - public function getOutcome() : int { |
|
130 | + public function getOutcome () : int { |
|
131 | 131 | if ( !$this->isVote() ) { |
132 | 132 | return self::OUTCOME_OK; |
133 | 133 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @throws \BadMethodCallException |
151 | 151 | * @throws \LogicException |
152 | 152 | */ |
153 | - public function getOutcomeText() : string { |
|
153 | + public function getOutcomeText () : string { |
|
154 | 154 | if ( !$this->isVote() ) { |
155 | 155 | throw new \BadMethodCallException( 'No need for an outcome text.' ); |
156 | 156 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return bool |
186 | 186 | */ |
187 | - public function isVote() : bool { |
|
187 | + public function isVote () : bool { |
|
188 | 188 | $sectionReg = '/<!-- SEZIONE DA UTILIZZARE PER/'; |
189 | 189 | return !$this->matches( $sectionReg ); |
190 | 190 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return int |
196 | 196 | */ |
197 | - public function getCreationTimestamp() : int { |
|
197 | + public function getCreationTimestamp () : int { |
|
198 | 198 | return $this->wiki->getPageCreationTS( $this->title ); |
199 | 199 | } |
200 | 200 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return int |
205 | 205 | */ |
206 | - public function getEndTimestamp() : int { |
|
206 | + public function getEndTimestamp () : int { |
|
207 | 207 | if ( $this->isVote() ) { |
208 | 208 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
209 | 209 | [ , $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 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string $title |
22 | 22 | * @param Wiki $wiki For the site where the page lives |
23 | 23 | */ |
24 | - public function __construct( string $title, Wiki $wiki ) { |
|
24 | + public function __construct ( string $title, Wiki $wiki ) { |
|
25 | 25 | $this->wiki = $wiki; |
26 | 26 | $this->title = $title; |
27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function getTitle() : string { |
|
32 | + public function getTitle () : string { |
|
33 | 33 | return $this->title; |
34 | 34 | } |
35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param int|null $section A section number to retrieve the content of that section |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - public function getContent( int $section = null ) : string { |
|
42 | + public function getContent ( int $section = null ) : string { |
|
43 | 43 | if ( $this->content === null ) { |
44 | 44 | $this->content = $this->wiki->getPageContent( $this->title, $section ); |
45 | 45 | } |
@@ -52,18 +52,18 @@ discard block |
||
52 | 52 | * @param array $params |
53 | 53 | * @throws \LogicException |
54 | 54 | */ |
55 | - public function edit( array $params ) : void { |
|
55 | + public function edit ( array $params ) : void { |
|
56 | 56 | $params = [ |
57 | 57 | 'title' => $this->getTitle() |
58 | 58 | ] + $params; |
59 | 59 | |
60 | 60 | $this->wiki->editPage( $params ); |
61 | - if ( isset( $params['text'] ) ) { |
|
62 | - $this->content = $params['text']; |
|
63 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
64 | - $this->content .= $params['appendtext']; |
|
65 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
66 | - $this->content = $params['prependtext'] . $this->content; |
|
61 | + if ( isset( $params[ 'text' ] ) ) { |
|
62 | + $this->content = $params[ 'text' ]; |
|
63 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
64 | + $this->content .= $params[ 'appendtext' ]; |
|
65 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
66 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
67 | 67 | } else { |
68 | 68 | throw new \LogicException( |
69 | 69 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function exists() : bool { |
|
79 | + public function exists () : bool { |
|
80 | 80 | $res = $this->wiki->getRequestFactory()->newFromParams( [ |
81 | 81 | 'action' => 'query', |
82 | 82 | 'titles' => $this->getTitle() |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param string $regex |
92 | 92 | * @return bool |
93 | 93 | */ |
94 | - public function matches( string $regex ) : bool { |
|
94 | + public function matches ( string $regex ) : bool { |
|
95 | 95 | return (bool)preg_match( $regex, $this->getContent() ); |
96 | 96 | } |
97 | 97 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @return string[] |
104 | 104 | * @throws MissingMatchException |
105 | 105 | */ |
106 | - public function getMatch( string $regex ) : array { |
|
107 | - $ret = []; |
|
106 | + public function getMatch ( string $regex ) : array { |
|
107 | + $ret = [ ]; |
|
108 | 108 | if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { |
109 | 109 | throw new MissingMatchException( "The content of $this does not match the given regex $regex" ); |
110 | 110 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @inheritDoc |
118 | 118 | */ |
119 | - public function getRegex( string $delimiter = '/' ) : string { |
|
119 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
120 | 120 | return str_replace( ' ', '[ _]', preg_quote( $this->title, $delimiter ) ); |
121 | 121 | } |
122 | 122 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public function __toString() { |
|
128 | + public function __toString () { |
|
129 | 129 | return $this->getTitle(); |
130 | 130 | } |
131 | 131 | } |
@@ -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 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param string $listTitle |
20 | 20 | * @param Wiki $wiki |
21 | 21 | */ |
22 | - public function __construct( string $listTitle, Wiki $wiki ) { |
|
22 | + public function __construct ( string $listTitle, Wiki $wiki ) { |
|
23 | 23 | parent::__construct( $listTitle, $wiki ); |
24 | 24 | } |
25 | 25 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string $listTitle |
31 | 31 | * @return self |
32 | 32 | */ |
33 | - public static function get( Wiki $wiki, string $listTitle ) : self { |
|
33 | + public static function get ( Wiki $wiki, string $listTitle ) : self { |
|
34 | 34 | static $instance = null; |
35 | 35 | if ( $instance === null ) { |
36 | 36 | $instance = new self( $listTitle, $wiki ); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param UserInfo $ui |
43 | 43 | * @return int|null |
44 | 44 | */ |
45 | - public function getOverrideTimestamp( UserInfo $ui ) : ?int { |
|
45 | + public function getOverrideTimestamp ( UserInfo $ui ) : ?int { |
|
46 | 46 | $info = $ui->getInfo(); |
47 | 47 | if ( !array_intersect_key( $info, [ 'override-perm' => true, 'override' => true ] ) ) { |
48 | 48 | return null; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | // A one-time override takes precedence |
52 | 52 | if ( array_key_exists( 'override', $info ) ) { |
53 | - $date = $info['override']; |
|
53 | + $date = $info[ 'override' ]; |
|
54 | 54 | } else { |
55 | - $date = $info['override-prem'] . '/' . date( 'Y' ); |
|
55 | + $date = $info[ 'override-prem' ] . '/' . date( 'Y' ); |
|
56 | 56 | } |
57 | 57 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
58 | 58 | } |
@@ -63,17 +63,17 @@ discard block |
||
63 | 63 | * @param string $user |
64 | 64 | * @return int |
65 | 65 | */ |
66 | - public function getNextTimestamp( string $user ) : int { |
|
66 | + public function getNextTimestamp ( string $user ) : int { |
|
67 | 67 | $userInfo = $this->getUserInfo( $user )->getInfo(); |
68 | - if ( isset( $userInfo['override-perm'] ) ) { |
|
68 | + if ( isset( $userInfo[ 'override-perm' ] ) ) { |
|
69 | 69 | $date = \DateTime::createFromFormat( |
70 | 70 | 'd/m/Y', |
71 | - $userInfo['override-perm'] . '/' . date( 'Y' ) |
|
71 | + $userInfo[ 'override-perm' ] . '/' . date( 'Y' ) |
|
72 | 72 | ); |
73 | 73 | } else { |
74 | 74 | $date = null; |
75 | - if ( isset( $userInfo['override'] ) ) { |
|
76 | - $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo['override'] ); |
|
75 | + if ( isset( $userInfo[ 'override' ] ) ) { |
|
76 | + $date = \DateTime::createFromFormat( 'd/m/Y', $userInfo[ 'override' ] ); |
|
77 | 77 | } |
78 | 78 | if ( !$date || $date <= new \DateTime ) { |
79 | 79 | $ts = self::getValidFlagTimestamp( $userInfo ); |
@@ -92,17 +92,15 @@ discard block |
||
92 | 92 | * @param array $groups |
93 | 93 | * @return int |
94 | 94 | */ |
95 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
96 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
97 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
98 | - 0; |
|
99 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
100 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
101 | - 0; |
|
95 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
96 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
97 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
98 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
99 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
102 | 100 | |
103 | 101 | $timestamp = max( $bureaucrat, $checkuser ); |
104 | 102 | if ( $timestamp === 0 ) { |
105 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
103 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
106 | 104 | } |
107 | 105 | return $timestamp; |
108 | 106 | } |
@@ -111,14 +109,14 @@ discard block |
||
111 | 109 | * @param array $groups |
112 | 110 | * @return bool |
113 | 111 | */ |
114 | - public static function isOverrideExpired( array $groups ) : bool { |
|
115 | - if ( !isset( $groups['override'] ) ) { |
|
112 | + public static function isOverrideExpired ( array $groups ) : bool { |
|
113 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
116 | 114 | return false; |
117 | 115 | } |
118 | 116 | |
119 | 117 | $flagTS = self::getValidFlagTimestamp( $groups ); |
120 | 118 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
121 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
119 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
122 | 120 | $delay = 60 * 60 * 24 * 3; |
123 | 121 | |
124 | 122 | return time() > $usualTS + $delay && time() > $overrideTS + $delay; |
@@ -129,9 +127,9 @@ discard block |
||
129 | 127 | * |
130 | 128 | * @return UserInfo[] |
131 | 129 | */ |
132 | - public function getAdminsList() : array { |
|
130 | + public function getAdminsList () : array { |
|
133 | 131 | if ( $this->adminsList === null ) { |
134 | - $this->adminsList = []; |
|
132 | + $this->adminsList = [ ]; |
|
135 | 133 | foreach ( $this->getDecodedContent() as $user => $info ) { |
136 | 134 | $this->adminsList[ $user ] = new UserInfo( $user, $info ); |
137 | 135 | } |
@@ -143,8 +141,8 @@ discard block |
||
143 | 141 | * @param string $user |
144 | 142 | * @return UserInfo |
145 | 143 | */ |
146 | - public function getUserInfo( string $user ) : UserInfo { |
|
147 | - return $this->getAdminsList()[$user]; |
|
144 | + public function getUserInfo ( string $user ) : UserInfo { |
|
145 | + return $this->getAdminsList()[ $user ]; |
|
148 | 146 | } |
149 | 147 | |
150 | 148 | /** |
@@ -152,7 +150,7 @@ discard block |
||
152 | 150 | * |
153 | 151 | * @return array[] |
154 | 152 | */ |
155 | - public function getDecodedContent() : array { |
|
153 | + public function getDecodedContent () : array { |
|
156 | 154 | return json_decode( $this->getContent(), true ); |
157 | 155 | } |
158 | 156 | } |
@@ -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; |
4 | 4 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param UserInfo $ui |
22 | 22 | * @param Wiki $wiki |
23 | 23 | */ |
24 | - public function __construct( UserInfo $ui, Wiki $wiki ) { |
|
24 | + public function __construct ( UserInfo $ui, Wiki $wiki ) { |
|
25 | 25 | $this->wiki = $wiki; |
26 | 26 | $this->name = $ui->getName(); |
27 | 27 | $this->ui = $ui; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function getName() : string { |
|
33 | + public function getName () : string { |
|
34 | 34 | return $this->name; |
35 | 35 | } |
36 | 36 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @return string[] |
41 | 41 | */ |
42 | - public function getGroups() : array { |
|
42 | + public function getGroups () : array { |
|
43 | 43 | return $this->ui->extractGroups(); |
44 | 44 | } |
45 | 45 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string[] [ group => date ] |
50 | 50 | */ |
51 | - public function getGroupsWithDates() : array { |
|
51 | + public function getGroupsWithDates () : array { |
|
52 | 52 | return $this->ui->extractGroupsWithDates(); |
53 | 53 | } |
54 | 54 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param string $groupName |
59 | 59 | * @return bool |
60 | 60 | */ |
61 | - public function inGroup( string $groupName ) : bool { |
|
61 | + public function inGroup ( string $groupName ) : bool { |
|
62 | 62 | return in_array( $groupName, $this->getGroups(), true ); |
63 | 63 | } |
64 | 64 | |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @inheritDoc |
69 | 69 | */ |
70 | - public function getRegex( string $delimiter = '/' ) : string { |
|
70 | + public function getRegex ( string $delimiter = '/' ) : string { |
|
71 | 71 | $bits = $this->getAliases(); |
72 | - $bits[] = $this->name; |
|
72 | + $bits[ ] = $this->name; |
|
73 | 73 | $regexify = static function ( $el ) use ( $delimiter ) { |
74 | 74 | return str_replace( ' ', '[ _]', preg_quote( $el, $delimiter ) ); |
75 | 75 | }; |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return string[] |
83 | 83 | */ |
84 | - public function getAliases() : array { |
|
84 | + public function getAliases () : array { |
|
85 | 85 | return $this->ui->getAliases(); |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return Page |
90 | 90 | */ |
91 | - public function getTalkPage() : Page { |
|
91 | + public function getTalkPage () : Page { |
|
92 | 92 | return new Page( "User talk:{$this->name}", $this->wiki ); |
93 | 93 | } |
94 | 94 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * Get the default base page, e.g. WP:A/Riconferma annuale/XXX |
97 | 97 | * @return Page |
98 | 98 | */ |
99 | - public function getBasePage() : Page { |
|
99 | + public function getBasePage () : Page { |
|
100 | 100 | $prefix = Config::getInstance()->get( 'main-page-title' ); |
101 | 101 | return new Page( "$prefix/$this", $this->wiki ); |
102 | 102 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @throws MissingPageException |
109 | 109 | * @return Page |
110 | 110 | */ |
111 | - public function getExistingBasePage() : Page { |
|
111 | + public function getExistingBasePage () : Page { |
|
112 | 112 | $basePage = $this->getBasePage(); |
113 | 113 | if ( !$basePage->exists() ) { |
114 | 114 | $basePage = null; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function __toString() { |
|
135 | + public function __toString () { |
|
136 | 136 | return $this->name; |
137 | 137 | } |
138 | 138 | } |