@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param LoggerInterface $logger |
29 | 29 | * @param string $domain The URL of the wiki, if different from default |
30 | 30 | */ |
31 | - public function __construct( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
31 | + public function __construct ( LoggerInterface $logger, string $domain = DEFAULT_URL ) { |
|
32 | 32 | $this->logger = $logger; |
33 | 33 | $this->domain = $domain; |
34 | 34 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @throws MissingPageException |
43 | 43 | * @throws MissingSectionException |
44 | 44 | */ |
45 | - public function getPageContent( string $title, int $section = null ) : string { |
|
45 | + public function getPageContent ( string $title, int $section = null ) : string { |
|
46 | 46 | $msg = "Retrieving content of $title" . ( $section !== null ? ", section $section" : '' ); |
47 | 47 | $this->logger->debug( $msg ); |
48 | 48 | $params = [ |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ]; |
55 | 55 | |
56 | 56 | if ( $section !== null ) { |
57 | - $params['rvsection'] = $section; |
|
57 | + $params[ 'rvsection' ] = $section; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $req = $this->buildRequest( $params ); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | throw new MissingPageException( $title ); |
65 | 65 | } |
66 | 66 | |
67 | - $mainSlot = $page->revisions[0]->slots->main; |
|
67 | + $mainSlot = $page->revisions[ 0 ]->slots->main; |
|
68 | 68 | |
69 | 69 | // @phan-suppress-next-line PhanImpossibleTypeComparison $section can be null |
70 | 70 | if ( $section !== null && isset( $mainSlot->nosuchsection ) ) { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param array $params |
80 | 80 | * @throws EditException |
81 | 81 | */ |
82 | - public function editPage( array $params ) { |
|
82 | + public function editPage ( array $params ) { |
|
83 | 83 | $this->login(); |
84 | 84 | |
85 | 85 | $params = [ |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ] + $params; |
89 | 89 | |
90 | 90 | if ( Config::getInstance()->get( 'bot-edits' ) ) { |
91 | - $params['bot'] = 1; |
|
91 | + $params[ 'bot' ] = 1; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $res = $this->buildRequest( $params )->setPost()->execute(); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * Login wrapper. Checks if we're already logged in and clears tokens cache |
107 | 107 | * @throws LoginException |
108 | 108 | */ |
109 | - public function login() { |
|
109 | + public function login () { |
|
110 | 110 | if ( self::$loggedIn ) { |
111 | 111 | return; |
112 | 112 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | self::$loggedIn = true; |
135 | 135 | // Clear tokens cache |
136 | - $this->tokens = []; |
|
136 | + $this->tokens = [ ]; |
|
137 | 137 | $this->logger->info( 'Login succeeded' ); |
138 | 138 | } |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $type |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - public function getToken( string $type ) : string { |
|
146 | + public function getToken ( string $type ) : string { |
|
147 | 147 | if ( !isset( $this->tokens[ $type ] ) ) { |
148 | 148 | $params = [ |
149 | 149 | 'action' => 'query', |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $title |
167 | 167 | * @return int |
168 | 168 | */ |
169 | - public function getPageCreationTS( string $title ) : int { |
|
169 | + public function getPageCreationTS ( string $title ) : int { |
|
170 | 170 | $params = [ |
171 | 171 | 'action' => 'query', |
172 | 172 | 'prop' => 'revisions', |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $res = $this->buildRequest( $params )->execute(); |
181 | 181 | $data = $res->query->pages; |
182 | - return strtotime( reset( $data )->revisions[0]->timestamp ); |
|
182 | + return strtotime( reset( $data )->revisions[ 0 ]->timestamp ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param string $title |
189 | 189 | * @param string $reason |
190 | 190 | */ |
191 | - public function protectPage( string $title, string $reason ) { |
|
191 | + public function protectPage ( string $title, string $reason ) { |
|
192 | 192 | $this->logger->info( "Protecting page $title" ); |
193 | 193 | $this->login(); |
194 | 194 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param array $params |
210 | 210 | * @return RequestBase |
211 | 211 | */ |
212 | - private function buildRequest( array $params ) : RequestBase { |
|
212 | + private function buildRequest ( array $params ) : RequestBase { |
|
213 | 213 | return RequestBase::newFromParams( $params )->setUrl( $this->domain ); |
214 | 214 | } |
215 | 215 | } |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** @var self */ |
14 | 14 | private static $instance; |
15 | 15 | /** @var array */ |
16 | - private $opts = []; |
|
16 | + private $opts = [ ]; |
|
17 | 17 | /** @var array|null Lazy-loaded to avoid unnecessary requests */ |
18 | 18 | private $messages; |
19 | 19 | /** @var Wiki */ |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param Wiki $wiki |
26 | 26 | */ |
27 | - private function __construct( Wiki $wiki ) { |
|
27 | + private function __construct ( Wiki $wiki ) { |
|
28 | 28 | $this->wiki = $wiki; |
29 | 29 | } |
30 | 30 | |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @param Wiki $wiki |
36 | 36 | * @throws ConfigException |
37 | 37 | */ |
38 | - public static function init( array $defaults, Wiki $wiki ) { |
|
38 | + public static function init ( array $defaults, Wiki $wiki ) { |
|
39 | 39 | if ( self::$instance ) { |
40 | 40 | throw new ConfigException( 'Config was already initialized' ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | $inst = new self( $wiki ); |
44 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
45 | - $inst->set( 'msg-title', $defaults['msg-title'] ); |
|
46 | - $inst->set( 'username', $defaults['username'] ); |
|
47 | - $inst->set( 'password', $defaults['password'] ); |
|
44 | + $inst->set( 'list-title', $defaults[ 'list-title' ] ); |
|
45 | + $inst->set( 'msg-title', $defaults[ 'msg-title' ] ); |
|
46 | + $inst->set( 'username', $defaults[ 'username' ] ); |
|
47 | + $inst->set( 'password', $defaults[ 'password' ] ); |
|
48 | 48 | |
49 | 49 | // On-wiki values |
50 | 50 | try { |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return string |
65 | 65 | * @throws ConfigException |
66 | 66 | */ |
67 | - public function getWikiMessage( string $key ) : string { |
|
67 | + public function getWikiMessage ( string $key ) : string { |
|
68 | 68 | if ( $this->messages === null ) { |
69 | 69 | try { |
70 | 70 | $cont = $this->wiki->getPageContent( $this->opts[ 'msg-title' ] ); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | if ( !isset( $this->messages[ $key ] ) ) { |
77 | 77 | throw new ConfigException( "Message '$key' does not exist." ); |
78 | 78 | } |
79 | - return $this->messages[$key]; |
|
79 | + return $this->messages[ $key ]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $key |
86 | 86 | * @param mixed $value |
87 | 87 | */ |
88 | - protected function set( string $key, $value ) { |
|
88 | + protected function set ( string $key, $value ) { |
|
89 | 89 | $this->opts[ $key ] = $value; |
90 | 90 | } |
91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return self |
96 | 96 | * @throws ConfigException |
97 | 97 | */ |
98 | - public static function getInstance() : self { |
|
98 | + public static function getInstance () : self { |
|
99 | 99 | if ( !self::$instance ) { |
100 | 100 | throw new ConfigException( 'Config not yet initialized' ); |
101 | 101 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return mixed |
110 | 110 | * @throws ConfigException |
111 | 111 | */ |
112 | - public function get( string $opt ) { |
|
112 | + public function get ( string $opt ) { |
|
113 | 113 | if ( !isset( $this->opts[ $opt ] ) ) { |
114 | 114 | throw new ConfigException( "Config option '$opt' not set." ); |
115 | 115 | } |