@@ -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 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | * @throws MissingPageException |
| 26 | 26 | */ |
| 27 | - public function getPageContent( string $title ) : string { |
|
| 28 | - $this->logger->debug( "Retrieving page $title" ); |
|
| 27 | + public function getPageContent(string $title) : string { |
|
| 28 | + $this->logger->debug("Retrieving page $title"); |
|
| 29 | 29 | $params = [ |
| 30 | 30 | 'action' => 'query', |
| 31 | 31 | 'titles' => $title, |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | 'rvlimit' => 1 |
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | - $req = RequestBase::newFromParams( $params ); |
|
| 38 | + $req = RequestBase::newFromParams($params); |
|
| 39 | 39 | $data = $req->execute(); |
| 40 | - $page = reset( $data['query']['pages'] ); |
|
| 41 | - if ( isset( $page['missing'] ) ) { |
|
| 42 | - throw new MissingPageException( $title ); |
|
| 40 | + $page = reset($data['query']['pages']); |
|
| 41 | + if (isset($page['missing'])) { |
|
| 42 | + throw new MissingPageException($title); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | return $page['revisions'][0]['slots']['main']['*']; |
@@ -51,19 +51,19 @@ discard block |
||
| 51 | 51 | * @param array $params |
| 52 | 52 | * @throws APIRequestException |
| 53 | 53 | */ |
| 54 | - public function editPage( array $params ) { |
|
| 54 | + public function editPage(array $params) { |
|
| 55 | 55 | $this->login(); |
| 56 | 56 | |
| 57 | 57 | $params = [ |
| 58 | 58 | 'action' => 'edit', |
| 59 | - 'token' => $this->getToken( 'csrf' ), |
|
| 60 | - 'bot' => Config::getInstance()->get( 'bot-edits' ) |
|
| 59 | + 'token' => $this->getToken('csrf'), |
|
| 60 | + 'bot' => Config::getInstance()->get('bot-edits') |
|
| 61 | 61 | ] + $params; |
| 62 | 62 | |
| 63 | - $req = RequestBase::newFromParams( $params, true ); |
|
| 63 | + $req = RequestBase::newFromParams($params, true); |
|
| 64 | 64 | $res = $req->execute(); |
| 65 | - if ( $res['edit']['result'] !== 'Success' ) { |
|
| 66 | - throw new APIRequestException( $res['edit']['info'] ); |
|
| 65 | + if ($res['edit']['result'] !== 'Success') { |
|
| 66 | + throw new APIRequestException($res['edit']['info']); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -71,55 +71,55 @@ discard block |
||
| 71 | 71 | * @throws LoginException |
| 72 | 72 | */ |
| 73 | 73 | public function login() { |
| 74 | - if ( self::$loggedIn ) { |
|
| 75 | - $this->logger->debug( 'Already logged in' ); |
|
| 74 | + if (self::$loggedIn) { |
|
| 75 | + $this->logger->debug('Already logged in'); |
|
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $this->logger->debug( 'Logging in' ); |
|
| 79 | + $this->logger->debug('Logging in'); |
|
| 80 | 80 | |
| 81 | 81 | $params = [ |
| 82 | 82 | 'action' => 'login', |
| 83 | - 'lgname' => Config::getInstance()->get( 'username' ), |
|
| 84 | - 'lgpassword' => Config::getInstance()->get( 'password' ), |
|
| 85 | - 'lgtoken' => $this->getToken( 'login' ) |
|
| 83 | + 'lgname' => Config::getInstance()->get('username'), |
|
| 84 | + 'lgpassword' => Config::getInstance()->get('password'), |
|
| 85 | + 'lgtoken' => $this->getToken('login') |
|
| 86 | 86 | ]; |
| 87 | 87 | |
| 88 | 88 | try { |
| 89 | - $req = RequestBase::newFromParams( $params, true ); |
|
| 89 | + $req = RequestBase::newFromParams($params, true); |
|
| 90 | 90 | $res = $req->execute(); |
| 91 | - } catch ( APIRequestException $e ) { |
|
| 92 | - throw new LoginException( $e->getMessage() ); |
|
| 91 | + } catch (APIRequestException $e) { |
|
| 92 | + throw new LoginException($e->getMessage()); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ( !isset( $res['login']['result'] ) || $res['login']['result'] !== 'Success' ) { |
|
| 96 | - throw new LoginException( 'Unknown error' ); |
|
| 95 | + if (!isset($res['login']['result']) || $res['login']['result'] !== 'Success') { |
|
| 96 | + throw new LoginException('Unknown error'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | self::$loggedIn = true; |
| 100 | 100 | // Clear tokens cache |
| 101 | 101 | $this->tokens = []; |
| 102 | - $this->logger->debug( 'Login succeeded' ); |
|
| 102 | + $this->logger->debug('Login succeeded'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * @param string $type |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - public function getToken( string $type ) : string { |
|
| 110 | - if ( !isset( $this->tokens[ $type ] ) ) { |
|
| 109 | + public function getToken(string $type) : string { |
|
| 110 | + if (!isset($this->tokens[$type])) { |
|
| 111 | 111 | $params = [ |
| 112 | 112 | 'action' => 'query', |
| 113 | 113 | 'meta' => 'tokens', |
| 114 | 114 | 'type' => $type |
| 115 | 115 | ]; |
| 116 | 116 | |
| 117 | - $req = RequestBase::newFromParams( $params ); |
|
| 117 | + $req = RequestBase::newFromParams($params); |
|
| 118 | 118 | $res = $req->execute(); |
| 119 | 119 | |
| 120 | - $this->tokens[ $type ] = $res['query']['tokens']["{$type}token"]; |
|
| 120 | + $this->tokens[$type] = $res['query']['tokens']["{$type}token"]; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - return $this->tokens[ $type ]; |
|
| 123 | + return $this->tokens[$type]; |
|
| 124 | 124 | } |
| 125 | 125 | } |