Passed
Push — master ( aeb3c7...3e94dc )
by Daimona
01:51
created
includes/Config.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme;
4 4
 
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
 	/** @var self */
13 13
 	private static $instance;
14 14
 	/** @var array */
15
-	private $opts = [];
15
+	private $opts = [ ];
16 16
 
17 17
 	/**
18 18
 	 * Use self::init() and self::getInstance()
19 19
 	 */
20
-	private function __construct() {
20
+	private function __construct () {
21 21
 	}
22 22
 
23 23
 	/**
@@ -26,26 +26,26 @@  discard block
 block discarded – undo
26 26
 	 * @param array $defaults
27 27
 	 * @throws ConfigException
28 28
 	 */
29
-	public static function init( array $defaults ) {
29
+	public static function init ( array $defaults ) {
30 30
 		if ( self::$instance ) {
31
-			throw new ConfigException( 'Config was already initialized' );
31
+			throw new ConfigException ( 'Config was already initialized' );
32 32
 		}
33 33
 
34 34
 		$inst = new self;
35
-		$inst->set( 'list-title', $defaults['list-title'] );
36
-		$inst->set( 'username', $defaults['username'] );
37
-		$inst->set( 'password', $defaults['password'] );
35
+		$inst->set ( 'list-title', $defaults[ 'list-title' ] );
36
+		$inst->set ( 'username', $defaults[ 'username' ] );
37
+		$inst->set ( 'password', $defaults[ 'password' ] );
38 38
 		self::$instance = $inst;
39 39
 
40 40
 		// On-wiki values
41 41
 		try {
42
-			$conf = ( new WikiController )->getPageContent( $defaults[ 'config-title' ] );
42
+			$conf = ( new WikiController )->getPageContent ( $defaults[ 'config-title' ] );
43 43
 		} catch ( MissingPageException $e ) {
44
-			throw new ConfigException( 'Please create a config page.' );
44
+			throw new ConfigException ( 'Please create a config page.' );
45 45
 		}
46 46
 
47
-		foreach ( json_decode( $conf, true ) as $key => $val ) {
48
-			self::$instance->set( $key, $val );
47
+		foreach ( json_decode ( $conf, true ) as $key => $val ) {
48
+			self::$instance->set ( $key, $val );
49 49
 		}
50 50
 	}
51 51
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @param string $key
56 56
 	 * @param mixed $value
57 57
 	 */
58
-	protected function set( string $key, $value ) {
58
+	protected function set ( string $key, $value ) {
59 59
 		$this->opts[ $key ] = $value;
60 60
 	}
61 61
 
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 	 * @return self
66 66
 	 * @throws ConfigException
67 67
 	 */
68
-	public static function getInstance() : self {
68
+	public static function getInstance () : self {
69 69
 		if ( !self::$instance ) {
70
-			throw new ConfigException( 'Config not yet initialized' );
70
+			throw new ConfigException ( 'Config not yet initialized' );
71 71
 		}
72 72
 		return self::$instance;
73 73
 	}
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	 * @return mixed
80 80
 	 * @throws ConfigException
81 81
 	 */
82
-	public function get( string $opt ) {
82
+	public function get ( string $opt ) {
83 83
 		if ( !isset( $this->opts[ $opt ] ) ) {
84
-			throw new ConfigException( "Config option '$opt' not set." );
84
+			throw new ConfigException ( "Config option '$opt' not set." );
85 85
 		}
86 86
 		return $this->opts[ $opt ];
87 87
 	}
Please login to merge, or discard this patch.
includes/Exception/MissingPageException.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Exception;
4 4
 
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
 	/**
10 10
 	 * @param string|null $title If available
11 11
 	 */
12
-	public function __construct( string $title = null ) {
12
+	public function __construct ( string $title = null ) {
13 13
 		if ( $title ) {
14
-			parent::__construct( "The specified page doesn't exist: $title" );
14
+			parent::__construct ( "The specified page doesn't exist: $title" );
15 15
 		} else {
16
-			parent::__construct();
16
+			parent::__construct ();
17 17
 		}
18 18
 	}
19 19
 }
Please login to merge, or discard this patch.
includes/Exception/ProtectedPageException.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Exception;
4 4
 
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
 	/**
10 10
 	 * @param string|null $title If available
11 11
 	 */
12
-	public function __construct( string $title = null ) {
12
+	public function __construct ( string $title = null ) {
13 13
 		if ( $title ) {
14
-			parent::__construct( "The specified page is protected: $title" );
14
+			parent::__construct ( "The specified page is protected: $title" );
15 15
 		} else {
16
-			parent::__construct();
16
+			parent::__construct ();
17 17
 		}
18 18
 	}
19 19
 }
Please login to merge, or discard this patch.
includes/TaskResult.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme;
4 4
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @param int $status One of the Task::STATUS_* constants
21 21
 	 * @param string[] $errors
22 22
 	 */
23
-	public function __construct( int $status, array $errors = [] ) {
23
+	public function __construct ( int $status, array $errors = [ ] ) {
24 24
 		$this->status = $status;
25 25
 		$this->errors = $errors;
26 26
 	}
@@ -28,39 +28,39 @@  discard block
 block discarded – undo
28 28
 	/**
29 29
 	 * @return int
30 30
 	 */
31
-	public function getStatus() : int {
31
+	public function getStatus () : int {
32 32
 		return $this->status;
33 33
 	}
34 34
 
35 35
 	/**
36 36
 	 * @return string[]
37 37
 	 */
38
-	public function getErrors() {
38
+	public function getErrors () {
39 39
 		return $this->errors;
40 40
 	}
41 41
 
42 42
 	/**
43 43
 	 * @param TaskResult $that
44 44
 	 */
45
-	public function merge( TaskResult $that ) {
45
+	public function merge ( TaskResult $that ) {
46 46
 		$this->status |= $that->status;
47
-		$this->errors = array_merge( $this->errors, $that->errors );
47
+		$this->errors = array_merge ( $this->errors, $that->errors );
48 48
 	}
49 49
 
50 50
 	/**
51 51
 	 * @return string
52 52
 	 */
53
-	public function __toString() {
54
-		if ( $this->isOK() ) {
53
+	public function __toString () {
54
+		if ( $this->isOK () ) {
55 55
 			$stat = 'OK';
56 56
 			$errs = "\tNo errors.";
57 57
 		} else {
58 58
 			$stat = 'ERROR';
59
-			$formattedErrs = [];
59
+			$formattedErrs = [ ];
60 60
 			foreach ( $this->errors as $err ) {
61
-				$formattedErrs[] = "\t - $err";
61
+				$formattedErrs[ ] = "\t - $err";
62 62
 			}
63
-			$errs = implode( "\n", $formattedErrs );
63
+			$errs = implode ( "\n", $formattedErrs );
64 64
 		}
65 65
 		return "=== RESULT ===\n - Status: $stat\n - Errors:\n$errs\n";
66 66
 	}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @return bool
72 72
 	 */
73
-	public function isOK() : bool {
73
+	public function isOK () : bool {
74 74
 		return $this->status === self::STATUS_OK;
75 75
 	}
76 76
 }
Please login to merge, or discard this patch.
includes/ContextSource.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme;
4 4
 
@@ -18,51 +18,51 @@  discard block
 block discarded – undo
18 18
 	/** @var WikiController */
19 19
 	private $controller;
20 20
 
21
-	public function __construct() {
22
-		$this->setLogger( new Logger );
23
-		$this->setConfig( Config::getInstance() );
24
-		$this->setController( new WikiController );
21
+	public function __construct () {
22
+		$this->setLogger ( new Logger );
23
+		$this->setConfig ( Config::getInstance () );
24
+		$this->setController ( new WikiController );
25 25
 	}
26 26
 
27 27
 	/**
28 28
 	 * @return LoggerInterface
29 29
 	 */
30
-	protected function getLogger() : LoggerInterface {
30
+	protected function getLogger () : LoggerInterface {
31 31
 		return $this->logger;
32 32
 	}
33 33
 
34 34
 	/**
35 35
 	 * @inheritDoc
36 36
 	 */
37
-	public function setLogger( LoggerInterface $logger ) {
37
+	public function setLogger ( LoggerInterface $logger ) {
38 38
 		$this->logger = $logger;
39 39
 	}
40 40
 
41 41
 	/**
42 42
 	 * @return Config
43 43
 	 */
44
-	protected function getConfig() : Config {
44
+	protected function getConfig () : Config {
45 45
 		return $this->config;
46 46
 	}
47 47
 
48 48
 	/**
49 49
 	 * @param Config $cfg
50 50
 	 */
51
-	protected function setConfig( Config $cfg ) {
51
+	protected function setConfig ( Config $cfg ) {
52 52
 		$this->config = $cfg;
53 53
 	}
54 54
 
55 55
 	/**
56 56
 	 * @return WikiController
57 57
 	 */
58
-	protected function getController() : WikiController {
58
+	protected function getController () : WikiController {
59 59
 		return $this->controller;
60 60
 	}
61 61
 
62 62
 	/**
63 63
 	 * @param WikiController $controller
64 64
 	 */
65
-	protected function setController( WikiController $controller ) {
65
+	protected function setController ( WikiController $controller ) {
66 66
 		$this->controller = $controller;
67 67
 	}
68 68
 }
Please login to merge, or discard this patch.
includes/WikiController.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme;
4 4
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	/** @var string[] */
19 19
 	private $tokens;
20 20
 
21
-	public function __construct() {
21
+	public function __construct () {
22 22
 		$this->logger = new Logger;
23 23
 	}
24 24
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	 * @return string
30 30
 	 * @throws MissingPageException
31 31
 	 */
32
-	public function getPageContent( string $title ) : string {
33
-		$this->logger->debug( "Retrieving page $title" );
32
+	public function getPageContent ( string $title ) : string {
33
+		$this->logger->debug ( "Retrieving page $title" );
34 34
 		$params = [
35 35
 			'action' => 'query',
36 36
 			'titles' => $title,
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 			'rvlimit' => 1
41 41
 		];
42 42
 
43
-		$req = RequestBase::newFromParams( $params );
44
-		$data = $req->execute();
45
-		$page = reset( $data['query']['pages'] );
46
-		if ( isset( $page['missing'] ) ) {
47
-			throw new MissingPageException( $title );
43
+		$req = RequestBase::newFromParams ( $params );
44
+		$data = $req->execute ();
45
+		$page = reset ( $data[ 'query' ][ 'pages' ] );
46
+		if ( isset( $page[ 'missing' ] ) ) {
47
+			throw new MissingPageException ( $title );
48 48
 		}
49 49
 
50
-		return $page['revisions'][0]['slots']['main']['*'];
50
+		return $page[ 'revisions' ][ 0 ][ 'slots' ][ 'main' ][ '*' ];
51 51
 	}
52 52
 
53 53
 	/**
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 	 * @param array $params
57 57
 	 * @throws APIRequestException
58 58
 	 */
59
-	public function editPage( array $params ) {
60
-		$this->login();
59
+	public function editPage ( array $params ) {
60
+		$this->login ();
61 61
 
62 62
 		$params = [
63 63
 			'action' => 'edit',
64
-			'token' => $this->getToken( 'csrf' ),
65
-			'bot' => Config::getInstance()->get( 'bot-edits' )
64
+			'token' => $this->getToken ( 'csrf' ),
65
+			'bot' => Config::getInstance ()->get ( 'bot-edits' )
66 66
 		] + $params;
67 67
 
68
-		$req = RequestBase::newFromParams( $params, true );
69
-		$res = $req->execute();
70
-		if ( $res['edit']['result'] !== 'Success' ) {
71
-			throw new APIRequestException( $res['edit']['info'] );
68
+		$req = RequestBase::newFromParams ( $params, true );
69
+		$res = $req->execute ();
70
+		if ( $res[ 'edit' ][ 'result' ] !== 'Success' ) {
71
+			throw new APIRequestException ( $res[ 'edit' ][ 'info' ] );
72 72
 		}
73 73
 	}
74 74
 
@@ -76,36 +76,36 @@  discard block
 block discarded – undo
76 76
 	 * Login wrapper. Checks if we're already logged in and clears tokens cache
77 77
 	 * @throws LoginException
78 78
 	 */
79
-	public function login() {
79
+	public function login () {
80 80
 		if ( self::$loggedIn ) {
81
-			$this->logger->debug( 'Already logged in' );
81
+			$this->logger->debug ( 'Already logged in' );
82 82
 			return;
83 83
 		}
84 84
 
85
-		$this->logger->debug( 'Logging in' );
85
+		$this->logger->debug ( 'Logging in' );
86 86
 
87 87
 		$params = [
88 88
 			'action' => 'login',
89
-			'lgname' => Config::getInstance()->get( 'username' ),
90
-			'lgpassword' => Config::getInstance()->get( 'password' ),
91
-			'lgtoken' => $this->getToken( 'login' )
89
+			'lgname' => Config::getInstance ()->get ( 'username' ),
90
+			'lgpassword' => Config::getInstance ()->get ( 'password' ),
91
+			'lgtoken' => $this->getToken ( 'login' )
92 92
 		];
93 93
 
94 94
 		try {
95
-			$req = RequestBase::newFromParams( $params, true );
96
-			$res = $req->execute();
95
+			$req = RequestBase::newFromParams ( $params, true );
96
+			$res = $req->execute ();
97 97
 		} catch ( APIRequestException $e ) {
98
-			throw new LoginException( $e->getMessage() );
98
+			throw new LoginException ( $e->getMessage () );
99 99
 		}
100 100
 
101
-		if ( !isset( $res['login']['result'] ) || $res['login']['result'] !== 'Success' ) {
102
-			throw new LoginException( 'Unknown error' );
101
+		if ( !isset( $res[ 'login' ][ 'result' ] ) || $res[ 'login' ][ 'result' ] !== 'Success' ) {
102
+			throw new LoginException ( 'Unknown error' );
103 103
 		}
104 104
 
105 105
 		self::$loggedIn = true;
106 106
 		// Clear tokens cache
107
-		$this->tokens = [];
108
-		$this->logger->debug( 'Login succeeded' );
107
+		$this->tokens = [ ];
108
+		$this->logger->debug ( 'Login succeeded' );
109 109
 	}
110 110
 
111 111
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param string $type
115 115
 	 * @return string
116 116
 	 */
117
-	public function getToken( string $type ) : string {
117
+	public function getToken ( string $type ) : string {
118 118
 		if ( !isset( $this->tokens[ $type ] ) ) {
119 119
 			$params = [
120 120
 				'action' => 'query',
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 				'type'   => $type
123 123
 			];
124 124
 
125
-			$req = RequestBase::newFromParams( $params );
126
-			$res = $req->execute();
125
+			$req = RequestBase::newFromParams ( $params );
126
+			$res = $req->execute ();
127 127
 
128
-			$this->tokens[ $type ] = $res['query']['tokens']["{$type}token"];
128
+			$this->tokens[ $type ] = $res[ 'query' ][ 'tokens' ][ "{$type}token" ];
129 129
 		}
130 130
 
131 131
 		return $this->tokens[ $type ];
Please login to merge, or discard this patch.
includes/Task/UserNotice.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Task;
4 4
 
@@ -11,22 +11,22 @@  discard block
 block discarded – undo
11 11
 	/**
12 12
 	 * @inheritDoc
13 13
 	 */
14
-	public function run() : TaskResult {
15
-		$this->getLogger()->info( 'Starting task UserNotice' );
16
-
17
-		$ricNums = [];
18
-		foreach ( $this->getDataProvider()->getCreatedPages() as $page ) {
19
-			$bits = explode( '/', $page );
20
-			$num = intval( array_pop( $bits ) );
21
-			$ricNums[ array_pop( $bits ) ] = $num;
14
+	public function run () : TaskResult {
15
+		$this->getLogger ()->info ( 'Starting task UserNotice' );
16
+
17
+		$ricNums = [ ];
18
+		foreach ( $this->getDataProvider ()->getCreatedPages () as $page ) {
19
+			$bits = explode ( '/', $page );
20
+			$num = intval ( array_pop ( $bits ) );
21
+			$ricNums[ array_pop ( $bits ) ] = $num;
22 22
 		}
23 23
 
24
-		foreach ( $this->getDataProvider()->getUsersToProcess() as $user => $_ ) {
25
-			$this->addMsg( $user, $ricNums[ $user ] );
24
+		foreach ( $this->getDataProvider ()->getUsersToProcess () as $user => $_ ) {
25
+			$this->addMsg ( $user, $ricNums[ $user ] );
26 26
 		}
27 27
 
28
-		$this->getLogger()->info( 'Task UserNotice completed successfully' );
29
-		return new TaskResult( self::STATUS_OK );
28
+		$this->getLogger ()->info ( 'Task UserNotice completed successfully' );
29
+		return new TaskResult ( self::STATUS_OK );
30 30
 	}
31 31
 
32 32
 	/**
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
 	 * @param string $user
36 36
 	 * @param int $ricNum
37 37
 	 */
38
-	protected function addMsg( string $user, int $ricNum ) {
39
-		$this->getLogger()->info( "Leaving msg to $user" );
40
-		$msg = str_replace( '$num', "$ricNum", $this->getConfig()->get( 'user-notice-msg' ) );
38
+	protected function addMsg ( string $user, int $ricNum ) {
39
+		$this->getLogger ()->info ( "Leaving msg to $user" );
40
+		$msg = str_replace ( '$num', "$ricNum", $this->getConfig ()->get ( 'user-notice-msg' ) );
41 41
 
42 42
 		$params = [
43 43
 			'title' => "User talk:$user",
44 44
 			'section' => 'new',
45 45
 			'text' => $msg,
46
-			'sectiontitle' => $this->getConfig()->get( 'user-notice-title' ),
47
-			'summary' => $this->getConfig()->get( 'user-notice-summary' )
46
+			'sectiontitle' => $this->getConfig ()->get ( 'user-notice-title' ),
47
+			'summary' => $this->getConfig ()->get ( 'user-notice-summary' )
48 48
 		];
49 49
 
50
-		$this->getController()->editPage( $params );
50
+		$this->getController ()->editPage ( $params );
51 51
 	}
52 52
 }
Please login to merge, or discard this patch.
includes/Task/UpdatesAround.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Task;
4 4
 
@@ -12,19 +12,19 @@  discard block
 block discarded – undo
12 12
 	/**
13 13
 	 * @inheritDoc
14 14
 	 */
15
-	public function run() : TaskResult {
16
-		$this->getLogger()->info( 'Starting task UpdatesAround' );
15
+	public function run () : TaskResult {
16
+		$this->getLogger ()->info ( 'Starting task UpdatesAround' );
17 17
 
18
-		$pages = $this->getDataProvider()->getCreatedPages();
18
+		$pages = $this->getDataProvider ()->getCreatedPages ();
19 19
 		// Wikipedia:Amministratori/Riconferma annuale
20
-		$this->addToMainPage( $pages );
20
+		$this->addToMainPage ( $pages );
21 21
 		// WP:Wikipediano/Votazioni
22
-		$this->addVote( $pages );
22
+		$this->addVote ( $pages );
23 23
 		// Template:VotazioniRCnews
24
-		$this->addNews( count( $pages ) );
24
+		$this->addNews ( count ( $pages ) );
25 25
 
26
-		$this->getLogger()->info( 'Task UpdatesAround completed successfully' );
27
-		return new TaskResult( self::STATUS_OK );
26
+		$this->getLogger ()->info ( 'Task UpdatesAround completed successfully' );
27
+		return new TaskResult ( self::STATUS_OK );
28 28
 	}
29 29
 
30 30
 	/**
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param string[] $pages
34 34
 	 */
35
-	protected function addToMainPage( array $pages ) {
36
-		$this->getLogger()->info(
37
-			'Adding the following to main: ' . implode( ', ', $pages )
35
+	protected function addToMainPage ( array $pages ) {
36
+		$this->getLogger ()->info (
37
+			'Adding the following to main: ' . implode ( ', ', $pages )
38 38
 		);
39 39
 
40 40
 		$append = '';
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
 		}
44 44
 
45 45
 		$params = [
46
-			'title' => $this->getConfig()->get( 'ric-main-page' ),
46
+			'title' => $this->getConfig ()->get ( 'ric-main-page' ),
47 47
 			'appendtext' => $append,
48
-			'summary' => $this->getConfig()->get( 'ric-main-page-summary' )
48
+			'summary' => $this->getConfig ()->get ( 'ric-main-page-summary' )
49 49
 		];
50 50
 
51
-		$this->getController()->editPage( $params );
51
+		$this->getController ()->editPage ( $params );
52 52
 	}
53 53
 
54 54
 	/**
@@ -56,46 +56,46 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @param string[] $pages
58 58
 	 */
59
-	protected function addVote( array $pages ) {
60
-		$this->getLogger()->info(
61
-			'Adding the following to votes: ' . implode( ', ', $pages )
59
+	protected function addVote ( array $pages ) {
60
+		$this->getLogger ()->info (
61
+			'Adding the following to votes: ' . implode ( ', ', $pages )
62 62
 		);
63
-		$votePage = $this->getConfig()->get( 'ric-vote-page' );
63
+		$votePage = $this->getConfig ()->get ( 'ric-vote-page' );
64 64
 
65
-		$content = $this->getController()->getPageContent( $votePage );
65
+		$content = $this->getController ()->getPageContent ( $votePage );
66 66
 		// Remove comments etc.
67
-		$visibleContent = strip_tags( $content );
67
+		$visibleContent = strip_tags ( $content );
68 68
 
69
-		$time = $this->getTimeWithArticle();
69
+		$time = $this->getTimeWithArticle ();
70 70
 		$newLines = '';
71 71
 		foreach ( $pages as $page ) {
72
-			$user = explode( '/', $page )[2];
72
+			$user = explode ( '/', $page )[ 2 ];
73 73
 			$newLines .= "*[[Utente:$user|]]. La [[$page|procedura]] termina $time;\n";
74 74
 		}
75 75
 
76 76
 		$introReg = '!^;È in corso la .*riconferma tacita.* degli .*amministratori.+!m';
77
-		if ( preg_match( $introReg, $visibleContent ) ) {
77
+		if ( preg_match ( $introReg, $visibleContent ) ) {
78 78
 			// Put before the existing ones
79
-			$newContent = preg_replace( $introReg, '$0' . "\n$newLines", $content, 1 );
79
+			$newContent = preg_replace ( $introReg, '$0' . "\n$newLines", $content, 1 );
80 80
 		} else {
81 81
 			// Start section
82
-			$matches = [];
83
-			if ( preg_match( $introReg, $content, $matches ) === false ) {
84
-				throw new TaskException( 'Intro not found in vote page' );
82
+			$matches = [ ];
83
+			if ( preg_match ( $introReg, $content, $matches ) === false ) {
84
+				throw new TaskException ( 'Intro not found in vote page' );
85 85
 			}
86 86
 			$beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m';
87 87
 			// Replace semicolon with full stop
88
-			$newLines = substr( $newLines, 0, -2 ) . ".\n";
89
-			$newContent = preg_replace( $beforeReg, '$0' . "\n{$matches[0]}\n$newLines", $content, 1 );
88
+			$newLines = substr ( $newLines, 0, -2 ) . ".\n";
89
+			$newContent = preg_replace ( $beforeReg, '$0' . "\n{$matches[ 0 ]}\n$newLines", $content, 1 );
90 90
 		}
91 91
 
92 92
 		$params = [
93 93
 			'title' => $votePage,
94 94
 			'text' => $newContent,
95
-			'summary' => $this->getConfig()->get( 'ric-vote-page-summary' )
95
+			'summary' => $this->getConfig ()->get ( 'ric-vote-page-summary' )
96 96
 		];
97 97
 
98
-		$this->getController()->editPage( $params );
98
+		$this->getController ()->editPage ( $params );
99 99
 	}
100 100
 
101 101
 	/**
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return string
105 105
 	 */
106
-	private function getTimeWithArticle() : string {
107
-		$oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' );
108
-		$endTS = time() + ( 60 * 60 * 24 * 7 );
109
-		$endTime = strftime( '%e %B alle %R', $endTS );
106
+	private function getTimeWithArticle () : string {
107
+		$oldLoc = setlocale ( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' );
108
+		$endTS = time () + ( 60 * 60 * 24 * 7 );
109
+		$endTime = strftime ( '%e %B alle %R', $endTS );
110 110
 		// Remove the left space if day has a single digit
111
-		$endTime = ltrim( $endTime );
112
-		$artic = in_array( date( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il ";
113
-		setlocale( LC_TIME, $oldLoc );
111
+		$endTime = ltrim ( $endTime );
112
+		$artic = in_array ( date ( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il ";
113
+		setlocale ( LC_TIME, $oldLoc );
114 114
 
115 115
 		return $artic . $endTime;
116 116
 	}
@@ -120,27 +120,27 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @param int $amount
122 122
 	 */
123
-	protected function addNews( int $amount ) {
124
-		$this->getLogger()->info( "Increasing the news counter by $amount" );
125
-		$newsPage = $this->getConfig()->get( 'ric-news-page' );
123
+	protected function addNews ( int $amount ) {
124
+		$this->getLogger ()->info ( "Increasing the news counter by $amount" );
125
+		$newsPage = $this->getConfig ()->get ( 'ric-news-page' );
126 126
 
127
-		$content = $this->getController()->getPageContent( $newsPage );
127
+		$content = $this->getController ()->getPageContent ( $newsPage );
128 128
 		$reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!';
129 129
 
130
-		$matches = [];
131
-		if ( preg_match( $reg, $content, $matches ) === false ) {
132
-			throw new TaskException( 'Param not found in news page' );
130
+		$matches = [ ];
131
+		if ( preg_match ( $reg, $content, $matches ) === false ) {
132
+			throw new TaskException ( 'Param not found in news page' );
133 133
 		}
134 134
 
135
-		$newNum = (int)$matches[2] + $amount;
136
-		$newContent = preg_replace( $reg, '${1}' . $newNum, $content );
135
+		$newNum = (int)$matches[ 2 ] + $amount;
136
+		$newContent = preg_replace ( $reg, '${1}' . $newNum, $content );
137 137
 
138 138
 		$params = [
139 139
 			'title' => $newsPage,
140 140
 			'text' => $newContent,
141
-			'summary' => $this->getConfig()->get( 'ric-news-page-summary' )
141
+			'summary' => $this->getConfig ()->get ( 'ric-news-page-summary' )
142 142
 		];
143 143
 
144
-		$this->getController()->editPage( $params );
144
+		$this->getController ()->editPage ( $params );
145 145
 	}
146 146
 }
Please login to merge, or discard this patch.
includes/Task/UpdateList.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Task;
4 4
 
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @inheritDoc
20 20
 	 */
21
-	public function run() : TaskResult {
22
-		$this->getLogger()->info( 'Starting task UpdateList' );
23
-		$this->actualList = $this->getActualAdmins();
24
-		$this->botList = $this->getList();
21
+	public function run () : TaskResult {
22
+		$this->getLogger ()->info ( 'Starting task UpdateList' );
23
+		$this->actualList = $this->getActualAdmins ();
24
+		$this->botList = $this->getList ();
25 25
 
26
-		$missing = $this->getMissingGroups();
27
-		$extra = $this->getExtraGroups();
26
+		$missing = $this->getMissingGroups ();
27
+		$extra = $this->getExtraGroups ();
28 28
 
29 29
 		if ( $missing || $extra ) {
30
-			$this->doUpdateList( $this->getNewContent( $missing, $extra ) );
30
+			$this->doUpdateList ( $this->getNewContent ( $missing, $extra ) );
31 31
 		}
32 32
 
33 33
 		if ( $this->errors ) {
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 			$status = self::STATUS_OK;
40 40
 		}
41 41
 
42
-		$this->getLogger()->info( $msg );
43
-		return new TaskResult( $status, $this->errors );
42
+		$this->getLogger ()->info ( $msg );
43
+		return new TaskResult ( $status, $this->errors );
44 44
 	}
45 45
 
46 46
 	/**
47 47
 	 * @return array
48 48
 	 */
49
-	protected function getActualAdmins() : array {
50
-		$this->getLogger()->debug( 'Retrieving admins - API' );
49
+	protected function getActualAdmins () : array {
50
+		$this->getLogger ()->debug ( 'Retrieving admins - API' );
51 51
 		$params = [
52 52
 			'action' => 'query',
53 53
 			'list' => 'allusers',
@@ -56,23 +56,23 @@  discard block
 block discarded – undo
56 56
 			'aulimit' => 'max',
57 57
 		];
58 58
 
59
-		$req = RequestBase::newFromParams( $params );
60
-		return $this->extractAdmins( $req->execute() );
59
+		$req = RequestBase::newFromParams ( $params );
60
+		return $this->extractAdmins ( $req->execute () );
61 61
 	}
62 62
 
63 63
 	/**
64 64
 	 * @param array $data
65 65
 	 * @return array
66 66
 	 */
67
-	protected function extractAdmins( array $data ) : array {
68
-		$ret = [];
69
-		$blacklist = $this->getConfig()->get( 'exclude-admins' );
70
-		foreach ( $data['query']['allusers'] as $u ) {
71
-			if ( in_array( $u['name'], $blacklist ) ) {
67
+	protected function extractAdmins ( array $data ) : array {
68
+		$ret = [ ];
69
+		$blacklist = $this->getConfig ()->get ( 'exclude-admins' );
70
+		foreach ( $data[ 'query' ][ 'allusers' ] as $u ) {
71
+			if ( in_array ( $u[ 'name' ], $blacklist ) ) {
72 72
 				continue;
73 73
 			}
74
-			$interestingGroups = array_intersect( $u['groups'], [ 'sysop', 'bureaucrat', 'checkuser' ] );
75
-			$ret[ $u['name'] ] = $interestingGroups;
74
+			$interestingGroups = array_intersect ( $u[ 'groups' ], [ 'sysop', 'bureaucrat', 'checkuser' ] );
75
+			$ret[ $u[ 'name' ] ] = $interestingGroups;
76 76
 		}
77 77
 		return $ret;
78 78
 	}
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * @return array
82 82
 	 */
83
-	protected function getList() : array {
84
-		$this->getLogger()->debug( 'Retrieving admins - JSON list' );
85
-		$content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) );
83
+	protected function getList () : array {
84
+		$this->getLogger ()->debug ( 'Retrieving admins - JSON list' );
85
+		$content = $this->getController ()->getPageContent ( $this->getConfig ()->get ( 'list-title' ) );
86 86
 
87
-		return json_decode( $content, true );
87
+		return json_decode ( $content, true );
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,23 +92,23 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @return array[]
94 94
 	 */
95
-	protected function getMissingGroups() : array {
96
-		$missing = [];
95
+	protected function getMissingGroups () : array {
96
+		$missing = [ ];
97 97
 		foreach ( $this->actualList as $adm => $groups ) {
98 98
 			if ( !isset( $this->botList[ $adm ] ) ) {
99 99
 				$groupsList = $groups;
100
-			} elseif ( count( $groups ) > count( $this->botList[$adm] ) ) {
100
+			} elseif ( count ( $groups ) > count ( $this->botList[ $adm ] ) ) {
101 101
 				// Only some groups are missing
102
-				$groupsList = array_diff_key( $groups, $this->botList[$adm] );
102
+				$groupsList = array_diff_key ( $groups, $this->botList[ $adm ] );
103 103
 			} else {
104 104
 				continue;
105 105
 			}
106 106
 
107 107
 			foreach ( $groupsList as $group ) {
108 108
 				try {
109
-					$missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group );
109
+					$missing[ $adm ][ $group ] = $this->getFlagDate ( $adm, $group );
110 110
 				} catch ( TaskException $e ) {
111
-					$this->errors[] = $e->getMessage();
111
+					$this->errors[ ] = $e->getMessage ();
112 112
 				}
113 113
 			}
114 114
 		}
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 * @return string
124 124
 	 * @throws TaskException
125 125
 	 */
126
-	protected function getFlagDate( string $admin, string $group ) : string {
127
-		$this->getLogger()->info( "Retrieving $group flag date for $admin" );
126
+	protected function getFlagDate ( string $admin, string $group ) : string {
127
+		$this->getLogger ()->info ( "Retrieving $group flag date for $admin" );
128 128
 
129 129
 		if ( $group === 'checkuser' ) {
130 130
 			// Little hack
@@ -142,19 +142,19 @@  discard block
 block discarded – undo
142 142
 			'lelimit' => 'max'
143 143
 		];
144 144
 
145
-		$req = RequestBase::newFromParams( $params );
146
-		$data = $req->execute();
147
-		$ts = $this->extractTimestamp( $data, $group );
145
+		$req = RequestBase::newFromParams ( $params );
146
+		$data = $req->execute ();
147
+		$ts = $this->extractTimestamp ( $data, $group );
148 148
 
149 149
 		if ( isset( $oldUrl ) ) {
150 150
 			RequestBase::$url = $oldUrl;
151 151
 		}
152 152
 
153 153
 		if ( $ts === null ) {
154
-			throw new TaskException( "$group flag date unavailable for $admin" );
154
+			throw new TaskException ( "$group flag date unavailable for $admin" );
155 155
 		}
156 156
 
157
-		return date( "d/m/Y", strtotime( $ts ) );
157
+		return date ( "d/m/Y", strtotime ( $ts ) );
158 158
 	}
159 159
 
160 160
 	/**
@@ -164,17 +164,17 @@  discard block
 block discarded – undo
164 164
 	 * @param string $group
165 165
 	 * @return string|null
166 166
 	 */
167
-	private function extractTimestamp( array $data, string $group ) : ?string {
167
+	private function extractTimestamp ( array $data, string $group ) : ?string {
168 168
 		$ts = null;
169
-		foreach ( $data['query']['logevents'] as $entry ) {
170
-			if ( !isset( $entry['params'] ) ) {
169
+		foreach ( $data[ 'query' ][ 'logevents' ] as $entry ) {
170
+			if ( !isset( $entry[ 'params' ] ) ) {
171 171
 				// Old entries
172 172
 				continue;
173 173
 			}
174
-			if ( in_array( $group, $entry['params']['newgroups'] ) &&
175
-				!in_array( $group, $entry['params']['oldgroups'] )
174
+			if ( in_array ( $group, $entry[ 'params' ][ 'newgroups' ] ) &&
175
+				!in_array ( $group, $entry[ 'params' ][ 'oldgroups' ] )
176 176
 			) {
177
-				$ts = $entry['timestamp'];
177
+				$ts = $entry[ 'timestamp' ];
178 178
 				break;
179 179
 			}
180 180
 		}
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
 	 *
187 187
 	 * @return array[]
188 188
 	 */
189
-	protected function getExtraGroups() : array {
190
-		$extra = [];
189
+	protected function getExtraGroups () : array {
190
+		$extra = [ ];
191 191
 		foreach ( $this->botList as $name => $groups ) {
192 192
 			if ( !isset( $this->actualList[ $name ] ) ) {
193 193
 				$extra[ $name ] = $groups;
194
-			} elseif ( count( $groups ) > count( $this->actualList[ $name ] ) ) {
195
-				$extra[ $name ] = array_diff_key( $groups, $this->actualList[ $name ] );
194
+			} elseif ( count ( $groups ) > count ( $this->actualList[ $name ] ) ) {
195
+				$extra[ $name ] = array_diff_key ( $groups, $this->actualList[ $name ] );
196 196
 			}
197 197
 		}
198 198
 		return $extra;
@@ -203,25 +203,25 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @param array $newContent
205 205
 	 */
206
-	protected function doUpdateList( array $newContent ) {
207
-		ksort( $newContent );
206
+	protected function doUpdateList ( array $newContent ) {
207
+		ksort ( $newContent );
208 208
 
209 209
 		if ( $newContent !== $this->botList ) {
210
-			$this->getLogger()->info( 'Updating admin list' );
210
+			$this->getLogger ()->info ( 'Updating admin list' );
211 211
 		} else {
212
-			$this->getLogger()->info( 'Admin list already up-to-date' );
212
+			$this->getLogger ()->info ( 'Admin list already up-to-date' );
213 213
 			return;
214 214
 		}
215 215
 
216
-		$stringified = json_encode( $newContent );
216
+		$stringified = json_encode ( $newContent );
217 217
 
218 218
 		$params = [
219
-			'title' => $this->getConfig()->get( 'list-title' ),
219
+			'title' => $this->getConfig ()->get ( 'list-title' ),
220 220
 			'text' => $stringified,
221
-			'summary' => $this->getConfig()->get( 'list-update-summary' )
221
+			'summary' => $this->getConfig ()->get ( 'list-update-summary' )
222 222
 		];
223 223
 
224
-		$this->getController()->editPage( $params );
224
+		$this->getController ()->editPage ( $params );
225 225
 	}
226 226
 
227 227
 	/**
@@ -231,19 +231,19 @@  discard block
 block discarded – undo
231 231
 	 * @param array[] $extra
232 232
 	 * @return array[]
233 233
 	 */
234
-	protected function getNewContent( array $missing, array $extra ) : array {
234
+	protected function getNewContent ( array $missing, array $extra ) : array {
235 235
 		$newContent = $this->botList;
236 236
 		foreach ( $newContent as $user => $groups ) {
237 237
 			if ( isset( $missing[ $user ] ) ) {
238
-				$newContent[ $user ] = array_merge( $groups, $missing[ $user ] );
238
+				$newContent[ $user ] = array_merge ( $groups, $missing[ $user ] );
239 239
 				unset( $missing[ $user ] );
240 240
 			} elseif ( isset( $extra[ $user ] ) ) {
241
-				$newContent[ $user ] = array_diff_key( $groups, $extra[ $user ] );
241
+				$newContent[ $user ] = array_diff_key ( $groups, $extra[ $user ] );
242 242
 			}
243 243
 		}
244 244
 		// Add users which don't have an entry at all
245
-		$newContent = array_merge( $newContent, $missing );
245
+		$newContent = array_merge ( $newContent, $missing );
246 246
 		// And remove empty users
247
-		return array_filter( $newContent );
247
+		return array_filter ( $newContent );
248 248
 	}
249 249
 }
Please login to merge, or discard this patch.