@@ -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 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -11,35 +11,35 @@ 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 | - if ( $curl === false ) { |
|
| 17 | - throw new APIRequestException( 'Cannot open cURL handler.' ); |
|
| 16 | + if ($curl === false) { |
|
| 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 | - 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 ); |
|
| 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); |
|
| 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 | - if ( $result === false ) { |
|
| 36 | - throw new APIRequestException( curl_error( $curl ) ); |
|
| 35 | + if ($result === false) { |
|
| 36 | + throw new APIRequestException(curl_error($curl)); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Extract response body |
| 40 | - $headerSize = curl_getinfo( $curl, CURLINFO_HEADER_SIZE ); |
|
| 41 | - $body = substr( $result, $headerSize ); |
|
| 42 | - curl_close( $curl ); |
|
| 40 | + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
|
| 41 | + $body = substr($result, $headerSize); |
|
| 42 | + curl_close($curl); |
|
| 43 | 43 | |
| 44 | 44 | return $body; |
| 45 | 45 | } |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * @return int |
| 53 | 53 | * @internal Only used as CB for cURL |
| 54 | 54 | */ |
| 55 | - public function headersHandler( $ch, string $header ) : int { |
|
| 56 | - $bits = explode( ':', $header, 2 ); |
|
| 57 | - if ( trim( $bits[0] ) === 'Set-Cookie' ) { |
|
| 55 | + public function headersHandler($ch, string $header) : int { |
|
| 56 | + $bits = explode(':', $header, 2); |
|
| 57 | + if (trim($bits[0]) === 'Set-Cookie') { |
|
| 58 | 58 | $this->newCookies[] = $bits[1]; |
| 59 | 59 | } |
| 60 | 60 | // @phan-suppress-next-line PhanTypeMismatchReturn WTF? Why does phan thinks this is a string? |
| 61 | - return strlen( $header ); |
|
| 61 | + return strlen($header); |
|
| 62 | 62 | } |
| 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 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * Should only be used for debugging purpose. |
| 31 | 31 | */ |
| 32 | 32 | public static function resetLastRunDate() { |
| 33 | - file_put_contents( self::LOG_FILE, '' ); |
|
| 33 | + file_put_contents(self::LOG_FILE, ''); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | * @param string|null $taskName Only used in MODE_SINGLE |
| 39 | 39 | * @return TaskResult |
| 40 | 40 | */ |
| 41 | - public function run( int $mode, string $taskName = null ) : TaskResult { |
|
| 41 | + public function run(int $mode, string $taskName = null) : TaskResult { |
|
| 42 | 42 | $this->provider = new TaskDataProvider; |
| 43 | - if ( $mode === self::MODE_COMPLETE ) { |
|
| 43 | + if ($mode === self::MODE_COMPLETE) { |
|
| 44 | 44 | return $this->runAllTasks(); |
| 45 | - } elseif ( $taskName === null ) { |
|
| 46 | - throw new BadMethodCallException( 'A task name must be specified in MODE_SINGLE' ); |
|
| 45 | + } elseif ($taskName === null) { |
|
| 46 | + throw new BadMethodCallException('A task name must be specified in MODE_SINGLE'); |
|
| 47 | 47 | } else { |
| 48 | - return $this->runTask( $taskName ); |
|
| 48 | + return $this->runTask($taskName); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | * @return TaskResult |
| 54 | 54 | */ |
| 55 | 55 | protected function runAllTasks() : TaskResult { |
| 56 | - if ( self::getLastFullRunDate() === date( 'd/m/Y' ) ) { |
|
| 56 | + if (self::getLastFullRunDate() === date('d/m/Y')) { |
|
| 57 | 57 | // Really avoid executing twice the same day |
| 58 | - return new TaskResult( TaskResult::STATUS_ERROR, [ 'A full run was already executed today.' ] ); |
|
| 58 | + return new TaskResult(TaskResult::STATUS_ERROR, ['A full run was already executed today.']); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Order matters here |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | 'user-notice' |
| 67 | 67 | ]; |
| 68 | 68 | |
| 69 | - $res = new TaskResult( TaskResult::STATUS_OK ); |
|
| 69 | + $res = new TaskResult(TaskResult::STATUS_OK); |
|
| 70 | 70 | do { |
| 71 | - $res->merge( $this->runTask( current( $list ) ) ); |
|
| 72 | - } while ( $res->isOK() && next( $list ) ); |
|
| 71 | + $res->merge($this->runTask(current($list))); |
|
| 72 | + } while ($res->isOK() && next($list)); |
|
| 73 | 73 | |
| 74 | - if ( $res->isOK() ) { |
|
| 74 | + if ($res->isOK()) { |
|
| 75 | 75 | self::setLastFullRunDate(); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @return string|null d/m/Y or null if no last run registered |
| 83 | 83 | */ |
| 84 | 84 | public static function getLastFullRunDate() : ?string { |
| 85 | - if ( file_exists( self::LOG_FILE ) ) { |
|
| 86 | - return file_get_contents( self::LOG_FILE ) ?: null; |
|
| 85 | + if (file_exists(self::LOG_FILE)) { |
|
| 86 | + return file_get_contents(self::LOG_FILE) ?: null; |
|
| 87 | 87 | } else { |
| 88 | 88 | return null; |
| 89 | 89 | } |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | * @param string $task Defined in self::TASKS_MAP |
| 94 | 94 | * @return TaskResult |
| 95 | 95 | */ |
| 96 | - protected function runTask( string $task ) : TaskResult { |
|
| 97 | - if ( !isset( self::TASKS_MAP[ $task ] ) ) { |
|
| 98 | - throw new \InvalidArgumentException( "'$task' is not a valid task." ); |
|
| 96 | + protected function runTask(string $task) : TaskResult { |
|
| 97 | + if (!isset(self::TASKS_MAP[$task])) { |
|
| 98 | + throw new \InvalidArgumentException("'$task' is not a valid task."); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $class = self::TASKS_MAP[ $task ]; |
|
| 102 | - return $this->getTaskInstance( $class )->run(); |
|
| 101 | + $class = self::TASKS_MAP[$task]; |
|
| 102 | + return $this->getTaskInstance($class)->run(); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @param string $class |
| 109 | 109 | * @return Task |
| 110 | 110 | */ |
| 111 | - private function getTaskInstance( string $class ) : Task { |
|
| 112 | - return new $class( $this->provider ); |
|
| 111 | + private function getTaskInstance(string $class) : Task { |
|
| 112 | + return new $class($this->provider); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | public static function setLastFullRunDate() { |
| 116 | - file_put_contents( self::LOG_FILE, date( 'd/m/Y' ) ); |
|
| 116 | + file_put_contents(self::LOG_FILE, date('d/m/Y')); |
|
| 117 | 117 | } |
| 118 | 118 | } |
@@ -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 | |
@@ -18,20 +18,20 @@ discard block |
||
| 18 | 18 | * @return array[] |
| 19 | 19 | */ |
| 20 | 20 | public function getUsersToProcess() : array { |
| 21 | - if ( $this->users === null ) { |
|
| 22 | - $this->getLogger()->debug( 'Retrieving users list' ); |
|
| 23 | - $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
|
| 24 | - $listUsers = json_decode( $content, true ); |
|
| 21 | + if ($this->users === null) { |
|
| 22 | + $this->getLogger()->debug('Retrieving users list'); |
|
| 23 | + $content = $this->getController()->getPageContent($this->getConfig()->get('list-title')); |
|
| 24 | + $listUsers = json_decode($content, true); |
|
| 25 | 25 | |
| 26 | 26 | $this->users = []; |
| 27 | - foreach ( $listUsers as $user => $groups ) { |
|
| 28 | - $timestamp = $this->getValidTimestamp( $groups ); |
|
| 27 | + foreach ($listUsers as $user => $groups) { |
|
| 28 | + $timestamp = $this->getValidTimestamp($groups); |
|
| 29 | 29 | |
| 30 | - if ( date( 'd/m', $timestamp ) === date( 'd/m' ) && |
|
| 30 | + if (date('d/m', $timestamp) === date('d/m') && |
|
| 31 | 31 | // Don't trigger if the date is actually today |
| 32 | - date( 'd/m/Y', $timestamp ) !== date( 'd/m/Y' ) |
|
| 32 | + date('d/m/Y', $timestamp) !== date('d/m/Y') |
|
| 33 | 33 | ) { |
| 34 | - $this->users[ $user ] = $groups; |
|
| 34 | + $this->users[$user] = $groups; |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -45,17 +45,15 @@ discard block |
||
| 45 | 45 | * @param array $groups |
| 46 | 46 | * @return int |
| 47 | 47 | */ |
| 48 | - private function getValidTimestamp( array $groups ) : int { |
|
| 49 | - $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 50 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 51 | - 0; |
|
| 52 | - $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 53 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 54 | - 0; |
|
| 48 | + private function getValidTimestamp(array $groups) : int { |
|
| 49 | + $checkuser = isset($groups['checkuser']) ? |
|
| 50 | + \DateTime::createFromFormat('d/m/Y', $groups['checkuser'])->getTimestamp() : 0; |
|
| 51 | + $bureaucrat = isset($groups['bureaucrat']) ? |
|
| 52 | + \DateTime::createFromFormat('d/m/Y', $groups['bureaucrat'])->getTimestamp() : 0; |
|
| 55 | 53 | |
| 56 | - $timestamp = max( $bureaucrat, $checkuser ); |
|
| 57 | - if ( $timestamp === 0 ) { |
|
| 58 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 54 | + $timestamp = max($bureaucrat, $checkuser); |
|
| 55 | + if ($timestamp === 0) { |
|
| 56 | + $timestamp = \DateTime::createFromFormat('d/m/Y', $groups['sysop'])->getTimestamp(); |
|
| 59 | 57 | } |
| 60 | 58 | return $timestamp; |
| 61 | 59 | } |
@@ -65,8 +63,8 @@ discard block |
||
| 65 | 63 | * |
| 66 | 64 | * @param string $name |
| 67 | 65 | */ |
| 68 | - public function removeUser( string $name ) { |
|
| 69 | - unset( $this->users[ $name ] ); |
|
| 66 | + public function removeUser(string $name) { |
|
| 67 | + unset($this->users[$name]); |
|
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | /** |
@@ -79,7 +77,7 @@ discard block |
||
| 79 | 77 | /** |
| 80 | 78 | * @param string $title |
| 81 | 79 | */ |
| 82 | - public function addCreatedPages( string $title ) { |
|
| 80 | + public function addCreatedPages(string $title) { |
|
| 83 | 81 | $this->createdPages[] = $title; |
| 84 | 82 | } |
| 85 | 83 | } |
@@ -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 | |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @param array $params |
| 38 | 38 | * @param bool $isPOST |
| 39 | 39 | */ |
| 40 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 41 | - $this->params = [ 'format' => 'json' ] + $params; |
|
| 40 | + protected function __construct(array $params, bool $isPOST = false) { |
|
| 41 | + $this->params = ['format' => 'json'] + $params; |
|
| 42 | 42 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | * @param bool $isPOST |
| 50 | 50 | * @return self |
| 51 | 51 | */ |
| 52 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 53 | - if ( extension_loaded( 'curl' ) ) { |
|
| 54 | - $ret = new CurlRequest( $params, $isPOST ); |
|
| 52 | + public static function newFromParams(array $params, bool $isPOST = false) : self { |
|
| 53 | + if (extension_loaded('curl')) { |
|
| 54 | + $ret = new CurlRequest($params, $isPOST); |
|
| 55 | 55 | } else { |
| 56 | - $ret = new NativeRequest( $params, $isPOST ); |
|
| 56 | + $ret = new NativeRequest($params, $isPOST); |
|
| 57 | 57 | } |
| 58 | 58 | return $ret; |
| 59 | 59 | } |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | $curParams = $this->params; |
| 68 | 68 | $sets = []; |
| 69 | 69 | do { |
| 70 | - $res = $this->makeRequestInternal( $curParams ); |
|
| 70 | + $res = $this->makeRequestInternal($curParams); |
|
| 71 | 71 | |
| 72 | - $this->handleErrorAndWarnings( $res ); |
|
| 72 | + $this->handleErrorAndWarnings($res); |
|
| 73 | 73 | $sets[] = $res; |
| 74 | 74 | |
| 75 | 75 | $finished = true; |
| 76 | - if ( isset( $res->continue ) ) { |
|
| 77 | - $curParams = array_merge( $curParams, get_object_vars( $res->continue ) ); |
|
| 76 | + if (isset($res->continue)) { |
|
| 77 | + $curParams = array_merge($curParams, get_object_vars($res->continue)); |
|
| 78 | 78 | $finished = false; |
| 79 | 79 | } |
| 80 | - } while ( !$finished ); |
|
| 80 | + } while (!$finished); |
|
| 81 | 81 | |
| 82 | - return $this->mergeSets( $sets ); |
|
| 82 | + return $this->mergeSets($sets); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | * @param array $params |
| 89 | 89 | * @return \stdClass |
| 90 | 90 | */ |
| 91 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 92 | - if ( $this->method === 'POST' ) { |
|
| 91 | + private function makeRequestInternal(array $params) : \stdClass { |
|
| 92 | + if ($this->method === 'POST') { |
|
| 93 | 93 | $params['maxlag'] = self::MAXLAG; |
| 94 | 94 | } |
| 95 | - $params = http_build_query( $params ); |
|
| 95 | + $params = http_build_query($params); |
|
| 96 | 96 | |
| 97 | - $body = $this->reallyMakeRequest( $params ); |
|
| 97 | + $body = $this->reallyMakeRequest($params); |
|
| 98 | 98 | |
| 99 | - $this->setCookies( $this->newCookies ); |
|
| 100 | - return json_decode( $body ); |
|
| 99 | + $this->setCookies($this->newCookies); |
|
| 100 | + return json_decode($body); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,18 +106,18 @@ discard block |
||
| 106 | 106 | * @param string $params |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 109 | + abstract protected function reallyMakeRequest(string $params) : string; |
|
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * After a request, set cookies for the next ones |
| 113 | 113 | * |
| 114 | 114 | * @param array $cookies |
| 115 | 115 | */ |
| 116 | - protected function setCookies( array $cookies ) { |
|
| 117 | - foreach ( $cookies as $cookie ) { |
|
| 118 | - $bits = explode( ';', $cookie ); |
|
| 119 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 120 | - self::$cookiesToSet[ $name ] = $value; |
|
| 116 | + protected function setCookies(array $cookies) { |
|
| 117 | + foreach ($cookies as $cookie) { |
|
| 118 | + $bits = explode(';', $cookie); |
|
| 119 | + list($name, $value) = explode('=', $bits[0]); |
|
| 120 | + self::$cookiesToSet[$name] = $value; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @param \stdClass $res |
| 128 | 128 | * @throws APIRequestException |
| 129 | 129 | */ |
| 130 | - protected function handleErrorAndWarnings( $res ) { |
|
| 131 | - if ( isset( $res->error ) ) { |
|
| 132 | - switch ( $res->error->code ) { |
|
| 130 | + protected function handleErrorAndWarnings($res) { |
|
| 131 | + if (isset($res->error)) { |
|
| 132 | + switch ($res->error->code) { |
|
| 133 | 133 | case 'missingtitle': |
| 134 | 134 | $ex = new MissingPageException; |
| 135 | 135 | break; |
@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | $ex = new ProtectedPageException; |
| 138 | 138 | break; |
| 139 | 139 | default: |
| 140 | - $ex = new APIRequestException( $res->error->code . ' - ' . $res->error->info ); |
|
| 140 | + $ex = new APIRequestException($res->error->code . ' - ' . $res->error->info); |
|
| 141 | 141 | } |
| 142 | 142 | throw $ex; |
| 143 | - } elseif ( isset( $res->warnings ) ) { |
|
| 144 | - $act = $this->params[ 'action' ]; |
|
| 143 | + } elseif (isset($res->warnings)) { |
|
| 144 | + $act = $this->params['action']; |
|
| 145 | 145 | $warning = $res->warnings->$act; |
| 146 | - throw new APIRequestException( reset( $warning ) ); |
|
| 146 | + throw new APIRequestException(reset($warning)); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -153,16 +153,16 @@ discard block |
||
| 153 | 153 | * @param \stdClass[] $sets |
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | - private function mergeSets( array $sets ) : array { |
|
| 157 | - $sets = $this->objectToArray( $sets ); |
|
| 156 | + private function mergeSets(array $sets) : array { |
|
| 157 | + $sets = $this->objectToArray($sets); |
|
| 158 | 158 | // Use the first set as template |
| 159 | - $ret = array_shift( $sets ); |
|
| 159 | + $ret = array_shift($sets); |
|
| 160 | 160 | $act = $this->params['action']; |
| 161 | 161 | |
| 162 | - foreach ( $sets as $set ) { |
|
| 162 | + foreach ($sets as $set) { |
|
| 163 | 163 | $ret[$act] = array_merge_recursive( |
| 164 | - $this->objectToArray( $ret[$act] ), |
|
| 165 | - $this->objectToArray( $set[$act] ) |
|
| 164 | + $this->objectToArray($ret[$act]), |
|
| 165 | + $this->objectToArray($set[$act]) |
|
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | return $ret; |
@@ -175,14 +175,14 @@ discard block |
||
| 175 | 175 | * @param \stdClass|array $objOrArray |
| 176 | 176 | * @return array |
| 177 | 177 | */ |
| 178 | - private function objectToArray( $objOrArray ) : array { |
|
| 178 | + private function objectToArray($objOrArray) : array { |
|
| 179 | 179 | $array = []; |
| 180 | - if ( is_object( $objOrArray ) ) { |
|
| 181 | - $objOrArray = get_object_vars( $objOrArray ); |
|
| 180 | + if (is_object($objOrArray)) { |
|
| 181 | + $objOrArray = get_object_vars($objOrArray); |
|
| 182 | 182 | } |
| 183 | - foreach ( $objOrArray as $key => $value ) { |
|
| 184 | - if ( is_object( $value ) || is_array( $value ) ) { |
|
| 185 | - $value = $this->objectToArray( $value ); |
|
| 183 | + foreach ($objOrArray as $key => $value) { |
|
| 184 | + if (is_object($value) || is_array($value)) { |
|
| 185 | + $value = $this->objectToArray($value); |
|
| 186 | 186 | } |
| 187 | 187 | $array[$key] = $value; |
| 188 | 188 | } |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | protected function getHeaders() :array { |
| 198 | 198 | $ret = self::HEADERS; |
| 199 | - if ( self::$cookiesToSet ) { |
|
| 199 | + if (self::$cookiesToSet) { |
|
| 200 | 200 | $cookies = []; |
| 201 | - foreach ( self::$cookiesToSet as $cname => $cval ) { |
|
| 202 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 201 | + foreach (self::$cookiesToSet as $cname => $cval) { |
|
| 202 | + $cookies[] = trim("$cname=$cval"); |
|
| 203 | 203 | } |
| 204 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 204 | + $ret[] = 'Cookie: ' . implode('; ', $cookies); |
|
| 205 | 205 | } |
| 206 | 206 | return $ret; |
| 207 | 207 | } |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @param array $headers |
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | - protected function buildHeadersString( array $headers ) : string { |
|
| 215 | + protected function buildHeadersString(array $headers) : string { |
|
| 216 | 216 | $ret = ''; |
| 217 | - foreach ( $headers as $header ) { |
|
| 217 | + foreach ($headers as $header) { |
|
| 218 | 218 | $ret .= "$header\r\n"; |
| 219 | 219 | } |
| 220 | 220 | 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\Exception; |
| 4 | 4 | |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @param string|null $title If available |
| 11 | 11 | */ |
| 12 | - public function __construct( string $title = null ) { |
|
| 13 | - if ( $title ) { |
|
| 14 | - parent::__construct( "The specified page doesn't exist: $title" ); |
|
| 12 | + public function __construct(string $title = null) { |
|
| 13 | + if ($title) { |
|
| 14 | + parent::__construct("The specified page doesn't exist: $title"); |
|
| 15 | 15 | } else { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @param string|null $title If available |
| 11 | 11 | */ |
| 12 | - public function __construct( string $title = null ) { |
|
| 13 | - if ( $title ) { |
|
| 14 | - parent::__construct( "The specified page is protected: $title" ); |
|
| 12 | + public function __construct(string $title = null) { |
|
| 13 | + if ($title) { |
|
| 14 | + parent::__construct("The specified page is protected: $title"); |
|
| 15 | 15 | } else { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | * @inheritDoc |
| 14 | 14 | */ |
| 15 | 15 | public function run() : TaskResult { |
| 16 | - $this->getLogger()->info( 'Starting task UpdatesAround' ); |
|
| 16 | + $this->getLogger()->info('Starting task UpdatesAround'); |
|
| 17 | 17 | |
| 18 | - foreach ( $this->getDataProvider()->getCreatedPages() as $page ) { |
|
| 18 | + foreach ($this->getDataProvider()->getCreatedPages() as $page) { |
|
| 19 | 19 | // Wikipedia:Amministratori/Riconferma annuale |
| 20 | - $this->addToMainPage( $page ); |
|
| 20 | + $this->addToMainPage($page); |
|
| 21 | 21 | // WP:Wikipediano/Votazioni |
| 22 | - $this->addVote( $page ); |
|
| 22 | + $this->addVote($page); |
|
| 23 | 23 | // Template:VotazioniRCnews |
| 24 | - $this->addNews( $page ); |
|
| 24 | + $this->addNews($page); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - $this->getLogger()->info( 'Task UpdatesAround completed successfully' ); |
|
| 28 | - return new TaskResult( self::STATUS_OK ); |
|
| 27 | + $this->getLogger()->info('Task UpdatesAround completed successfully'); |
|
| 28 | + return new TaskResult(self::STATUS_OK); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @param string $page |
| 35 | 35 | */ |
| 36 | - protected function addToMainPage( string $page ) { |
|
| 37 | - $this->getLogger()->info( "Adding $page to main" ); |
|
| 36 | + protected function addToMainPage(string $page) { |
|
| 37 | + $this->getLogger()->info("Adding $page to main"); |
|
| 38 | 38 | |
| 39 | 39 | $params = [ |
| 40 | - 'title' => $this->getConfig()->get( 'ric-main-page' ), |
|
| 40 | + 'title' => $this->getConfig()->get('ric-main-page'), |
|
| 41 | 41 | 'appendtext' => '{{' . $page . '}}', |
| 42 | - 'summary' => $this->getConfig()->get( 'ric-main-page-summary' ) |
|
| 42 | + 'summary' => $this->getConfig()->get('ric-main-page-summary') |
|
| 43 | 43 | ]; |
| 44 | 44 | |
| 45 | - $this->getController()->editPage( $params ); |
|
| 45 | + $this->getController()->editPage($params); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -50,37 +50,37 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param string $page |
| 52 | 52 | */ |
| 53 | - protected function addVote( string $page ) { |
|
| 54 | - $this->getLogger()->info( "Adding $page to votes" ); |
|
| 55 | - $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
|
| 53 | + protected function addVote(string $page) { |
|
| 54 | + $this->getLogger()->info("Adding $page to votes"); |
|
| 55 | + $votePage = $this->getConfig()->get('ric-vote-page'); |
|
| 56 | 56 | |
| 57 | - $content = $this->getController()->getPageContent( $votePage ); |
|
| 57 | + $content = $this->getController()->getPageContent($votePage); |
|
| 58 | 58 | // Remove comments etc. |
| 59 | - $visibleContent = strip_tags( $content ); |
|
| 60 | - $user = explode( '/', $page )[2]; |
|
| 59 | + $visibleContent = strip_tags($content); |
|
| 60 | + $user = explode('/', $page)[2]; |
|
| 61 | 61 | $time = $this->getTimeWithArticle(); |
| 62 | 62 | |
| 63 | 63 | $newLine = "*[[Utente:$user|]]. La [[$page|procedura]] termina $time"; |
| 64 | 64 | |
| 65 | 65 | $introReg = '!^;È in corso la .*riconferma tacita.* degli .*amministratori.+!m'; |
| 66 | - if ( preg_match( $introReg, $visibleContent ) ) { |
|
| 67 | - $newContent = preg_replace( $introReg, '$0' . "\n$newLine;", $content, 1 ); |
|
| 66 | + if (preg_match($introReg, $visibleContent)) { |
|
| 67 | + $newContent = preg_replace($introReg, '$0' . "\n$newLine;", $content, 1); |
|
| 68 | 68 | } else { |
| 69 | 69 | $matches = []; |
| 70 | - if ( preg_match( $introReg, $content, $matches ) === false ) { |
|
| 71 | - throw new TaskException( 'Intro not found in vote page' ); |
|
| 70 | + if (preg_match($introReg, $content, $matches) === false) { |
|
| 71 | + throw new TaskException('Intro not found in vote page'); |
|
| 72 | 72 | } |
| 73 | 73 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 74 | - $newContent = preg_replace( $beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1 ); |
|
| 74 | + $newContent = preg_replace($beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $params = [ |
| 78 | 78 | 'title' => $votePage, |
| 79 | 79 | 'text' => $newContent, |
| 80 | - 'summary' => $this->getConfig()->get( 'ric-vote-page-summary' ) |
|
| 80 | + 'summary' => $this->getConfig()->get('ric-vote-page-summary') |
|
| 81 | 81 | ]; |
| 82 | 82 | |
| 83 | - $this->getController()->editPage( $params ); |
|
| 83 | + $this->getController()->editPage($params); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | 91 | private function getTimeWithArticle() : string { |
| 92 | - $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
|
| 93 | - $endTS = time() + ( 60 * 60 * 24 * 7 ); |
|
| 94 | - $endTime = strftime( '%e %B alle %R', $endTS ); |
|
| 92 | + $oldLoc = setlocale(LC_TIME, 'it_IT', 'Italian_Italy', 'Italian'); |
|
| 93 | + $endTS = time() + (60 * 60 * 24 * 7); |
|
| 94 | + $endTime = strftime('%e %B alle %R', $endTS); |
|
| 95 | 95 | // Remove the left space if day has a single digit |
| 96 | - $endTime = ltrim( $endTime ); |
|
| 97 | - $artic = in_array( date( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il "; |
|
| 98 | - setlocale( LC_TIME, $oldLoc ); |
|
| 96 | + $endTime = ltrim($endTime); |
|
| 97 | + $artic = in_array(date('j', $endTS), [8, 11]) ? "l'" : "il "; |
|
| 98 | + setlocale(LC_TIME, $oldLoc); |
|
| 99 | 99 | |
| 100 | 100 | return $artic . $endTime; |
| 101 | 101 | } |
@@ -105,27 +105,27 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @param string $page |
| 107 | 107 | */ |
| 108 | - protected function addNews( string $page ) { |
|
| 109 | - $this->getLogger()->info( "Adding $page to news" ); |
|
| 110 | - $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
|
| 108 | + protected function addNews(string $page) { |
|
| 109 | + $this->getLogger()->info("Adding $page to news"); |
|
| 110 | + $newsPage = $this->getConfig()->get('ric-news-page'); |
|
| 111 | 111 | |
| 112 | - $content = $this->getController()->getPageContent( $newsPage ); |
|
| 112 | + $content = $this->getController()->getPageContent($newsPage); |
|
| 113 | 113 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 114 | 114 | |
| 115 | 115 | $matches = []; |
| 116 | - if ( preg_match( $reg, $content, $matches ) === false ) { |
|
| 117 | - throw new TaskException( 'Param not found in news page' ); |
|
| 116 | + if (preg_match($reg, $content, $matches) === false) { |
|
| 117 | + throw new TaskException('Param not found in news page'); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $newNum = (int)$matches[2] + 1; |
| 121 | - $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
|
| 121 | + $newContent = preg_replace($reg, '${1}' . $newNum, $content); |
|
| 122 | 122 | |
| 123 | 123 | $params = [ |
| 124 | 124 | 'title' => $newsPage, |
| 125 | 125 | 'text' => $newContent, |
| 126 | - 'summary' => $this->getConfig()->get( 'ric-news-page-summary' ) |
|
| 126 | + 'summary' => $this->getConfig()->get('ric-news-page-summary') |
|
| 127 | 127 | ]; |
| 128 | 128 | |
| 129 | - $this->getController()->editPage( $params ); |
|
| 129 | + $this->getController()->editPage($params); |
|
| 130 | 130 | } |
| 131 | 131 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | * @inheritDoc |
| 20 | 20 | */ |
| 21 | 21 | public function run() : TaskResult { |
| 22 | - $this->getLogger()->info( 'Starting task UpdateList' ); |
|
| 22 | + $this->getLogger()->info('Starting task UpdateList'); |
|
| 23 | 23 | $this->actualList = $this->getActualAdmins(); |
| 24 | 24 | $this->botList = $this->getList(); |
| 25 | 25 | |
| 26 | 26 | $missing = $this->getMissingGroups(); |
| 27 | 27 | $extra = $this->getExtraGroups(); |
| 28 | 28 | |
| 29 | - if ( $missing || $extra ) { |
|
| 30 | - $this->doUpdateList( $this->getNewContent( $missing, $extra ) ); |
|
| 29 | + if ($missing || $extra) { |
|
| 30 | + $this->doUpdateList($this->getNewContent($missing, $extra)); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( $this->errors ) { |
|
| 33 | + if ($this->errors) { |
|
| 34 | 34 | // We're fine with it, but don't run other tasks |
| 35 | 35 | $msg = 'Task UpdateList completed with warnings.'; |
| 36 | 36 | $status = self::STATUS_ERROR; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | $status = self::STATUS_OK; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $this->getLogger()->info( $msg ); |
|
| 43 | - return new TaskResult( $status, $this->errors ); |
|
| 42 | + $this->getLogger()->info($msg); |
|
| 43 | + return new TaskResult($status, $this->errors); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | 49 | protected function getActualAdmins() : array { |
| 50 | - $this->getLogger()->debug( 'Retrieving admins - API' ); |
|
| 50 | + $this->getLogger()->debug('Retrieving admins - API'); |
|
| 51 | 51 | $params = [ |
| 52 | 52 | 'action' => 'query', |
| 53 | 53 | 'list' => 'allusers', |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | 'aulimit' => 'max', |
| 57 | 57 | ]; |
| 58 | 58 | |
| 59 | - $req = RequestBase::newFromParams( $params ); |
|
| 60 | - return $this->extractAdmins( $req->execute() ); |
|
| 59 | + $req = RequestBase::newFromParams($params); |
|
| 60 | + return $this->extractAdmins($req->execute()); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @param array $data |
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | - protected function extractAdmins( array $data ) : array { |
|
| 67 | + protected function extractAdmins(array $data) : array { |
|
| 68 | 68 | $ret = []; |
| 69 | - $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
|
| 70 | - foreach ( $data['query']['allusers'] as $u ) { |
|
| 71 | - if ( in_array( $u['name'], $blacklist ) ) { |
|
| 69 | + $blacklist = $this->getConfig()->get('exclude-admins'); |
|
| 70 | + foreach ($data['query']['allusers'] as $u) { |
|
| 71 | + if (in_array($u['name'], $blacklist)) { |
|
| 72 | 72 | continue; |
| 73 | 73 | } |
| 74 | - $interestingGroups = array_intersect( $u['groups'], [ 'sysop', 'bureaucrat', 'checkuser' ] ); |
|
| 75 | - $ret[ $u['name'] ] = $interestingGroups; |
|
| 74 | + $interestingGroups = array_intersect($u['groups'], ['sysop', 'bureaucrat', 'checkuser']); |
|
| 75 | + $ret[$u['name']] = $interestingGroups; |
|
| 76 | 76 | } |
| 77 | 77 | return $ret; |
| 78 | 78 | } |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | protected function getList() : array { |
| 84 | - $this->getLogger()->debug( 'Retrieving admins - JSON list' ); |
|
| 85 | - $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
|
| 84 | + $this->getLogger()->debug('Retrieving admins - JSON list'); |
|
| 85 | + $content = $this->getController()->getPageContent($this->getConfig()->get('list-title')); |
|
| 86 | 86 | |
| 87 | - return json_decode( $content, true ); |
|
| 87 | + return json_decode($content, true); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,20 +94,20 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | protected function getMissingGroups() : array { |
| 96 | 96 | $missing = []; |
| 97 | - foreach ( $this->actualList as $adm => $groups ) { |
|
| 98 | - if ( !isset( $this->botList[ $adm ] ) ) { |
|
| 97 | + foreach ($this->actualList as $adm => $groups) { |
|
| 98 | + if (!isset($this->botList[$adm])) { |
|
| 99 | 99 | $groupsList = $groups; |
| 100 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 100 | + } elseif (count($groups) > count($this->botList[$adm])) { |
|
| 101 | 101 | // Only some groups are missing |
| 102 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 102 | + $groupsList = array_diff_key($groups, $this->botList[$adm]); |
|
| 103 | 103 | } else { |
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - foreach ( $groupsList as $group ) { |
|
| 107 | + foreach ($groupsList as $group) { |
|
| 108 | 108 | try { |
| 109 | - $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
|
| 110 | - } catch ( TaskException $e ) { |
|
| 109 | + $missing[$adm][$group] = $this->getFlagDate($adm, $group); |
|
| 110 | + } catch (TaskException $e) { |
|
| 111 | 111 | $this->errors[] = $e->getMessage(); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @return string |
| 124 | 124 | * @throws TaskException |
| 125 | 125 | */ |
| 126 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 127 | - $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
|
| 126 | + protected function getFlagDate(string $admin, string $group) : string { |
|
| 127 | + $this->getLogger()->info("Retrieving $group flag date for $admin"); |
|
| 128 | 128 | |
| 129 | - if ( $group === 'checkuser' ) { |
|
| 129 | + if ($group === 'checkuser') { |
|
| 130 | 130 | // Little hack |
| 131 | 131 | $oldUrl = RequestBase::$url; |
| 132 | 132 | RequestBase::$url = 'https://meta.wikimedia.org/w/api.php'; |
@@ -142,19 +142,19 @@ discard block |
||
| 142 | 142 | 'lelimit' => 'max' |
| 143 | 143 | ]; |
| 144 | 144 | |
| 145 | - $req = RequestBase::newFromParams( $params ); |
|
| 145 | + $req = RequestBase::newFromParams($params); |
|
| 146 | 146 | $data = $req->execute(); |
| 147 | - $ts = $this->extractTimestamp( $data, $group ); |
|
| 147 | + $ts = $this->extractTimestamp($data, $group); |
|
| 148 | 148 | |
| 149 | - if ( isset( $oldUrl ) ) { |
|
| 149 | + if (isset($oldUrl)) { |
|
| 150 | 150 | RequestBase::$url = $oldUrl; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( $ts === null ) { |
|
| 154 | - throw new TaskException( "$group flag date unavailable for $admin" ); |
|
| 153 | + if ($ts === null) { |
|
| 154 | + throw new TaskException("$group flag date unavailable for $admin"); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return date( "d/m/Y", strtotime( $ts ) ); |
|
| 157 | + return date("d/m/Y", strtotime($ts)); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | * @param string $group |
| 165 | 165 | * @return string|null |
| 166 | 166 | */ |
| 167 | - private function extractTimestamp( array $data, string $group ) : ?string { |
|
| 167 | + private function extractTimestamp(array $data, string $group) : ?string { |
|
| 168 | 168 | $ts = null; |
| 169 | - foreach ( $data['query']['logevents'] as $entry ) { |
|
| 170 | - if ( !isset( $entry['params'] ) ) { |
|
| 169 | + foreach ($data['query']['logevents'] as $entry) { |
|
| 170 | + if (!isset($entry['params'])) { |
|
| 171 | 171 | // Old entries |
| 172 | 172 | continue; |
| 173 | 173 | } |
| 174 | - if ( in_array( $group, $entry['params']['newgroups'] ) && |
|
| 175 | - !in_array( $group, $entry['params']['oldgroups'] ) |
|
| 174 | + if (in_array($group, $entry['params']['newgroups']) && |
|
| 175 | + !in_array($group, $entry['params']['oldgroups']) |
|
| 176 | 176 | ) { |
| 177 | 177 | $ts = $entry['timestamp']; |
| 178 | 178 | break; |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | protected function getExtraGroups() : array { |
| 190 | 190 | $extra = []; |
| 191 | - foreach ( $this->botList as $name => $groups ) { |
|
| 192 | - if ( !isset( $this->actualList[ $name ] ) ) { |
|
| 193 | - $extra[ $name ] = $groups; |
|
| 194 | - } elseif ( count( $groups ) > count( $this->actualList[ $name ] ) ) { |
|
| 195 | - $extra[ $name ] = array_diff_key( $groups, $this->actualList[ $name ] ); |
|
| 191 | + foreach ($this->botList as $name => $groups) { |
|
| 192 | + if (!isset($this->actualList[$name])) { |
|
| 193 | + $extra[$name] = $groups; |
|
| 194 | + } elseif (count($groups) > count($this->actualList[$name])) { |
|
| 195 | + $extra[$name] = array_diff_key($groups, $this->actualList[$name]); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | return $extra; |
@@ -203,25 +203,25 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param array $newContent |
| 205 | 205 | */ |
| 206 | - protected function doUpdateList( array $newContent ) { |
|
| 207 | - ksort( $newContent ); |
|
| 206 | + protected function doUpdateList(array $newContent) { |
|
| 207 | + ksort($newContent); |
|
| 208 | 208 | |
| 209 | - if ( $newContent !== $this->botList ) { |
|
| 210 | - $this->getLogger()->info( 'Updating admin list' ); |
|
| 209 | + if ($newContent !== $this->botList) { |
|
| 210 | + $this->getLogger()->info('Updating admin list'); |
|
| 211 | 211 | } else { |
| 212 | - $this->getLogger()->info( 'Admin list already up-to-date' ); |
|
| 212 | + $this->getLogger()->info('Admin list already up-to-date'); |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $stringified = json_encode( $newContent ); |
|
| 216 | + $stringified = json_encode($newContent); |
|
| 217 | 217 | |
| 218 | 218 | $params = [ |
| 219 | - 'title' => $this->getConfig()->get( 'list-title' ), |
|
| 219 | + 'title' => $this->getConfig()->get('list-title'), |
|
| 220 | 220 | 'text' => $stringified, |
| 221 | - 'summary' => $this->getConfig()->get( 'list-update-summary' ) |
|
| 221 | + 'summary' => $this->getConfig()->get('list-update-summary') |
|
| 222 | 222 | ]; |
| 223 | 223 | |
| 224 | - $this->getController()->editPage( $params ); |
|
| 224 | + $this->getController()->editPage($params); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -231,19 +231,19 @@ discard block |
||
| 231 | 231 | * @param array[] $extra |
| 232 | 232 | * @return array[] |
| 233 | 233 | */ |
| 234 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 234 | + protected function getNewContent(array $missing, array $extra) : array { |
|
| 235 | 235 | $newContent = $this->botList; |
| 236 | - foreach ( $newContent as $user => $groups ) { |
|
| 237 | - if ( isset( $missing[ $user ] ) ) { |
|
| 238 | - $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
|
| 239 | - unset( $missing[ $user ] ); |
|
| 240 | - } elseif ( isset( $extra[ $user ] ) ) { |
|
| 241 | - $newContent[ $user ] = array_diff_key( $groups, $extra[ $user ] ); |
|
| 236 | + foreach ($newContent as $user => $groups) { |
|
| 237 | + if (isset($missing[$user])) { |
|
| 238 | + $newContent[$user] = array_merge($groups, $missing[$user]); |
|
| 239 | + unset($missing[$user]); |
|
| 240 | + } elseif (isset($extra[$user])) { |
|
| 241 | + $newContent[$user] = array_diff_key($groups, $extra[$user]); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | // Add users which don't have an entry at all |
| 245 | - $newContent = array_merge( $newContent, $missing ); |
|
| 245 | + $newContent = array_merge($newContent, $missing); |
|
| 246 | 246 | // And remove empty users |
| 247 | - return array_filter( $newContent ); |
|
| 247 | + return array_filter($newContent); |
|
| 248 | 248 | } |
| 249 | 249 | } |