@@ -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 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public function __construct( string $key ) { |
|
29 | + public function __construct ( string $key ) { |
|
30 | 30 | $this->value = Config::getInstance()->getWikiMessage( $key ); |
31 | 31 | } |
32 | 32 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param array $args |
35 | 35 | * @return self |
36 | 36 | */ |
37 | - public function params( array $args ) : self { |
|
37 | + public function params ( array $args ) : self { |
|
38 | 38 | $this->value = strtr( $this->value, $args ); |
39 | 39 | return $this; |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function text() : string { |
|
45 | + public function text () : string { |
|
46 | 46 | $this->parsePlurals(); |
47 | 47 | return $this->value; |
48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Replace {{$plur|<amount>|sing|plur}} |
52 | 52 | */ |
53 | - protected function parsePlurals() { |
|
53 | + protected function parsePlurals () { |
|
54 | 54 | $reg = '!\{\{\$plur\|(?P<amount>\d+)\|(?P<sing>[^}|]+)\|(?P<plur>[^|}]+)}}!'; |
55 | 55 | |
56 | 56 | if ( preg_match( $reg, $this->value ) === 0 ) { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $this->value = preg_replace_callback( |
60 | 60 | $reg, |
61 | 61 | function ( $matches ) { |
62 | - return intval( $matches['amount'] ) > 1 ? trim( $matches['plur'] ) : trim( $matches['sing'] ); |
|
62 | + return intval( $matches[ 'amount' ] ) > 1 ? trim( $matches[ 'plur' ] ) : trim( $matches[ 'sing' ] ); |
|
63 | 63 | }, |
64 | 64 | $this->value |
65 | 65 | ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @suppress PhanUnreferencedPublicMethod |
74 | 74 | * @fixme Is this necessary? |
75 | 75 | */ |
76 | - public static function getTimeWithArticle( int $timestamp ) : string { |
|
76 | + public static function getTimeWithArticle ( int $timestamp ) : string { |
|
77 | 77 | $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
78 | 78 | $timeString = strftime( '%e %B alle %R', $timestamp ); |
79 | 79 | // Remove the left space if day has a single digit |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param string $timeString Full format, e.g. "15 aprile 2019 18:27" |
91 | 91 | * @return int |
92 | 92 | */ |
93 | - public static function getTimestampFromLocalTime( string $timeString ) : int { |
|
93 | + public static function getTimestampFromLocalTime ( string $timeString ) : int { |
|
94 | 94 | $englishTime = str_ireplace( |
95 | 95 | array_values( self::MONTHS ), |
96 | 96 | array_keys( self::MONTHS ), |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | * @param string $emptyText |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - public static function commaList( array $data, string $emptyText = 'nessuno' ) : string { |
|
111 | + public static function commaList ( array $data, string $emptyText = 'nessuno' ) : string { |
|
112 | 112 | if ( count( $data ) > 1 ) { |
113 | 113 | $last = array_pop( $data ); |
114 | 114 | $ret = implode( ', ', $data ) . " e $last"; |
115 | 115 | } elseif ( $data ) { |
116 | - $ret = (string)$data[0]; |
|
116 | + $ret = (string)$data[ 0 ]; |
|
117 | 117 | } else { |
118 | 118 | $ret = $emptyText; |
119 | 119 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $ret; |
122 | 122 | } |
123 | 123 | |
124 | - public function __toString() { |
|
124 | + public function __toString () { |
|
125 | 125 | return $this->text(); |
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\Request; |
4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @inheritDoc |
13 | 13 | * @throws APIRequestException |
14 | 14 | */ |
15 | - protected function reallyMakeRequest( string $params ) : string { |
|
15 | + protected function reallyMakeRequest ( string $params ) : string { |
|
16 | 16 | $curl = curl_init(); |
17 | 17 | if ( $curl === false ) { |
18 | 18 | throw new APIRequestException( 'Cannot open cURL handler.' ); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | * @internal Only used as CB for cURL (CURLOPT_HEADERFUNCTION) |
56 | 56 | * @suppress PhanUnreferencedPublicMethod,PhanUnusedPublicNoOverrideMethodParameter |
57 | 57 | */ |
58 | - public function headersHandler( $ch, string $header ) : int { |
|
58 | + public function headersHandler ( $ch, string $header ) : int { |
|
59 | 59 | $bits = explode( ':', $header, 2 ); |
60 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
61 | - $this->newCookies[] = $bits[1]; |
|
60 | + if ( trim( $bits[ 0 ] ) === 'Set-Cookie' ) { |
|
61 | + $this->newCookies[ ] = $bits[ 1 ]; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return strlen( $header ); |
@@ -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 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param int $status One of the Task::STATUS_* constants |
22 | 22 | * @param string[] $errors |
23 | 23 | */ |
24 | - public function __construct( int $status, array $errors = [] ) { |
|
24 | + public function __construct ( int $status, array $errors = [ ] ) { |
|
25 | 25 | $this->status = $status; |
26 | 26 | $this->errors = $errors; |
27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @return int |
31 | 31 | */ |
32 | - public function getStatus() : int { |
|
32 | + public function getStatus () : int { |
|
33 | 33 | return $this->status; |
34 | 34 | } |
35 | 35 | |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * @return string[] |
38 | 38 | * @suppress PhanUnreferencedPublicMethod |
39 | 39 | */ |
40 | - public function getErrors() { |
|
40 | + public function getErrors () { |
|
41 | 41 | return $this->errors; |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @param TaskResult $that |
46 | 46 | */ |
47 | - public function merge( TaskResult $that ) { |
|
47 | + public function merge ( TaskResult $that ) { |
|
48 | 48 | $this->status |= $that->status; |
49 | 49 | $this->errors = array_merge( $this->errors, $that->errors ); |
50 | 50 | } |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public function __toString() { |
|
55 | + public function __toString () { |
|
56 | 56 | if ( $this->isOK() ) { |
57 | 57 | $stat = 'OK'; |
58 | 58 | $errs = "\tNo errors."; |
59 | 59 | } else { |
60 | 60 | $stat = 'ERROR'; |
61 | - $formattedErrs = []; |
|
61 | + $formattedErrs = [ ]; |
|
62 | 62 | foreach ( $this->errors as $err ) { |
63 | - $formattedErrs[] = "\t - $err"; |
|
63 | + $formattedErrs[ ] = "\t - $err"; |
|
64 | 64 | } |
65 | 65 | $errs = implode( "\n", $formattedErrs ); |
66 | 66 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function isOK() : bool { |
|
75 | + public function isOK () : bool { |
|
76 | 76 | return ( $this->status | self::STATUS_GOOD ) === self::STATUS_GOOD; |
77 | 77 | } |
78 | 78 | } |
@@ -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 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * @inheritDoc |
15 | 15 | */ |
16 | - public function runInternal() : int { |
|
16 | + public function runInternal () : int { |
|
17 | 17 | $pages = $this->getDataProvider()->getCreatedPages(); |
18 | 18 | |
19 | 19 | if ( !$pages ) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param PageRiconferma[] $pages |
37 | 37 | */ |
38 | - protected function addToMainPage( array $pages ) { |
|
38 | + protected function addToMainPage ( array $pages ) { |
|
39 | 39 | $this->getLogger()->info( |
40 | 40 | 'Adding the following to main: ' . implode( ', ', $pages ) |
41 | 41 | ); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @param PageRiconferma[] $pages |
70 | 70 | */ |
71 | - protected function addToVotazioni( array $pages ) { |
|
71 | + protected function addToVotazioni ( array $pages ) { |
|
72 | 72 | $this->getLogger()->info( |
73 | 73 | 'Adding the following to votes: ' . implode( ', ', $pages ) |
74 | 74 | ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param int $amount |
106 | 106 | * @throws TaskException |
107 | 107 | */ |
108 | - protected function addToNews( int $amount ) { |
|
108 | + protected function addToNews ( int $amount ) { |
|
109 | 109 | $this->getLogger()->info( "Increasing the news counter by $amount" ); |
110 | 110 | $newsPage = $this->getPage( $this->getOpt( 'news-page-title' ) ); |
111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $matches = $newsPage->getMatch( $reg ); |
120 | 120 | |
121 | - $newNum = (int)$matches[2] + $amount; |
|
121 | + $newNum = (int)$matches[ 2 ] + $amount; |
|
122 | 122 | $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
123 | 123 | |
124 | 124 | $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; |
4 | 4 | |
@@ -13,16 +13,16 @@ discard block |
||
13 | 13 | /** @var array[] */ |
14 | 14 | private $processUsers; |
15 | 15 | /** @var PageRiconferma[] */ |
16 | - private $createdPages = []; |
|
16 | + private $createdPages = [ ]; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Get a list of users to execute tasks on. |
20 | 20 | * |
21 | 21 | * @return array[] |
22 | 22 | */ |
23 | - public function getUsersToProcess() : array { |
|
23 | + public function getUsersToProcess () : array { |
|
24 | 24 | if ( $this->processUsers === null ) { |
25 | - $this->processUsers = []; |
|
25 | + $this->processUsers = [ ]; |
|
26 | 26 | foreach ( PageBotList::get( $this->getWiki() )->getAdminsList() as $user => $groups ) { |
27 | 27 | if ( $this->shouldAddUser( $groups ) ) { |
28 | 28 | $this->processUsers[ $user ] = $groups; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param string[] $groups |
40 | 40 | * @return bool |
41 | 41 | */ |
42 | - private function shouldAddUser( array $groups ) : bool { |
|
42 | + private function shouldAddUser ( array $groups ) : bool { |
|
43 | 43 | $override = true; |
44 | 44 | $timestamp = PageBotList::getOverrideTimestamp( $groups ); |
45 | 45 | |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return PageRiconferma[] |
60 | 60 | */ |
61 | - public function getOpenPages() : array { |
|
61 | + public function getOpenPages () : array { |
|
62 | 62 | static $list = null; |
63 | 63 | if ( $list === null ) { |
64 | - $list = []; |
|
64 | + $list = [ ]; |
|
65 | 65 | $mainTitle = $this->getOpt( 'main-page-title' ); |
66 | 66 | $params = [ |
67 | 67 | 'action' => 'query', |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $pages = RequestBase::newFromParams( $params )->execute()->query->pages; |
76 | 76 | foreach ( reset( $pages )->templates as $page ) { |
77 | 77 | if ( preg_match( "!$titleReg\/[^\/]+\/\d!", $page->title ) ) { |
78 | - $list[] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
78 | + $list[ ] = new PageRiconferma( $page->title, $this->getWiki() ); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return PageRiconferma[] |
90 | 90 | */ |
91 | - public function getPagesToClose() : array { |
|
91 | + public function getPagesToClose () : array { |
|
92 | 92 | static $list = null; |
93 | 93 | if ( $list === null ) { |
94 | - $list = []; |
|
94 | + $list = [ ]; |
|
95 | 95 | foreach ( $this->getOpenPages() as $page ) { |
96 | 96 | if ( time() > $page->getEndTimestamp() ) { |
97 | - $list[] = $page; |
|
97 | + $list[ ] = $page; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
@@ -106,21 +106,21 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param string $name |
108 | 108 | */ |
109 | - public function removeUser( string $name ) { |
|
109 | + public function removeUser ( string $name ) { |
|
110 | 110 | unset( $this->processUsers[ $name ] ); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | 114 | * @return PageRiconferma[] |
115 | 115 | */ |
116 | - public function getCreatedPages() : array { |
|
116 | + public function getCreatedPages () : array { |
|
117 | 117 | return $this->createdPages; |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @param PageRiconferma $page |
122 | 122 | */ |
123 | - public function addCreatedPages( PageRiconferma $page ) { |
|
124 | - $this->createdPages[] = $page; |
|
123 | + public function addCreatedPages ( PageRiconferma $page ) { |
|
124 | + $this->createdPages[ ] = $page; |
|
125 | 125 | } |
126 | 126 | } |
@@ -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 Wiki $wiki |
19 | 19 | */ |
20 | - public function __construct( string $name, Wiki $wiki ) { |
|
20 | + public function __construct ( string $name, Wiki $wiki ) { |
|
21 | 21 | parent::__construct( $wiki ); |
22 | 22 | $this->name = $name; |
23 | 23 | } |
@@ -25,7 +25,7 @@ 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 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return string[] |
36 | 36 | */ |
37 | - public function getGroups() : array { |
|
37 | + public function getGroups () : array { |
|
38 | 38 | return array_keys( $this->getGroupsWithDates() ); |
39 | 39 | } |
40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return string[] |
46 | 46 | */ |
47 | - public function getGroupsWithDates() : array { |
|
47 | + public function getGroupsWithDates () : array { |
|
48 | 48 | if ( $this->groups === null ) { |
49 | 49 | $usersList = PageBotList::get( $this->wiki )->getAdminsList(); |
50 | 50 | $this->groups = $usersList[ $this->name ]; |
@@ -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() ); |
63 | 63 | } |
64 | 64 | |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @inheritDoc |
69 | 69 | */ |
70 | - public function getRegex() : string { |
|
70 | + public function getRegex () : string { |
|
71 | 71 | return str_replace( ' ', '[ _]', preg_quote( $this->name ) ); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @return string |
76 | 76 | */ |
77 | - public function __toString() { |
|
77 | + public function __toString () { |
|
78 | 78 | return $this->name; |
79 | 79 | } |
80 | 80 | } |
@@ -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 Use self::get() |
14 | 14 | * @param Wiki $wiki |
15 | 15 | */ |
16 | - public function __construct( Wiki $wiki ) { |
|
16 | + public function __construct ( Wiki $wiki ) { |
|
17 | 17 | parent::__construct( Config::getInstance()->get( 'list-title' ), $wiki ); |
18 | 18 | } |
19 | 19 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param Wiki $wiki |
24 | 24 | * @return self |
25 | 25 | */ |
26 | - public static function get( Wiki $wiki ) : self { |
|
26 | + public static function get ( Wiki $wiki ) : self { |
|
27 | 27 | static $instance = null; |
28 | 28 | if ( $instance === null ) { |
29 | 29 | $instance = new self( $wiki ); |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @param string[] $groups |
36 | 36 | * @return int|null |
37 | 37 | */ |
38 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
38 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
39 | 39 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | |
43 | 43 | // A one-time override takes precedence |
44 | 44 | if ( array_key_exists( 'override', $groups ) ) { |
45 | - $date = $groups['override']; |
|
45 | + $date = $groups[ 'override' ]; |
|
46 | 46 | } else { |
47 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
47 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
48 | 48 | } |
49 | 49 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
50 | 50 | } |
@@ -55,17 +55,15 @@ discard block |
||
55 | 55 | * @param array $groups |
56 | 56 | * @return int |
57 | 57 | */ |
58 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
59 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
60 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
61 | - 0; |
|
62 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
63 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
64 | - 0; |
|
58 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
59 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
60 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
61 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
62 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
65 | 63 | |
66 | 64 | $timestamp = max( $bureaucrat, $checkuser ); |
67 | 65 | if ( $timestamp === 0 ) { |
68 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
66 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
69 | 67 | } |
70 | 68 | return $timestamp; |
71 | 69 | } |
@@ -75,7 +73,7 @@ discard block |
||
75 | 73 | * |
76 | 74 | * @return array[] |
77 | 75 | */ |
78 | - public function getAdminsList() : array { |
|
76 | + public function getAdminsList () : array { |
|
79 | 77 | return json_decode( $this->getContent(), true ); |
80 | 78 | } |
81 | 79 | } |
@@ -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 $title |
20 | 20 | * @param Wiki $wiki For the site where the page lives |
21 | 21 | */ |
22 | - public function __construct( string $title, Wiki $wiki ) { |
|
22 | + public function __construct ( string $title, Wiki $wiki ) { |
|
23 | 23 | parent::__construct( $wiki ); |
24 | 24 | $this->title = $title; |
25 | 25 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public function getTitle() : string { |
|
30 | + public function getTitle () : string { |
|
31 | 31 | return $this->title; |
32 | 32 | } |
33 | 33 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param int|null $section A section number to retrieve the content of that section |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function getContent( int $section = null ) : string { |
|
40 | + public function getContent ( int $section = null ) : string { |
|
41 | 41 | if ( $this->content === null ) { |
42 | 42 | $this->content = $this->wiki->getPageContent( $this->title, $section ); |
43 | 43 | } |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | * @param array $params |
51 | 51 | * @throws \LogicException |
52 | 52 | */ |
53 | - public function edit( array $params ) { |
|
53 | + public function edit ( array $params ) { |
|
54 | 54 | $params = [ |
55 | 55 | 'title' => $this->getTitle() |
56 | 56 | ] + $params; |
57 | 57 | |
58 | 58 | $this->wiki->editPage( $params ); |
59 | - if ( isset( $params['text'] ) ) { |
|
60 | - $this->content = $params['text']; |
|
61 | - } elseif ( isset( $params['appendtext'] ) ) { |
|
62 | - $this->content .= $params['appendtext']; |
|
63 | - } elseif ( isset( $params['prependtext'] ) ) { |
|
64 | - $this->content = $params['prependtext'] . $this->content; |
|
59 | + if ( isset( $params[ 'text' ] ) ) { |
|
60 | + $this->content = $params[ 'text' ]; |
|
61 | + } elseif ( isset( $params[ 'appendtext' ] ) ) { |
|
62 | + $this->content .= $params[ 'appendtext' ]; |
|
63 | + } elseif ( isset( $params[ 'prependtext' ] ) ) { |
|
64 | + $this->content = $params[ 'prependtext' ] . $this->content; |
|
65 | 65 | } else { |
66 | 66 | throw new \LogicException( |
67 | 67 | 'Unrecognized text param for edit. Params: ' . var_export( $params, true ) |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return bool |
76 | 76 | */ |
77 | - public function exists() : bool { |
|
77 | + public function exists () : bool { |
|
78 | 78 | $res = RequestBase::newFromParams( [ |
79 | 79 | 'action' => 'query', |
80 | 80 | 'titles' => $this->getTitle() |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param string $regex |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - public function matches( string $regex ) : bool { |
|
92 | + public function matches ( string $regex ) : bool { |
|
93 | 93 | return (bool)preg_match( $regex, $this->getContent() ); |
94 | 94 | } |
95 | 95 | |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @return string[] |
102 | 102 | * @throws \Exception |
103 | 103 | */ |
104 | - public function getMatch( string $regex ) : array { |
|
105 | - $ret = []; |
|
104 | + public function getMatch ( string $regex ) : array { |
|
105 | + $ret = [ ]; |
|
106 | 106 | if ( preg_match( $regex, $this->getContent(), $ret ) === 0 ) { |
107 | 107 | throw new \Exception( "The content of $this does not match the given regex $regex" ); |
108 | 108 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @inheritDoc |
116 | 116 | */ |
117 | - public function getRegex() : string { |
|
117 | + public function getRegex () : string { |
|
118 | 118 | return str_replace( ' ', '[ _]', preg_quote( $this->title ) ); |
119 | 119 | } |
120 | 120 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - public function __toString() { |
|
126 | + public function __toString () { |
|
127 | 127 | return $this->getTitle(); |
128 | 128 | } |
129 | 129 | } |
@@ -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 | public 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, $this->wiki ); |
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 | return substr( $this->getTitle(), 0, strrpos( $this->getTitle(), '/' ) ); |
76 | 76 | } |
77 | 77 | |
@@ -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->wiki->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->wiki->getPageCreationTS( $this->title ); |
210 | 210 | } |
211 | 211 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return int |
216 | 216 | */ |
217 | - public function getEndTimestamp() : int { |
|
217 | + public function getEndTimestamp () : int { |
|
218 | 218 | if ( $this->isVote() ) { |
219 | 219 | $reg = "!La votazione ha inizio il.+ alle ore ([\d:]+) e ha termine il (.+) alla stessa ora!"; |
220 | 220 | list( , $hours, $day ) = $this->getMatch( $reg ); |