@@ -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 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @param int $status One of the Task::STATUS_* constants |
| 18 | 18 | * @param string[] $errors |
| 19 | 19 | */ |
| 20 | - public function __construct( int $status, array $errors = [] ) { |
|
| 20 | + public function __construct(int $status, array $errors = []) { |
|
| 21 | 21 | $this->status = $status; |
| 22 | 22 | $this->errors = $errors; |
| 23 | 23 | } |
@@ -39,25 +39,25 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @param TaskResult $that |
| 41 | 41 | */ |
| 42 | - public function merge( TaskResult $that ) { |
|
| 42 | + public function merge(TaskResult $that) { |
|
| 43 | 43 | $this->status |= $that->status; |
| 44 | - $this->errors = array_merge( $this->errors, $that->errors ); |
|
| 44 | + $this->errors = array_merge($this->errors, $that->errors); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | 50 | public function __toString() { |
| 51 | - if ( $this->isOK() ) { |
|
| 51 | + if ($this->isOK()) { |
|
| 52 | 52 | $stat = 'OK'; |
| 53 | 53 | $errs = "\tNo errors."; |
| 54 | 54 | } else { |
| 55 | 55 | $stat = 'ERROR'; |
| 56 | 56 | $formattedErrs = []; |
| 57 | - foreach ( $this->errors as $err ) { |
|
| 57 | + foreach ($this->errors as $err) { |
|
| 58 | 58 | $formattedErrs[] = "\t - $err"; |
| 59 | 59 | } |
| 60 | - $errs = implode( "\n", $formattedErrs ); |
|
| 60 | + $errs = implode("\n", $formattedErrs); |
|
| 61 | 61 | } |
| 62 | 62 | return "=== RESULT ===\n - Status: $stat\n - Errors:\n$errs\n"; |
| 63 | 63 | } |
@@ -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 | |
@@ -14,13 +14,13 @@ discard block |
||
| 14 | 14 | * Entry point for the whole process |
| 15 | 15 | */ |
| 16 | 16 | public function run() { |
| 17 | - $this->logger->info( 'Starting full process.' ); |
|
| 17 | + $this->logger->info('Starting full process.'); |
|
| 18 | 18 | $manager = new TaskManager; |
| 19 | - $res = $manager->run( TaskManager::MODE_COMPLETE ); |
|
| 20 | - if ( $res->isOK() ) { |
|
| 21 | - $this->logger->info( 'Execution completed successfully.' ); |
|
| 19 | + $res = $manager->run(TaskManager::MODE_COMPLETE); |
|
| 20 | + if ($res->isOK()) { |
|
| 21 | + $this->logger->info('Execution completed successfully.'); |
|
| 22 | 22 | } else { |
| 23 | - $this->logger->error( "Execution failed.\n$res" ); |
|
| 23 | + $this->logger->error("Execution failed.\n$res"); |
|
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param string $task |
| 31 | 31 | */ |
| 32 | - public function runSingle( string $task ) { |
|
| 33 | - $this->logger->info( "Starting single task $task." ); |
|
| 32 | + public function runSingle(string $task) { |
|
| 33 | + $this->logger->info("Starting single task $task."); |
|
| 34 | 34 | $manager = new TaskManager; |
| 35 | - $res = $manager->run( TaskManager::MODE_SINGLE, $task ); |
|
| 36 | - if ( $res->isOK() ) { |
|
| 37 | - $this->logger->info( "Execution of $task completed successfully." ); |
|
| 35 | + $res = $manager->run(TaskManager::MODE_SINGLE, $task); |
|
| 36 | + if ($res->isOK()) { |
|
| 37 | + $this->logger->info("Execution of $task completed successfully."); |
|
| 38 | 38 | } else { |
| 39 | - $this->logger->error( "Execution of $task failed.\n$res" ); |
|
| 39 | + $this->logger->error("Execution of $task failed.\n$res"); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -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 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * Should only be used for debugging purpose. |
| 30 | 30 | */ |
| 31 | 31 | public static function resetLastRunDate() { |
| 32 | - file_put_contents( self::LOG_FILE, '' ); |
|
| 32 | + file_put_contents(self::LOG_FILE, ''); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param string|null $taskName Only used in MODE_SINGLE |
| 38 | 38 | * @return TaskResult |
| 39 | 39 | */ |
| 40 | - public function run( int $mode, string $taskName = null ) : TaskResult { |
|
| 40 | + public function run(int $mode, string $taskName = null) : TaskResult { |
|
| 41 | 41 | $this->provider = new TaskDataProvider; |
| 42 | - if ( $mode === self::MODE_COMPLETE ) { |
|
| 42 | + if ($mode === self::MODE_COMPLETE) { |
|
| 43 | 43 | return $this->runAllTasks(); |
| 44 | 44 | } else { |
| 45 | - return $this->runTask( $taskName ); |
|
| 45 | + return $this->runTask($taskName); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | * @return TaskResult |
| 51 | 51 | */ |
| 52 | 52 | protected function runAllTasks() : TaskResult { |
| 53 | - if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) { |
|
| 53 | + if (self::getLastFullRunDate() === date('d/m/Y')) { |
|
| 54 | 54 | // Really avoid executing twice the same day |
| 55 | - return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] ); |
|
| 55 | + return new TaskResult(TaskResult::STATUS_ERROR, ['A full run was already executed today.']); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Order matters here |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | 'user-notice' |
| 64 | 64 | ]; |
| 65 | 65 | |
| 66 | - $res = new TaskResult( TaskResult::STATUS_OK ); |
|
| 66 | + $res = new TaskResult(TaskResult::STATUS_OK); |
|
| 67 | 67 | do { |
| 68 | - $res->merge( $this->runTask( current( $list ) ) ); |
|
| 69 | - } while ( $res->isOK() && next( $list ) ); |
|
| 68 | + $res->merge($this->runTask(current($list))); |
|
| 69 | + } while ($res->isOK() && next($list)); |
|
| 70 | 70 | |
| 71 | - if ( $res->isOK() ) { |
|
| 71 | + if ($res->isOK()) { |
|
| 72 | 72 | self::setLastFullRunDate(); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | * @return string|null d/m/Y or null if no last run registered |
| 80 | 80 | */ |
| 81 | 81 | public static function getLastFullRunDate() : ?string { |
| 82 | - if ( file_exists( self::LOG_FILE ) ) { |
|
| 83 | - return file_get_contents( self::LOG_FILE ) ?: null; |
|
| 82 | + if (file_exists(self::LOG_FILE)) { |
|
| 83 | + return file_get_contents(self::LOG_FILE) ?: null; |
|
| 84 | 84 | } else { |
| 85 | 85 | return null; |
| 86 | 86 | } |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * @param string $task Defined in self::TASKS_MAP |
| 91 | 91 | * @return TaskResult |
| 92 | 92 | */ |
| 93 | - protected function runTask( string $task ) : TaskResult { |
|
| 94 | - if ( !isset( self::TASKS_MAP[ $task ] ) ) { |
|
| 95 | - throw new \InvalidArgumentException( "'$task' is not a valid task." ); |
|
| 93 | + protected function runTask(string $task) : TaskResult { |
|
| 94 | + if (!isset(self::TASKS_MAP[$task])) { |
|
| 95 | + throw new \InvalidArgumentException("'$task' is not a valid task."); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $class = self::TASKS_MAP[ $task ]; |
|
| 99 | - return $this->getTaskInstance( $class )->run(); |
|
| 98 | + $class = self::TASKS_MAP[$task]; |
|
| 99 | + return $this->getTaskInstance($class)->run(); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | * @param string $class |
| 106 | 106 | * @return Task |
| 107 | 107 | */ |
| 108 | - private function getTaskInstance( string $class ) : Task { |
|
| 109 | - return new $class( $this->provider ); |
|
| 108 | + private function getTaskInstance(string $class) : Task { |
|
| 109 | + return new $class($this->provider); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public static function setLastFullRunDate() { |
| 113 | - file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) ); |
|
| 113 | + file_put_contents(self::LOG_FILE, date('d/m/Y')); |
|
| 114 | 114 | } |
| 115 | 115 | } |
@@ -1,12 +1,12 @@ 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 | |
| 5 | 5 | use BotRiconferme\Config; |
| 6 | 6 | use BotRiconferme\Bot; |
| 7 | 7 | |
| 8 | -if ( PHP_SAPI !== 'cli' ) { |
|
| 9 | - exit( 'CLI only!' ); |
|
| 8 | +if (PHP_SAPI !== 'cli') { |
|
| 9 | + exit('CLI only!'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** MAIN PARAMS */ |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | 'config-title:' |
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | -$vals = getopt( '', $params ); |
|
| 31 | -if ( count( $vals ) !== count( $params ) ) { |
|
| 32 | - exit( 'Not enough params!' ); |
|
| 30 | +$vals = getopt('', $params); |
|
| 31 | +if (count($vals) !== count($params)) { |
|
| 32 | + exit('Not enough params!'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /* PASSWORD */ |
@@ -42,38 +42,38 @@ discard block |
||
| 42 | 42 | * --use-password-file |
| 43 | 43 | * which will look for a $PWFILE file in the current directory containing only the plain password |
| 44 | 44 | */ |
| 45 | -$pwParams = getopt( '', [ |
|
| 45 | +$pwParams = getopt('', [ |
|
| 46 | 46 | 'password:', |
| 47 | 47 | 'use-password-file' |
| 48 | -] ); |
|
| 48 | +]); |
|
| 49 | 49 | |
| 50 | -if ( isset( $pwParams[ 'password' ] ) ) { |
|
| 51 | - $pw = $pwParams[ 'password' ]; |
|
| 52 | -} elseif ( isset( $pwParams[ 'use-password-file' ] ) ) { |
|
| 53 | - if ( file_exists( $PWFILE ) ) { |
|
| 54 | - $pw = trim( file_get_contents( $PWFILE ) ); |
|
| 50 | +if (isset($pwParams['password'])) { |
|
| 51 | + $pw = $pwParams['password']; |
|
| 52 | +} elseif (isset($pwParams['use-password-file'])) { |
|
| 53 | + if (file_exists($PWFILE)) { |
|
| 54 | + $pw = trim(file_get_contents($PWFILE)); |
|
| 55 | 55 | } else { |
| 56 | - exit( 'Please create a password.txt file to use with use-password-file' ); |
|
| 56 | + exit('Please create a password.txt file to use with use-password-file'); |
|
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | - exit( 'Please provide a password or use a password file' ); |
|
| 59 | + exit('Please provide a password or use a password file'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | -$vals[ 'password' ] = $pw; |
|
| 62 | +$vals['password'] = $pw; |
|
| 63 | 63 | |
| 64 | 64 | /* START */ |
| 65 | 65 | |
| 66 | -Config::init( $vals ); |
|
| 66 | +Config::init($vals); |
|
| 67 | 67 | |
| 68 | 68 | $bot = new Bot(); |
| 69 | 69 | |
| 70 | 70 | /* |
| 71 | 71 | * E.g. --task=update-list |
| 72 | 72 | */ |
| 73 | -$taskOpts = getopt( '', [ 'task:' ] ); |
|
| 73 | +$taskOpts = getopt('', ['task:']); |
|
| 74 | 74 | |
| 75 | -if ( $taskOpts ) { |
|
| 76 | - $bot->runSingle( $taskOpts[ 'task' ] ); |
|
| 75 | +if ($taskOpts) { |
|
| 76 | + $bot->runSingle($taskOpts['task']); |
|
| 77 | 77 | } else { |
| 78 | 78 | $bot->run(); |
| 79 | 79 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @param array $params |
| 36 | 36 | * @param bool $isPOST |
| 37 | 37 | */ |
| 38 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 39 | - $this->params = [ 'format' => 'json' ] + $params; |
|
| 38 | + protected function __construct(array $params, bool $isPOST = false) { |
|
| 39 | + $this->params = ['format' => 'json'] + $params; |
|
| 40 | 40 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | * @param bool $isPOST |
| 48 | 48 | * @return self |
| 49 | 49 | */ |
| 50 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 51 | - if ( extension_loaded( 'curl' ) ) { |
|
| 52 | - $ret = new CurlRequest( $params, $isPOST ); |
|
| 50 | + public static function newFromParams(array $params, bool $isPOST = false) : self { |
|
| 51 | + if (extension_loaded('curl')) { |
|
| 52 | + $ret = new CurlRequest($params, $isPOST); |
|
| 53 | 53 | } else { |
| 54 | - $ret = new NativeRequest( $params, $isPOST ); |
|
| 54 | + $ret = new NativeRequest($params, $isPOST); |
|
| 55 | 55 | } |
| 56 | 56 | return $ret; |
| 57 | 57 | } |
@@ -65,19 +65,19 @@ discard block |
||
| 65 | 65 | $curParams = $this->params; |
| 66 | 66 | $sets = []; |
| 67 | 67 | do { |
| 68 | - $res = $this->makeRequestInternal( $curParams ); |
|
| 68 | + $res = $this->makeRequestInternal($curParams); |
|
| 69 | 69 | |
| 70 | - $this->handleErrorAndWarnings( $res ); |
|
| 70 | + $this->handleErrorAndWarnings($res); |
|
| 71 | 71 | $sets[] = $res; |
| 72 | 72 | |
| 73 | 73 | $finished = true; |
| 74 | - if ( isset( $res->continue ) ) { |
|
| 75 | - $curParams = array_merge( $curParams, get_object_vars( $res->continue ) ); |
|
| 74 | + if (isset($res->continue)) { |
|
| 75 | + $curParams = array_merge($curParams, get_object_vars($res->continue)); |
|
| 76 | 76 | $finished = false; |
| 77 | 77 | } |
| 78 | - } while ( !$finished ); |
|
| 78 | + } while (!$finished); |
|
| 79 | 79 | |
| 80 | - return $this->mergeSets( $sets ); |
|
| 80 | + return $this->mergeSets($sets); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | * @param array $params |
| 87 | 87 | * @return \stdClass |
| 88 | 88 | */ |
| 89 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 90 | - if ( $this->method === 'POST' ) { |
|
| 89 | + private function makeRequestInternal(array $params) : \stdClass { |
|
| 90 | + if ($this->method === 'POST') { |
|
| 91 | 91 | $params['maxlag'] = self::MAXLAG; |
| 92 | 92 | } |
| 93 | - $params = http_build_query( $params ); |
|
| 93 | + $params = http_build_query($params); |
|
| 94 | 94 | |
| 95 | - $body = $this->reallyMakeRequest( $params ); |
|
| 95 | + $body = $this->reallyMakeRequest($params); |
|
| 96 | 96 | |
| 97 | - $this->setCookies( $this->newCookies ); |
|
| 98 | - return json_decode( $body ); |
|
| 97 | + $this->setCookies($this->newCookies); |
|
| 98 | + return json_decode($body); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | * @param string $params |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 107 | + abstract protected function reallyMakeRequest(string $params) : string; |
|
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @param array $cookies |
| 111 | 111 | */ |
| 112 | - protected function setCookies( array $cookies ) { |
|
| 113 | - foreach ( $cookies as $cookie ) { |
|
| 114 | - $bits = explode( ';', $cookie ); |
|
| 115 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 116 | - self::$cookiesToSet[ $name ] = $value; |
|
| 112 | + protected function setCookies(array $cookies) { |
|
| 113 | + foreach ($cookies as $cookie) { |
|
| 114 | + $bits = explode(';', $cookie); |
|
| 115 | + list($name, $value) = explode('=', $bits[0]); |
|
| 116 | + self::$cookiesToSet[$name] = $value; |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * @param \stdClass $res |
| 122 | 122 | * @throws APIRequestException |
| 123 | 123 | */ |
| 124 | - protected function handleErrorAndWarnings( $res ) { |
|
| 125 | - if ( isset( $res->error ) ) { |
|
| 126 | - switch ( $res->error->code ) { |
|
| 124 | + protected function handleErrorAndWarnings($res) { |
|
| 125 | + if (isset($res->error)) { |
|
| 126 | + switch ($res->error->code) { |
|
| 127 | 127 | case 'missingtitle': |
| 128 | 128 | $ex = new MissingPageException; |
| 129 | 129 | break; |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | $ex = new ProtectedPageException; |
| 132 | 132 | break; |
| 133 | 133 | default: |
| 134 | - $ex = new APIRequestException( $res->error->code . ' - ' . $res->error->info ); |
|
| 134 | + $ex = new APIRequestException($res->error->code . ' - ' . $res->error->info); |
|
| 135 | 135 | } |
| 136 | 136 | throw $ex; |
| 137 | - } elseif ( isset( $res->warnings ) ) { |
|
| 138 | - $act = $this->params[ 'action' ]; |
|
| 137 | + } elseif (isset($res->warnings)) { |
|
| 138 | + $act = $this->params['action']; |
|
| 139 | 139 | $warning = $res->warnings->$act; |
| 140 | - throw new APIRequestException( reset( $warning ) ); |
|
| 140 | + throw new APIRequestException(reset($warning)); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
@@ -147,16 +147,16 @@ discard block |
||
| 147 | 147 | * @param \stdClass[] $sets |
| 148 | 148 | * @return array |
| 149 | 149 | */ |
| 150 | - private function mergeSets( array $sets ) : array { |
|
| 151 | - $sets = $this->objectToArray( $sets ); |
|
| 150 | + private function mergeSets(array $sets) : array { |
|
| 151 | + $sets = $this->objectToArray($sets); |
|
| 152 | 152 | // Use the first set as template |
| 153 | - $ret = array_shift( $sets ); |
|
| 153 | + $ret = array_shift($sets); |
|
| 154 | 154 | $act = $this->params['action']; |
| 155 | 155 | |
| 156 | - foreach ( $sets as $set ) { |
|
| 156 | + foreach ($sets as $set) { |
|
| 157 | 157 | $ret[$act] = array_merge_recursive( |
| 158 | - $this->objectToArray( $ret[$act] ), |
|
| 159 | - $this->objectToArray( $set[$act] ) |
|
| 158 | + $this->objectToArray($ret[$act]), |
|
| 159 | + $this->objectToArray($set[$act]) |
|
| 160 | 160 | ); |
| 161 | 161 | } |
| 162 | 162 | return $ret; |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | * @param \stdClass|array $objOrArray |
| 170 | 170 | * @return array |
| 171 | 171 | */ |
| 172 | - private function objectToArray( $objOrArray ) : array { |
|
| 172 | + private function objectToArray($objOrArray) : array { |
|
| 173 | 173 | $array = []; |
| 174 | - if ( is_object( $objOrArray ) ) { |
|
| 175 | - $objOrArray = get_object_vars( $objOrArray ); |
|
| 174 | + if (is_object($objOrArray)) { |
|
| 175 | + $objOrArray = get_object_vars($objOrArray); |
|
| 176 | 176 | } |
| 177 | - foreach ( $objOrArray as $key => $value ) { |
|
| 178 | - if ( is_object( $value ) || is_array( $value ) ) { |
|
| 179 | - $value = $this->objectToArray( $value ); |
|
| 177 | + foreach ($objOrArray as $key => $value) { |
|
| 178 | + if (is_object($value) || is_array($value)) { |
|
| 179 | + $value = $this->objectToArray($value); |
|
| 180 | 180 | } |
| 181 | 181 | $array[$key] = $value; |
| 182 | 182 | } |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | protected function getHeaders() :array { |
| 190 | 190 | $ret = self::HEADERS; |
| 191 | - if ( self::$cookiesToSet ) { |
|
| 191 | + if (self::$cookiesToSet) { |
|
| 192 | 192 | $cookies = []; |
| 193 | - foreach ( self::$cookiesToSet as $cname => $cval ) { |
|
| 194 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 193 | + foreach (self::$cookiesToSet as $cname => $cval) { |
|
| 194 | + $cookies[] = trim("$cname=$cval"); |
|
| 195 | 195 | } |
| 196 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 196 | + $ret[] = 'Cookie: ' . implode('; ', $cookies); |
|
| 197 | 197 | } |
| 198 | 198 | return $ret; |
| 199 | 199 | } |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | * @param array $headers |
| 203 | 203 | * @return string |
| 204 | 204 | */ |
| 205 | - protected function buildHeadersString( array $headers ) : string { |
|
| 205 | + protected function buildHeadersString(array $headers) : string { |
|
| 206 | 206 | $ret = ''; |
| 207 | - foreach ( $headers as $header ) { |
|
| 207 | + foreach ($headers as $header) { |
|
| 208 | 208 | $ret .= "$header\r\n"; |
| 209 | 209 | } |
| 210 | 210 | return $ret; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -11,32 +11,32 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @inheritDoc |
| 13 | 13 | */ |
| 14 | - protected function reallyMakeRequest( string $params ) : string { |
|
| 14 | + protected function reallyMakeRequest(string $params) : string { |
|
| 15 | 15 | $curl = curl_init(); |
| 16 | - curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); |
|
| 17 | - curl_setopt( $curl, CURLOPT_HEADER, true ); |
|
| 18 | - curl_setopt( $curl, CURLOPT_HEADERFUNCTION, [ $this, 'headersHandler' ] ); |
|
| 19 | - curl_setopt( $curl, CURLOPT_HTTPHEADER, $this->getHeaders() ); |
|
| 16 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 17 | + curl_setopt($curl, CURLOPT_HEADER, true); |
|
| 18 | + curl_setopt($curl, CURLOPT_HEADERFUNCTION, [$this, 'headersHandler']); |
|
| 19 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $this->getHeaders()); |
|
| 20 | 20 | |
| 21 | 21 | $url = self::$url; |
| 22 | - if ( $this->method === 'POST' ) { |
|
| 23 | - curl_setopt( $curl, CURLOPT_URL, $url ); |
|
| 24 | - curl_setopt( $curl, CURLOPT_POST, true ); |
|
| 25 | - curl_setopt( $curl, CURLOPT_POSTFIELDS, $params ); |
|
| 22 | + if ($this->method === 'POST') { |
|
| 23 | + curl_setopt($curl, CURLOPT_URL, $url); |
|
| 24 | + curl_setopt($curl, CURLOPT_POST, true); |
|
| 25 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $params); |
|
| 26 | 26 | } else { |
| 27 | - curl_setopt( $curl, CURLOPT_URL, "$url?$params" ); |
|
| 27 | + curl_setopt($curl, CURLOPT_URL, "$url?$params"); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - $result = curl_exec( $curl ); |
|
| 30 | + $result = curl_exec($curl); |
|
| 31 | 31 | |
| 32 | - if ( $result === false ) { |
|
| 33 | - throw new APIRequestException( curl_error( $curl ) ); |
|
| 32 | + if ($result === false) { |
|
| 33 | + throw new APIRequestException(curl_error($curl)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // Extract response body |
| 37 | - $headerSize = curl_getinfo( $curl, CURLINFO_HEADER_SIZE ); |
|
| 38 | - $body = substr( $result, $headerSize ); |
|
| 39 | - curl_close( $curl ); |
|
| 37 | + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
|
| 38 | + $body = substr($result, $headerSize); |
|
| 39 | + curl_close($curl); |
|
| 40 | 40 | |
| 41 | 41 | return $body; |
| 42 | 42 | } |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | * @return int |
| 50 | 50 | * @internal Only used as CB for cURL |
| 51 | 51 | */ |
| 52 | - public function headersHandler( $ch, string $header ) : int { |
|
| 53 | - $bits = explode( ':', $header, 2 ); |
|
| 54 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
| 52 | + public function headersHandler($ch, string $header) : int { |
|
| 53 | + $bits = explode(':', $header, 2); |
|
| 54 | + if (trim($bits[0]) === 'Set-Cookie') { |
|
| 55 | 55 | $this->newCookies[] = $bits[1]; |
| 56 | 56 | } |
| 57 | 57 | // @phan-suppress-next-line PhanTypeMismatchReturn WTF? Why does phan thinks this is a string? |
| 58 | - return strlen( $header ); |
|
| 58 | + return strlen($header); |
|
| 59 | 59 | } |
| 60 | 60 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -9,25 +9,25 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @inheritDoc |
| 11 | 11 | */ |
| 12 | - protected function reallyMakeRequest( string $params ) : string { |
|
| 12 | + protected function reallyMakeRequest(string $params) : string { |
|
| 13 | 13 | $context = [ |
| 14 | 14 | 'http' => [ |
| 15 | 15 | 'method' => $this->method, |
| 16 | - 'header' => $this->buildHeadersString( $this->getHeaders() ) |
|
| 16 | + 'header' => $this->buildHeadersString($this->getHeaders()) |
|
| 17 | 17 | ] |
| 18 | 18 | ]; |
| 19 | 19 | $url = self::$url; |
| 20 | - if ( $this->method === 'POST' ) { |
|
| 20 | + if ($this->method === 'POST') { |
|
| 21 | 21 | $context['http']['content'] = $params; |
| 22 | 22 | } else { |
| 23 | 23 | $url = "$url?$params"; |
| 24 | 24 | } |
| 25 | - $context = stream_context_create( $context ); |
|
| 26 | - $body = file_get_contents( $url, false, $context ); |
|
| 25 | + $context = stream_context_create($context); |
|
| 26 | + $body = file_get_contents($url, false, $context); |
|
| 27 | 27 | |
| 28 | - foreach ( $http_response_header as $header ) { |
|
| 29 | - $bits = explode( ':', $header, 2 ); |
|
| 30 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
| 28 | + foreach ($http_response_header as $header) { |
|
| 29 | + $bits = explode(':', $header, 2); |
|
| 30 | + if (trim($bits[0]) === 'Set-Cookie') { |
|
| 31 | 31 | $this->newCookies[] = $bits[1]; |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |