@@ -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 | |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | /** @var string Used for logging */ |
32 | 32 | private $pagePrefix = ''; |
33 | 33 | /** @var string[] */ |
34 | - private $cookies = []; |
|
34 | + private $cookies = [ ]; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param LoginInfo $li |
38 | 38 | * @param LoggerInterface $logger |
39 | 39 | * @param RequestFactory $requestFactory |
40 | 40 | */ |
41 | - public function __construct( |
|
41 | + public function __construct ( |
|
42 | 42 | LoginInfo $li, |
43 | 43 | LoggerInterface $logger, |
44 | 44 | RequestFactory $requestFactory |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @return LoginInfo |
53 | 53 | */ |
54 | - public function getLoginInfo(): LoginInfo { |
|
54 | + public function getLoginInfo (): LoginInfo { |
|
55 | 55 | return $this->loginInfo; |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return RequestFactory |
60 | 60 | */ |
61 | - public function getRequestFactory(): RequestFactory { |
|
61 | + public function getRequestFactory (): RequestFactory { |
|
62 | 62 | return $this->requestFactory; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @param string $prefix |
67 | 67 | */ |
68 | - public function setPagePrefix( string $prefix ): void { |
|
68 | + public function setPagePrefix ( string $prefix ): void { |
|
69 | 69 | $this->pagePrefix = $prefix; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @param string $ident |
74 | 74 | */ |
75 | - public function setLocalUserIdentifier( string $ident ): void { |
|
75 | + public function setLocalUserIdentifier ( string $ident ): void { |
|
76 | 76 | $this->localUserIdentifier = $ident; |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - public function getLocalUserIdentifier(): string { |
|
82 | + public function getLocalUserIdentifier (): string { |
|
83 | 83 | return $this->localUserIdentifier; |
84 | 84 | } |
85 | 85 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string $title |
88 | 88 | * @param int|null $section |
89 | 89 | */ |
90 | - private function logRead( string $title, int $section = null ): void { |
|
90 | + private function logRead ( string $title, int $section = null ): void { |
|
91 | 91 | $fullTitle = $this->pagePrefix . $title; |
92 | 92 | $msg = "Retrieving content of $fullTitle" . ( $section !== null ? ", section $section" : '' ); |
93 | 93 | $this->logger->info( $msg ); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @throws MissingPageException |
103 | 103 | * @throws MissingSectionException |
104 | 104 | */ |
105 | - public function getPageContent( string $title, int $section = null ): string { |
|
105 | + public function getPageContent ( string $title, int $section = null ): string { |
|
106 | 106 | $this->logRead( $title, $section ); |
107 | 107 | $params = [ |
108 | 108 | 'action' => 'query', |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ]; |
114 | 114 | |
115 | 115 | if ( $section !== null ) { |
116 | - $params['rvsection'] = $section; |
|
116 | + $params[ 'rvsection' ] = $section; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | $req = $this->buildRequest( $params ); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | throw new MissingPageException( $title ); |
123 | 123 | } |
124 | 124 | |
125 | - $mainSlot = $page->revisions[0]->slots->main; |
|
125 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
126 | 126 | |
127 | 127 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
128 | 128 | throw new MissingSectionException( $title, $section ); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @phan-param array<int|string|bool> $params |
138 | 138 | * @throws EditException |
139 | 139 | */ |
140 | - public function editPage( array $params ): void { |
|
140 | + public function editPage ( array $params ): void { |
|
141 | 141 | $this->login(); |
142 | 142 | |
143 | 143 | $params = [ |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ] + $params; |
147 | 147 | |
148 | 148 | if ( BOT_EDITS === true ) { |
149 | - $params['bot'] = 1; |
|
149 | + $params[ 'bot' ] = 1; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $res = $this->buildRequest( $params )->setPost()->executeSingle(); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
165 | 165 | * @throws LoginException |
166 | 166 | */ |
167 | - public function login(): void { |
|
167 | + public function login (): void { |
|
168 | 168 | if ( $this->loginInfo === null ) { |
169 | 169 | throw new CannotLoginException( 'Missing login data' ); |
170 | 170 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | $this->loggedIn = true; |
196 | 196 | // Clear tokens cache |
197 | - $this->tokens = []; |
|
197 | + $this->tokens = [ ]; |
|
198 | 198 | $this->logger->info( 'Login succeeded' ); |
199 | 199 | } |
200 | 200 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param string $type |
205 | 205 | * @return string |
206 | 206 | */ |
207 | - public function getToken( string $type ): string { |
|
207 | + public function getToken ( string $type ): string { |
|
208 | 208 | if ( !isset( $this->tokens[ $type ] ) ) { |
209 | 209 | $params = [ |
210 | 210 | 'action' => 'query', |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @param string $title |
225 | 225 | * @return int |
226 | 226 | */ |
227 | - public function getPageCreationTS( string $title ): int { |
|
227 | + public function getPageCreationTS ( string $title ): int { |
|
228 | 228 | $params = [ |
229 | 229 | 'action' => 'query', |
230 | 230 | 'prop' => 'revisions', |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | ]; |
237 | 237 | |
238 | 238 | $page = $this->buildRequest( $params )->executeAsQuery()->current(); |
239 | - return strtotime( $page->revisions[0]->timestamp ); |
|
239 | + return strtotime( $page->revisions[ 0 ]->timestamp ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param string $title |
246 | 246 | * @param string $reason |
247 | 247 | */ |
248 | - public function protectPage( string $title, string $reason ): void { |
|
248 | + public function protectPage ( string $title, string $reason ): void { |
|
249 | 249 | $fullTitle = $this->pagePrefix . $title; |
250 | 250 | $this->logger->info( "Protecting page $fullTitle" ); |
251 | 251 | $this->login(); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @param string $username |
269 | 269 | * @param string $reason |
270 | 270 | */ |
271 | - public function blockUser( string $username, string $reason ): void { |
|
271 | + public function blockUser ( string $username, string $reason ): void { |
|
272 | 272 | $this->logger->info( "Blocking user $username" ); |
273 | 273 | $this->login(); |
274 | 274 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @phan-param array<int|string|bool> $params |
296 | 296 | * @return RequestBase |
297 | 297 | */ |
298 | - private function buildRequest( array $params ): RequestBase { |
|
298 | + private function buildRequest ( array $params ): RequestBase { |
|
299 | 299 | return $this->requestFactory->createRequest( |
300 | 300 | $params, |
301 | 301 | $this->cookies, |