Passed
Push — master ( 5ab0bb...aeb3c7 )
by Daimona
02:13
created
includes/Request/CurlRequest.php 1 patch
Spacing   +22 added lines, -22 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\Request;
4 4
 
@@ -11,36 +11,36 @@  discard block
 block discarded – undo
11 11
 	/**
12 12
 	 * @inheritDoc
13 13
 	 */
14
-	protected function reallyMakeRequest( string $params ) : string {
15
-		$curl = curl_init();
14
+	protected function reallyMakeRequest ( string $params ) : string {
15
+		$curl = curl_init ();
16 16
 		if ( $curl === false ) {
17
-			throw new APIRequestException( 'Cannot open cURL handler.' );
17
+			throw new APIRequestException ( 'Cannot open cURL handler.' );
18 18
 		}
19
-		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
20
-		curl_setopt( $curl, CURLOPT_HEADER, true );
21
-		curl_setopt( $curl, CURLOPT_HEADERFUNCTION, [ $this, 'headersHandler' ] );
22
-		curl_setopt( $curl, CURLOPT_HTTPHEADER, $this->getHeaders() );
19
+		curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
20
+		curl_setopt ( $curl, CURLOPT_HEADER, true );
21
+		curl_setopt ( $curl, CURLOPT_HEADERFUNCTION, [ $this, 'headersHandler' ] );
22
+		curl_setopt ( $curl, CURLOPT_HTTPHEADER, $this->getHeaders () );
23 23
 
24 24
 		$url = self::$url;
25 25
 		if ( $this->method === 'POST' ) {
26
-			curl_setopt( $curl, CURLOPT_URL, $url );
27
-			curl_setopt( $curl, CURLOPT_POST, true );
28
-			curl_setopt( $curl, CURLOPT_POSTFIELDS, $params );
26
+			curl_setopt ( $curl, CURLOPT_URL, $url );
27
+			curl_setopt ( $curl, CURLOPT_POST, true );
28
+			curl_setopt ( $curl, CURLOPT_POSTFIELDS, $params );
29 29
 		} else {
30
-			curl_setopt( $curl, CURLOPT_URL, "$url?$params" );
30
+			curl_setopt ( $curl, CURLOPT_URL, "$url?$params" );
31 31
 		}
32 32
 
33
-		$result = curl_exec( $curl );
33
+		$result = curl_exec ( $curl );
34 34
 
35 35
 		if ( $result === false ) {
36
-			throw new APIRequestException( curl_error( $curl ) );
36
+			throw new APIRequestException ( curl_error ( $curl ) );
37 37
 		}
38 38
 
39 39
 		// Extract response body
40
-		$headerSize = curl_getinfo( $curl, CURLINFO_HEADER_SIZE );
40
+		$headerSize = curl_getinfo ( $curl, CURLINFO_HEADER_SIZE );
41 41
 		/** @var string $result Because RETURNTRANSFER is set */
42
-		$body = substr( $result, $headerSize );
43
-		curl_close( $curl );
42
+		$body = substr ( $result, $headerSize );
43
+		curl_close ( $curl );
44 44
 
45 45
 		return $body;
46 46
 	}
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 	 * @return int
54 54
 	 * @internal Only used as CB for cURL
55 55
 	 */
56
-	public function headersHandler( $ch, string $header ) : int {
57
-		$bits = explode( ':', $header, 2 );
58
-		if ( trim( $bits[0] ) === 'Set-Cookie' ) {
59
-			$this->newCookies[] = $bits[1];
56
+	public function headersHandler ( $ch, string $header ) : int {
57
+		$bits = explode ( ':', $header, 2 );
58
+		if ( trim ( $bits[ 0 ] ) === 'Set-Cookie' ) {
59
+			$this->newCookies[ ] = $bits[ 1 ];
60 60
 		}
61 61
 		// @phan-suppress-next-line PhanTypeMismatchReturn WTF? Why does phan thinks this is a string?
62
-		return strlen( $header );
62
+		return strlen ( $header );
63 63
 	}
64 64
 }
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.