@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @inheritDoc |
18 | 18 | */ |
19 | - public function runInternal() : int { |
|
19 | + public function runInternal () : int { |
|
20 | 20 | $failed = $this->getFailures(); |
21 | 21 | if ( $failed ) { |
22 | 22 | $bureaucrats = $this->getFailedBureaucrats( $failed ); |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return PageRiconferma[] |
38 | 38 | */ |
39 | - private function getFailures() : array { |
|
40 | - $ret = []; |
|
39 | + private function getFailures () : array { |
|
40 | + $ret = [ ]; |
|
41 | 41 | $allPages = $this->getDataProvider()->getPagesToClose(); |
42 | 42 | foreach ( $allPages as $page ) { |
43 | 43 | if ( $page->getOutcome() & PageRiconferma::OUTCOME_FAIL ) { |
44 | - $ret[] = $page; |
|
44 | + $ret[ ] = $page; |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | return $ret; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @param User[] $users |
52 | 52 | */ |
53 | - protected function updateBurList( array $users ) { |
|
53 | + protected function updateBurList ( array $users ) { |
|
54 | 54 | $this->getLogger()->info( 'Updating bur list. Removing: ' . implode( ', ', $users ) ); |
55 | 55 | $remList = Element::regexFromArray( $users ); |
56 | 56 | $burList = new Page( $this->getConfig()->get( 'bur-list-title' ) ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @param PageRiconferma[] $pages |
75 | 75 | */ |
76 | - protected function requestRemoval( array $pages ) { |
|
76 | + protected function requestRemoval ( array $pages ) { |
|
77 | 77 | $this->getLogger()->info( 'Requesting flag removal for: ' . implode( ', ', $pages ) ); |
78 | 78 | |
79 | 79 | $flagRemPage = new Page( |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param PageRiconferma[] $pages |
111 | 111 | */ |
112 | - protected function updateAnnunci( array $pages ) { |
|
112 | + protected function updateAnnunci ( array $pages ) { |
|
113 | 113 | $this->getLogger()->info( 'Updating annunci' ); |
114 | 114 | $section = 1; |
115 | 115 | |
116 | - $names = []; |
|
116 | + $names = [ ]; |
|
117 | 117 | $text = ''; |
118 | 118 | foreach ( $pages as $page ) { |
119 | 119 | $user = $page->getUser()->getName(); |
120 | - $names[] = $user; |
|
120 | + $names[ ] = $user; |
|
121 | 121 | $text .= $this->msg( 'annunci-text' )->params( [ '$user' => $user ] )->text(); |
122 | 122 | } |
123 | 123 | |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param PageRiconferma[] $pages |
151 | 151 | */ |
152 | - protected function updateUltimeNotizie( array $pages ) { |
|
152 | + protected function updateUltimeNotizie ( array $pages ) { |
|
153 | 153 | $this->getLogger()->info( 'Updating ultime notizie' ); |
154 | 154 | $notiziePage = new Page( $this->getConfig()->get( 'ultimenotizie-page-title' ) ); |
155 | 155 | |
156 | - $names = []; |
|
156 | + $names = [ ]; |
|
157 | 157 | $text = ''; |
158 | 158 | $msg = $this->msg( 'ultimenotizie-text' ); |
159 | 159 | foreach ( $pages as $page ) { |
160 | 160 | $user = $page->getUser()->getName(); |
161 | - $names[] = $user; |
|
161 | + $names[ ] = $user; |
|
162 | 162 | $text .= $msg->params( [ '$user' => $user, '$title' => $page->getTitle() ] )->text(); |
163 | 163 | } |
164 | 164 | |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | * @param PageRiconferma[] $pages |
188 | 188 | * @return User[] |
189 | 189 | */ |
190 | - private function getFailedBureaucrats( array $pages ) : array { |
|
191 | - $ret = []; |
|
190 | + private function getFailedBureaucrats ( array $pages ) : array { |
|
191 | + $ret = [ ]; |
|
192 | 192 | foreach ( $pages as $page ) { |
193 | 193 | $user = $page->getUser(); |
194 | 194 | if ( $user->inGroup( 'bureaucrat' ) ) { |
195 | - $ret[] = $user; |
|
195 | + $ret[ ] = $user; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | return $ret; |
@@ -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 | |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @inheritDoc |
18 | 18 | */ |
19 | - public function runInternal() : int { |
|
19 | + public function runInternal () : int { |
|
20 | 20 | $pages = $this->getDataProvider()->getPagesToClose(); |
21 | 21 | |
22 | 22 | if ( !$pages ) { |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @param PageRiconferma[] $pages |
39 | 39 | * @see UpdatesAround::addToVotazioni() |
40 | 40 | */ |
41 | - protected function updateVotazioni( array $pages ) { |
|
41 | + protected function updateVotazioni ( array $pages ) { |
|
42 | 42 | $this->getLogger()->info( |
43 | 43 | 'Updating votazioni: ' . implode( ', ', $pages ) |
44 | 44 | ); |
45 | 45 | $votePage = new Page( $this->getConfig()->get( 'vote-page-title' ) ); |
46 | 46 | |
47 | - $users = []; |
|
47 | + $users = [ ]; |
|
48 | 48 | foreach ( $pages as $page ) { |
49 | - $users[] = $page->getUser(); |
|
49 | + $users[ ] = $page->getUser(); |
|
50 | 50 | } |
51 | 51 | $usersReg = Element::regexFromArray( $users ); |
52 | 52 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param array $pages |
68 | 68 | * @see UpdatesAround::addToNews() |
69 | 69 | */ |
70 | - protected function updateNews( array $pages ) { |
|
70 | + protected function updateNews ( array $pages ) { |
|
71 | 71 | $simpleAmount = $voteAmount = 0; |
72 | 72 | foreach ( $pages as $page ) { |
73 | 73 | if ( $page->isVote() ) { |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | $simpleMatches = $newsPage->getMatch( $simpleReg ); |
88 | 88 | $voteMatches = $newsPage->getMatch( $voteReg ); |
89 | 89 | |
90 | - $newSimp = (int)$simpleMatches[2] - $simpleAmount ?: ''; |
|
91 | - $newVote = (int)$voteMatches[2] - $voteAmount ?: ''; |
|
90 | + $newSimp = (int)$simpleMatches[ 2 ] - $simpleAmount ?: ''; |
|
91 | + $newVote = (int)$voteMatches[ 2 ] - $voteAmount ?: ''; |
|
92 | 92 | $newContent = preg_replace( $simpleReg, '${1}' . $newSimp, $newsPage->getContent() ); |
93 | 93 | $newContent = preg_replace( $voteReg, '${1}' . $newVote, $newContent ); |
94 | 94 | |
@@ -106,21 +106,21 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param bool[] $outcomes |
108 | 108 | */ |
109 | - protected function updateAdminList( array $outcomes ) { |
|
109 | + protected function updateAdminList ( array $outcomes ) { |
|
110 | 110 | $this->getLogger()->info( 'Updating admin list' ); |
111 | 111 | $adminsPage = new Page( $this->getConfig()->get( 'admins-list-title' ) ); |
112 | 112 | $newContent = $adminsPage->getContent(); |
113 | 113 | |
114 | - $riconfNames = $removeNames = []; |
|
114 | + $riconfNames = $removeNames = [ ]; |
|
115 | 115 | foreach ( $outcomes as $user => $confirmed ) { |
116 | 116 | $userReg = ( new User( $user ) )->getRegex(); |
117 | 117 | $reg = "!(\{\{Amministratore\/riga\|$userReg.+\| *)\d+( *\|[ \w]*\}\}.*\n)!"; |
118 | 118 | if ( $confirmed ) { |
119 | 119 | $newContent = preg_replace( $reg, '${1}{{subst:#time:Ymd|+1 year}}$2', $newContent ); |
120 | - $riconfNames[] = $user; |
|
120 | + $riconfNames[ ] = $user; |
|
121 | 121 | } else { |
122 | 122 | $newContent = preg_replace( $reg, '', $newContent ); |
123 | - $removeNames[] = $user; |
|
123 | + $removeNames[ ] = $user; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -140,21 +140,21 @@ discard block |
||
140 | 140 | /** |
141 | 141 | * @param bool[] $outcomes |
142 | 142 | */ |
143 | - protected function updateCUList( array $outcomes ) { |
|
143 | + protected function updateCUList ( array $outcomes ) { |
|
144 | 144 | $this->getLogger()->info( 'Updating CU list.' ); |
145 | 145 | $cuList = new Page( $this->getConfig()->get( 'cu-list-title' ) ); |
146 | 146 | $newContent = $cuList->getContent(); |
147 | 147 | |
148 | - $riconfNames = $removeNames = []; |
|
148 | + $riconfNames = $removeNames = [ ]; |
|
149 | 149 | foreach ( $outcomes as $user => $confirmed ) { |
150 | 150 | $userReg = ( new User( $user ) )->getRegex(); |
151 | 151 | $reg = "!(\{\{ *Checkuser *\| *$userReg *\|[^}]+\| *)[\w \d]+(}}.*\n)!"; |
152 | 152 | if ( $confirmed ) { |
153 | 153 | $newContent = preg_replace( $reg, '${1}{{subst:#time:j F Y}}$2', $newContent ); |
154 | - $riconfNames[] = $user; |
|
154 | + $riconfNames[ ] = $user; |
|
155 | 155 | } else { |
156 | 156 | $newContent = preg_replace( $reg, '', $newContent ); |
157 | - $removeNames[] = $user; |
|
157 | + $removeNames[ ] = $user; |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * @param PageRiconferma[] $pages |
179 | 179 | * @return bool[] |
180 | 180 | */ |
181 | - private function getGroupOutcomes( string $group, array $pages ) : array { |
|
182 | - $ret = []; |
|
181 | + private function getGroupOutcomes ( string $group, array $pages ) : array { |
|
182 | + $ret = [ ]; |
|
183 | 183 | foreach ( $pages as $page ) { |
184 | 184 | $user = $page->getUser(); |
185 | 185 | if ( $user->inGroup( $group ) ) { |
@@ -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 | |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @inheritDoc |
17 | 17 | */ |
18 | - protected function getSubtasksMap(): array { |
|
18 | + protected function getSubtasksMap (): array { |
|
19 | 19 | // Everything is done here. |
20 | - return []; |
|
20 | + return [ ]; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @inheritDoc |
25 | 25 | */ |
26 | - public function runInternal() : int { |
|
26 | + public function runInternal () : int { |
|
27 | 27 | $pages = $this->getDataProvider()->getOpenPages(); |
28 | 28 | |
29 | 29 | if ( !$pages ) { |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param PageRiconferma[] $pages |
38 | 38 | * @return int a STATUS_* constant |
39 | 39 | */ |
40 | - protected function processPages( array $pages ) : int { |
|
41 | - $donePages = []; |
|
40 | + protected function processPages ( array $pages ) : int { |
|
41 | + $donePages = [ ]; |
|
42 | 42 | foreach ( $pages as $page ) { |
43 | 43 | if ( $page->hasOpposition() && !$page->isVote() ) { |
44 | 44 | $this->openVote( $page ); |
45 | - $donePages[] = $page; |
|
45 | + $donePages[ ] = $page; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @param PageRiconferma $page |
62 | 62 | */ |
63 | - protected function openVote( PageRiconferma $page ) { |
|
63 | + protected function openVote ( PageRiconferma $page ) { |
|
64 | 64 | $this->getLogger()->info( "Starting vote on $page" ); |
65 | 65 | |
66 | 66 | $content = $page->getContent(); |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | * @see SimpleUpdates::updateVotazioni() |
100 | 100 | * @see UpdatesAround::addToVotazioni() |
101 | 101 | */ |
102 | - protected function updateVotazioni( array $pages ) { |
|
102 | + protected function updateVotazioni ( array $pages ) { |
|
103 | 103 | $votePage = new Page( $this->getConfig()->get( 'vote-page-title' ) ); |
104 | 104 | |
105 | - $users = []; |
|
105 | + $users = [ ]; |
|
106 | 106 | foreach ( $pages as $page ) { |
107 | - $users[] = $page->getUser(); |
|
107 | + $users[ ] = $page->getUser(); |
|
108 | 108 | } |
109 | 109 | $usersReg = Element::regexFromArray( $users ); |
110 | 110 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @see SimpleUpdates::updateNews() |
143 | 143 | * @throws TaskException |
144 | 144 | */ |
145 | - protected function updateNews( int $amount ) { |
|
145 | + protected function updateNews ( int $amount ) { |
|
146 | 146 | $this->getLogger()->info( "Turning $amount pages into votes" ); |
147 | 147 | $newsPage = new Page( $this->getConfig()->get( 'news-page-title' ) ); |
148 | 148 | |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | throw new TaskException( 'Param "voto" not found in news page' ); |
158 | 158 | } |
159 | 159 | |
160 | - $newTac = intval( $newsPage->getMatch( $regTac )[2] ) - $amount ?: ''; |
|
161 | - $newVot = intval( $newsPage->getMatch( $regVot )[2] ) + $amount ?: ''; |
|
160 | + $newTac = intval( $newsPage->getMatch( $regTac )[ 2 ] ) - $amount ?: ''; |
|
161 | + $newVot = intval( $newsPage->getMatch( $regVot )[ 2 ] ) + $amount ?: ''; |
|
162 | 162 | |
163 | 163 | $newContent = preg_replace( $regTac, '${1}' . $newTac, $content ); |
164 | 164 | $newContent = preg_replace( $regVot, '${1}' . $newVot, $newContent ); |
@@ -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; |
@@ -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 ); |
@@ -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"; |