Passed
Push — master ( 734688...a5fa97 )
by Daimona
02:07
created
includes/ContextSource.php 1 patch
Spacing   +7 added lines, -7 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
 
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 	private $controller;
17 17
 
18 18
 	public function __construct() {
19
-		$this->setLogger( new Logger );
20
-		$this->setConfig( Config::getInstance() );
21
-		$this->setController( new WikiController );
19
+		$this->setLogger(new Logger);
20
+		$this->setConfig(Config::getInstance());
21
+		$this->setController(new WikiController);
22 22
 	}
23 23
 
24 24
 	/**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	/**
32 32
 	 * @inheritDoc
33 33
 	 */
34
-	public function setLogger( LoggerInterface $logger ) {
34
+	public function setLogger(LoggerInterface $logger) {
35 35
 		$this->logger = $logger;
36 36
 	}
37 37
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	/**
46 46
 	 * @param Config $cfg
47 47
 	 */
48
-	protected function setConfig( Config $cfg ) {
48
+	protected function setConfig(Config $cfg) {
49 49
 		$this->config = $cfg;
50 50
 	}
51 51
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	/**
60 60
 	 * @param WikiController $controller
61 61
 	 */
62
-	protected function setController( WikiController $controller ) {
62
+	protected function setController(WikiController $controller) {
63 63
 		$this->controller = $controller;
64 64
 	}
65 65
 }
Please login to merge, or discard this patch.
includes/TaskDataProvider.php 1 patch
Spacing   +21 added lines, -23 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
 
@@ -13,20 +13,20 @@  discard block
 block discarded – undo
13 13
 	 * @return array[]
14 14
 	 */
15 15
 	public function getUsersToProcess() : array {
16
-		if ( $this->users === null ) {
17
-			$this->getLogger()->debug( 'Retrieving users list' );
18
-			$content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) );
19
-			$listUsers = json_decode( $content, true );
16
+		if ($this->users === null) {
17
+			$this->getLogger()->debug('Retrieving users list');
18
+			$content = $this->getController()->getPageContent($this->getConfig()->get('list-title'));
19
+			$listUsers = json_decode($content, true);
20 20
 
21 21
 			$this->users = [];
22
-			foreach ( $listUsers as $user => $groups ) {
23
-				$timestamp = $this->getValidTimestamp( $groups );
22
+			foreach ($listUsers as $user => $groups) {
23
+				$timestamp = $this->getValidTimestamp($groups);
24 24
 
25
-				if ( date( 'd/m', $timestamp ) === date( 'd/m' ) &&
25
+				if (date('d/m', $timestamp) === date('d/m') &&
26 26
 					// Don't trigger if the date is actually today
27
-					date( 'd/m/Y', $timestamp ) !== date( 'd/m/Y' )
27
+					date('d/m/Y', $timestamp) !== date('d/m/Y')
28 28
 				) {
29
-					$this->users[ $user ] = $groups;
29
+					$this->users[$user] = $groups;
30 30
 				}
31 31
 			}
32 32
 		}
@@ -40,17 +40,15 @@  discard block
 block discarded – undo
40 40
 	 * @param array $groups
41 41
 	 * @return int
42 42
 	 */
43
-	private function getValidTimestamp( array $groups ) : int {
44
-		$checkuser = isset( $groups[ 'checkuser' ] ) ?
45
-			\DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() :
46
-			0;
47
-		$bureaucrat = isset( $groups[ 'bureaucrat' ] ) ?
48
-			\DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() :
49
-			0;
43
+	private function getValidTimestamp(array $groups) : int {
44
+		$checkuser = isset($groups['checkuser']) ?
45
+			\DateTime::createFromFormat('d/m/Y', $groups['checkuser'])->getTimestamp() : 0;
46
+		$bureaucrat = isset($groups['bureaucrat']) ?
47
+			\DateTime::createFromFormat('d/m/Y', $groups['bureaucrat'])->getTimestamp() : 0;
50 48
 
51
-		$timestamp = max( $bureaucrat, $checkuser );
52
-		if ( $timestamp === 0 ) {
53
-			$timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp();
49
+		$timestamp = max($bureaucrat, $checkuser);
50
+		if ($timestamp === 0) {
51
+			$timestamp = \DateTime::createFromFormat('d/m/Y', $groups['sysop'])->getTimestamp();
54 52
 		}
55 53
 		return $timestamp;
56 54
 	}
@@ -58,8 +56,8 @@  discard block
 block discarded – undo
58 56
 	/**
59 57
 	 * @param string $name
60 58
 	 */
61
-	public function removeUser( string $name ) {
62
-		unset( $this->users[ $name ] );
59
+	public function removeUser(string $name) {
60
+		unset($this->users[$name]);
63 61
 	}
64 62
 
65 63
 	/**
@@ -72,7 +70,7 @@  discard block
 block discarded – undo
72 70
 	/**
73 71
 	 * @param string $title
74 72
 	 */
75
-	public function addCreatedPages( string $title ) {
73
+	public function addCreatedPages(string $title) {
76 74
 		$this->createdPages[] = $title;
77 75
 	}
78 76
 }
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
 
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
 	/**
7 7
 	 * @param string|null $title
8 8
 	 */
9
-	public function __construct( string $title = null ) {
10
-		if ( $title ) {
11
-			parent::__construct( "The specified page doesn't exist: $title" );
9
+	public function __construct(string $title = null) {
10
+		if ($title) {
11
+			parent::__construct("The specified page doesn't exist: $title");
12 12
 		} else {
13 13
 			parent::__construct();
14 14
 		}
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
 
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
 	/**
7 7
 	 * @param string|null $title
8 8
 	 */
9
-	public function __construct( string $title = null ) {
10
-		if ( $title ) {
11
-			parent::__construct( "The specified page is protected: $title" );
9
+	public function __construct(string $title = null) {
10
+		if ($title) {
11
+			parent::__construct("The specified page is protected: $title");
12 12
 		} else {
13 13
 			parent::__construct();
14 14
 		}
Please login to merge, or discard this patch.
includes/Exception/TaskException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php declare( strict_types=1 );
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace BotRiconferme\Exception;
4 4
 
Please login to merge, or discard this patch.
includes/Logger.php 1 patch
Spacing   +3 added lines, -3 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
 
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	/**
9 9
 	 * @inheritDoc
10 10
 	 */
11
-	public function log( $level, $message, array $context = [] ) {
12
-		error_log( "$level - $message" );
11
+	public function log($level, $message, array $context = []) {
12
+		error_log("$level - $message");
13 13
 	}
14 14
 }
Please login to merge, or discard this patch.
includes/Task/UserNotice.php 1 patch
Spacing   +16 added lines, -16 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
 
@@ -9,39 +9,39 @@  discard block
 block discarded – undo
9 9
 	 * @inheritDoc
10 10
 	 */
11 11
 	public function run() : TaskResult {
12
-		$this->getLogger()->info( 'Starting task UserNotice' );
12
+		$this->getLogger()->info('Starting task UserNotice');
13 13
 
14 14
 		$ricNums = [];
15
-		foreach ( $this->getDataProvider()->getCreatedPages() as $page ) {
16
-			$bits = explode( '/', $page );
17
-			$num = intval( array_pop( $bits ) );
18
-			$ricNums[ array_pop( $bits ) ] = $num;
15
+		foreach ($this->getDataProvider()->getCreatedPages() as $page) {
16
+			$bits = explode('/', $page);
17
+			$num = intval(array_pop($bits));
18
+			$ricNums[array_pop($bits)] = $num;
19 19
 		}
20 20
 
21
-		foreach ( $this->getDataProvider()->getUsersToProcess() as $user => $_ ) {
22
-			$this->addMsg( $user, $ricNums[ $user ] );
21
+		foreach ($this->getDataProvider()->getUsersToProcess() as $user => $_) {
22
+			$this->addMsg($user, $ricNums[$user]);
23 23
 		}
24 24
 
25
-		$this->getLogger()->info( 'Task UserNotice completed successfully' );
26
-		return new TaskResult( self::STATUS_OK );
25
+		$this->getLogger()->info('Task UserNotice completed successfully');
26
+		return new TaskResult(self::STATUS_OK);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @param string $user
31 31
 	 * @param int $ricNum
32 32
 	 */
33
-	protected function addMsg( string $user, int $ricNum ) {
34
-		$this->getLogger()->info( "Leaving msg to $user" );
35
-		$msg = str_replace( '$num', "$ricNum", $this->getConfig()->get( 'user-notice-msg' ) );
33
+	protected function addMsg(string $user, int $ricNum) {
34
+		$this->getLogger()->info("Leaving msg to $user");
35
+		$msg = str_replace('$num', "$ricNum", $this->getConfig()->get('user-notice-msg'));
36 36
 
37 37
 		$params = [
38 38
 			'title' => "User talk:$user",
39 39
 			'section' => 'new',
40 40
 			'text' => $msg,
41
-			'sectiontitle' => $this->getConfig()->get( 'user-notice-title' ),
42
-			'summary' => $this->getConfig()->get( 'user-notice-summary' )
41
+			'sectiontitle' => $this->getConfig()->get('user-notice-title'),
42
+			'summary' => $this->getConfig()->get('user-notice-summary')
43 43
 		];
44 44
 
45
-		$this->getController()->editPage( $params );
45
+		$this->getController()->editPage($params);
46 46
 	}
47 47
 }
Please login to merge, or discard this patch.
includes/Task/UpdatesAround.php 1 patch
Spacing   +41 added lines, -41 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
 
@@ -10,83 +10,83 @@  discard block
 block discarded – undo
10 10
 	 * @inheritDoc
11 11
 	 */
12 12
 	public function run() : TaskResult {
13
-		$this->getLogger()->info( 'Starting task UpdatesAround' );
13
+		$this->getLogger()->info('Starting task UpdatesAround');
14 14
 
15
-		foreach ( $this->getDataProvider()->getCreatedPages() as $page ) {
15
+		foreach ($this->getDataProvider()->getCreatedPages() as $page) {
16 16
 			// Wikipedia:Amministratori/Riconferma annuale
17
-			$this->addToMainPage( $page );
17
+			$this->addToMainPage($page);
18 18
 			// WP:Wikipediano/Votazioni
19
-			$this->addVote( $page );
19
+			$this->addVote($page);
20 20
 			// Template:VotazioniRCnews
21
-			$this->addNews( $page );
21
+			$this->addNews($page);
22 22
 		}
23 23
 
24
-		$this->getLogger()->info( 'Task UpdatesAround completed successfully' );
25
-		return new TaskResult( self::STATUS_OK );
24
+		$this->getLogger()->info('Task UpdatesAround completed successfully');
25
+		return new TaskResult(self::STATUS_OK);
26 26
 	}
27 27
 
28 28
 	/**
29 29
 	 * @param string $page
30 30
 	 */
31
-	protected function addToMainPage( string $page ) {
32
-		$this->getLogger()->info( "Adding $page to main" );
31
+	protected function addToMainPage(string $page) {
32
+		$this->getLogger()->info("Adding $page to main");
33 33
 
34 34
 		$params = [
35
-			'title' => $this->getConfig()->get( 'ric-main-page' ),
35
+			'title' => $this->getConfig()->get('ric-main-page'),
36 36
 			'appendtext' => '{{' . $page . '}}',
37
-			'summary' => $this->getConfig()->get( 'ric-main-page-summary' )
37
+			'summary' => $this->getConfig()->get('ric-main-page-summary')
38 38
 		];
39 39
 
40
-		$this->getController()->editPage( $params );
40
+		$this->getController()->editPage($params);
41 41
 	}
42 42
 
43 43
 	/**
44 44
 	 * @param string $page
45 45
 	 */
46
-	protected function addVote( string $page ) {
47
-		$this->getLogger()->info( "Adding $page to votes" );
48
-		$votePage = $this->getConfig()->get( 'ric-vote-page' );
46
+	protected function addVote(string $page) {
47
+		$this->getLogger()->info("Adding $page to votes");
48
+		$votePage = $this->getConfig()->get('ric-vote-page');
49 49
 
50
-		$content = $this->getController()->getPageContent( $votePage );
50
+		$content = $this->getController()->getPageContent($votePage);
51 51
 		// Remove comments etc.
52
-		$visibleContent = strip_tags( $content );
53
-		$user = explode( '/', $page )[2];
52
+		$visibleContent = strip_tags($content);
53
+		$user = explode('/', $page)[2];
54 54
 		$time = $this->getTimeWithArticle();
55 55
 
56 56
 		$newLine = "*[[Utente:$user|]]. La [[$page|procedura]] termina $time";
57 57
 
58 58
 		$introReg = '!^;È in corso la .*riconferma tacita.* degli .*amministratori.+!m';
59
-		if ( preg_match( $introReg, $visibleContent ) ) {
60
-			$newContent = preg_replace( $introReg, "$0\n$newLine;", $content, 1 );
59
+		if (preg_match($introReg, $visibleContent)) {
60
+			$newContent = preg_replace($introReg, "$0\n$newLine;", $content, 1);
61 61
 		} else {
62 62
 			$matches = [];
63
-			if ( preg_match( $introReg, $content, $matches ) === false ) {
64
-				throw new TaskException( 'Intro not found in vote page' );
63
+			if (preg_match($introReg, $content, $matches) === false) {
64
+				throw new TaskException('Intro not found in vote page');
65 65
 			}
66 66
 			$beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m';
67
-			$newContent = preg_replace( $beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1 );
67
+			$newContent = preg_replace($beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1);
68 68
 		}
69 69
 
70 70
 		$params = [
71 71
 			'title' => $votePage,
72 72
 			'text' => $newContent,
73
-			'summary' => $this->getConfig()->get( 'ric-vote-page-summary' )
73
+			'summary' => $this->getConfig()->get('ric-vote-page-summary')
74 74
 		];
75 75
 
76
-		$this->getController()->editPage( $params );
76
+		$this->getController()->editPage($params);
77 77
 	}
78 78
 
79 79
 	/**
80 80
 	 * @return string
81 81
 	 */
82 82
 	private function getTimeWithArticle() : string {
83
-		$oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' );
84
-		$endTS = time() + ( 60 * 60 * 24 * 7 );
85
-		$endTime = strftime( '%e %B alle %R', $endTS );
83
+		$oldLoc = setlocale(LC_TIME, 'it_IT', 'Italian_Italy', 'Italian');
84
+		$endTS = time() + (60 * 60 * 24 * 7);
85
+		$endTime = strftime('%e %B alle %R', $endTS);
86 86
 		// Remove the left space if day has a single digit
87
-		$endTime = ltrim( $endTime );
88
-		$artic = in_array( date( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il ";
89
-		setlocale( LC_TIME, $oldLoc );
87
+		$endTime = ltrim($endTime);
88
+		$artic = in_array(date('j', $endTS), [8, 11]) ? "l'" : "il ";
89
+		setlocale(LC_TIME, $oldLoc);
90 90
 
91 91
 		return $artic . $endTime;
92 92
 	}
@@ -94,27 +94,27 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	 * @param string $page
96 96
 	 */
97
-	protected function addNews( string $page ) {
98
-		$this->getLogger()->info( "Adding $page to news" );
99
-		$newsPage = $this->getConfig()->get( 'ric-news-page' );
97
+	protected function addNews(string $page) {
98
+		$this->getLogger()->info("Adding $page to news");
99
+		$newsPage = $this->getConfig()->get('ric-news-page');
100 100
 
101
-		$content = $this->getController()->getPageContent( $newsPage );
101
+		$content = $this->getController()->getPageContent($newsPage);
102 102
 		$reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!';
103 103
 
104 104
 		$matches = [];
105
-		if ( preg_match( $reg, $content, $matches ) === false ) {
106
-			throw new TaskException( 'Param not found in news page' );
105
+		if (preg_match($reg, $content, $matches) === false) {
106
+			throw new TaskException('Param not found in news page');
107 107
 		}
108 108
 
109 109
 		$newNum = (int)$matches[2] + 1;
110
-		$newContent = preg_replace( $reg, '${1}' . $newNum, $content );
110
+		$newContent = preg_replace($reg, '${1}' . $newNum, $content);
111 111
 
112 112
 		$params = [
113 113
 			'title' => $newsPage,
114 114
 			'text' => $newContent,
115
-			'summary' => $this->getConfig()->get( 'ric-news-page-summary' )
115
+			'summary' => $this->getConfig()->get('ric-news-page-summary')
116 116
 		];
117 117
 
118
-		$this->getController()->editPage( $params );
118
+		$this->getController()->editPage($params);
119 119
 	}
120 120
 }
Please login to merge, or discard this patch.
includes/Task/Task.php 1 patch
Spacing   +8 added lines, -8 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,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @param TaskDataProvider $dataProvider
20 20
 	 */
21
-	public function __construct( TaskDataProvider $dataProvider ) {
22
-		set_exception_handler( [ $this, 'handleException' ] );
23
-		set_error_handler( [ $this, 'handleError' ] );
21
+	public function __construct(TaskDataProvider $dataProvider) {
22
+		set_exception_handler([$this, 'handleException']);
23
+		set_error_handler([$this, 'handleError']);
24 24
 		parent::__construct();
25 25
 		$this->dataProvider = $dataProvider;
26 26
 	}
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param \Throwable $ex
44 44
 	 * @protected
45 45
 	 */
46
-	public function handleException( \Throwable $ex ) {
46
+	public function handleException(\Throwable $ex) {
47 47
 		$this->getLogger()->error(
48
-			get_class( $ex ) . ': ' .
48
+			get_class($ex) . ': ' .
49 49
 			$ex->getMessage() . "\nTrace:\n" .
50 50
 			$ex->getTraceAsString()
51 51
 		);
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @param int $errline
61 61
 	 * @protected
62 62
 	 */
63
-	public function handleError( $errno, $errstr, $errfile, $errline ) {
64
-		throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline );
63
+	public function handleError($errno, $errstr, $errfile, $errline) {
64
+		throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
65 65
 	}
66 66
 
67 67
 	/**
Please login to merge, or discard this patch.