@@ -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 | } |
@@ -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 | |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | * Entry point for the whole process |
| 17 | 17 | */ |
| 18 | 18 | public function run() { |
| 19 | - $this->logger->info( 'Starting full process.' ); |
|
| 19 | + $this->logger->info('Starting full process.'); |
|
| 20 | 20 | $manager = new TaskManager; |
| 21 | - $res = $manager->run( TaskManager::MODE_COMPLETE ); |
|
| 21 | + $res = $manager->run(TaskManager::MODE_COMPLETE); |
|
| 22 | 22 | $line = '---------------------------------------------------'; |
| 23 | - if ( $res->isOK() ) { |
|
| 24 | - $this->logger->info( "Execution completed successfully.\n$line\n\n" ); |
|
| 23 | + if ($res->isOK()) { |
|
| 24 | + $this->logger->info("Execution completed successfully.\n$line\n\n"); |
|
| 25 | 25 | } else { |
| 26 | - $this->logger->error( "Execution failed.\n$res\n$line\n\n" ); |
|
| 26 | + $this->logger->error("Execution failed.\n$res\n$line\n\n"); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param string $task |
| 34 | 34 | */ |
| 35 | - public function runSingle( string $task ) { |
|
| 36 | - $this->logger->info( "Starting single task $task." ); |
|
| 35 | + public function runSingle(string $task) { |
|
| 36 | + $this->logger->info("Starting single task $task."); |
|
| 37 | 37 | $manager = new TaskManager; |
| 38 | - $res = $manager->run( TaskManager::MODE_SINGLE, $task ); |
|
| 38 | + $res = $manager->run(TaskManager::MODE_SINGLE, $task); |
|
| 39 | 39 | $line = '---------------------------------------------------'; |
| 40 | - if ( $res->isOK() ) { |
|
| 41 | - $this->logger->info( "Execution of $task completed successfully.\n$line\n\n" ); |
|
| 40 | + if ($res->isOK()) { |
|
| 41 | + $this->logger->info("Execution of $task completed successfully.\n$line\n\n"); |
|
| 42 | 42 | } else { |
| 43 | - $this->logger->error( "Execution of $task failed.\n$res\n$line\n\n" ); |
|
| 43 | + $this->logger->error("Execution of $task failed.\n$res\n$line\n\n"); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | require __DIR__ . '/vendor/autoload.php'; |
| 4 | 4 | |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | use BotRiconferme\Bot; |
| 7 | 7 | use BotRiconferme\Request\RequestBase; |
| 8 | 8 | |
| 9 | -if ( PHP_SAPI !== 'cli' ) { |
|
| 10 | - exit( 'CLI only!' ); |
|
| 9 | +if (PHP_SAPI !== 'cli') { |
|
| 10 | + exit('CLI only!'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** MAIN PARAMS */ |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | 'config-title:' |
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | -$vals = getopt( '', $params ); |
|
| 30 | -if ( count( $vals ) !== count( $params ) ) { |
|
| 31 | - exit( 'Not enough params!' ); |
|
| 29 | +$vals = getopt('', $params); |
|
| 30 | +if (count($vals) !== count($params)) { |
|
| 31 | + exit('Not enough params!'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /* URL (for debugging purpose) */ |
| 35 | -$url = getopt( '', [ 'force-url:' ] ); |
|
| 36 | -if ( isset( $url['force-url'] ) ) { |
|
| 35 | +$url = getopt('', ['force-url:']); |
|
| 36 | +if (isset($url['force-url'])) { |
|
| 37 | 37 | RequestBase::$url = $url['force-url']; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -47,38 +47,38 @@ discard block |
||
| 47 | 47 | * --use-password-file |
| 48 | 48 | * which will look for a $PWFILE file in the current directory containing only the plain password |
| 49 | 49 | */ |
| 50 | -$pwParams = getopt( '', [ |
|
| 50 | +$pwParams = getopt('', [ |
|
| 51 | 51 | 'password:', |
| 52 | 52 | 'use-password-file' |
| 53 | -] ); |
|
| 53 | +]); |
|
| 54 | 54 | |
| 55 | -if ( isset( $pwParams[ 'password' ] ) ) { |
|
| 56 | - $pw = $pwParams[ 'password' ]; |
|
| 57 | -} elseif ( isset( $pwParams[ 'use-password-file' ] ) ) { |
|
| 58 | - if ( file_exists( $PWFILE ) ) { |
|
| 59 | - $pw = trim( file_get_contents( $PWFILE ) ); |
|
| 55 | +if (isset($pwParams['password'])) { |
|
| 56 | + $pw = $pwParams['password']; |
|
| 57 | +} elseif (isset($pwParams['use-password-file'])) { |
|
| 58 | + if (file_exists($PWFILE)) { |
|
| 59 | + $pw = trim(file_get_contents($PWFILE)); |
|
| 60 | 60 | } else { |
| 61 | - exit( 'Please create a password.txt file to use with use-password-file' ); |
|
| 61 | + exit('Please create a password.txt file to use with use-password-file'); |
|
| 62 | 62 | } |
| 63 | 63 | } else { |
| 64 | - exit( 'Please provide a password or use a password file' ); |
|
| 64 | + exit('Please provide a password or use a password file'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | -$vals[ 'password' ] = $pw; |
|
| 67 | +$vals['password'] = $pw; |
|
| 68 | 68 | |
| 69 | 69 | /* START */ |
| 70 | 70 | |
| 71 | -Config::init( $vals ); |
|
| 71 | +Config::init($vals); |
|
| 72 | 72 | |
| 73 | 73 | $bot = new Bot(); |
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | * E.g. --task=update-list |
| 77 | 77 | */ |
| 78 | -$taskOpts = getopt( '', [ 'task:' ] ); |
|
| 78 | +$taskOpts = getopt('', ['task:']); |
|
| 79 | 79 | |
| 80 | -if ( $taskOpts ) { |
|
| 81 | - $bot->runSingle( $taskOpts[ 'task' ] ); |
|
| 80 | +if ($taskOpts) { |
|
| 81 | + $bot->runSingle($taskOpts['task']); |
|
| 82 | 82 | } else { |
| 83 | 83 | $bot->run(); |
| 84 | 84 | } |