@@ -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,9 +16,9 @@ discard block |
||
| 16 | 16 | private $controller; |
| 17 | 17 | |
| 18 | 18 | public function __construct() { |
| 19 | - $this->setLogger( new Logger ); |
|
| 20 | - $this->setConfig( Config::getInstance() ); |
|
| 21 | - $this->setController( new WikiController ); |
|
| 19 | + $this->setLogger(new Logger); |
|
| 20 | + $this->setConfig(Config::getInstance()); |
|
| 21 | + $this->setController(new WikiController); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @inheritDoc |
| 33 | 33 | */ |
| 34 | - public function setLogger( LoggerInterface $logger ) { |
|
| 34 | + public function setLogger(LoggerInterface $logger) { |
|
| 35 | 35 | $this->logger = $logger; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | /** |
| 46 | 46 | * @param Config $cfg |
| 47 | 47 | */ |
| 48 | - protected function setConfig( Config $cfg ) { |
|
| 48 | + protected function setConfig(Config $cfg) { |
|
| 49 | 49 | $this->config = $cfg; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | /** |
| 60 | 60 | * @param WikiController $controller |
| 61 | 61 | */ |
| 62 | - protected function setController( WikiController $controller ) { |
|
| 62 | + protected function setController(WikiController $controller) { |
|
| 63 | 63 | $this->controller = $controller; |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -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 | |
@@ -13,20 +13,20 @@ discard block |
||
| 13 | 13 | * @return array[] |
| 14 | 14 | */ |
| 15 | 15 | public function getUsersToProcess() : array { |
| 16 | - if ( $this->users === null ) { |
|
| 17 | - $this->getLogger()->debug( 'Retrieving users list' ); |
|
| 18 | - $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
|
| 19 | - $listUsers = json_decode( $content, true ); |
|
| 16 | + if ($this->users === null) { |
|
| 17 | + $this->getLogger()->debug('Retrieving users list'); |
|
| 18 | + $content = $this->getController()->getPageContent($this->getConfig()->get('list-title')); |
|
| 19 | + $listUsers = json_decode($content, true); |
|
| 20 | 20 | |
| 21 | 21 | $this->users = []; |
| 22 | - foreach ( $listUsers as $user => $groups ) { |
|
| 23 | - $timestamp = $this->getValidTimestamp( $groups ); |
|
| 22 | + foreach ($listUsers as $user => $groups) { |
|
| 23 | + $timestamp = $this->getValidTimestamp($groups); |
|
| 24 | 24 | |
| 25 | - if ( date( 'd/m', $timestamp ) === date( 'd/m' ) && |
|
| 25 | + if (date('d/m', $timestamp) === date('d/m') && |
|
| 26 | 26 | // Don't trigger if the date is actually today |
| 27 | - date( 'd/m/Y', $timestamp ) !== date( 'd/m/Y' ) |
|
| 27 | + date('d/m/Y', $timestamp) !== date('d/m/Y') |
|
| 28 | 28 | ) { |
| 29 | - $this->users[ $user ] = $groups; |
|
| 29 | + $this->users[$user] = $groups; |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -40,17 +40,15 @@ discard block |
||
| 40 | 40 | * @param array $groups |
| 41 | 41 | * @return int |
| 42 | 42 | */ |
| 43 | - private function getValidTimestamp( array $groups ) : int { |
|
| 44 | - $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 45 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 46 | - 0; |
|
| 47 | - $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 48 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 49 | - 0; |
|
| 43 | + private function getValidTimestamp(array $groups) : int { |
|
| 44 | + $checkuser = isset($groups['checkuser']) ? |
|
| 45 | + \DateTime::createFromFormat('d/m/Y', $groups['checkuser'])->getTimestamp() : 0; |
|
| 46 | + $bureaucrat = isset($groups['bureaucrat']) ? |
|
| 47 | + \DateTime::createFromFormat('d/m/Y', $groups['bureaucrat'])->getTimestamp() : 0; |
|
| 50 | 48 | |
| 51 | - $timestamp = max( $bureaucrat, $checkuser ); |
|
| 52 | - if ( $timestamp === 0 ) { |
|
| 53 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 49 | + $timestamp = max($bureaucrat, $checkuser); |
|
| 50 | + if ($timestamp === 0) { |
|
| 51 | + $timestamp = \DateTime::createFromFormat('d/m/Y', $groups['sysop'])->getTimestamp(); |
|
| 54 | 52 | } |
| 55 | 53 | return $timestamp; |
| 56 | 54 | } |
@@ -58,8 +56,8 @@ discard block |
||
| 58 | 56 | /** |
| 59 | 57 | * @param string $name |
| 60 | 58 | */ |
| 61 | - public function removeUser( string $name ) { |
|
| 62 | - unset( $this->users[ $name ] ); |
|
| 59 | + public function removeUser(string $name) { |
|
| 60 | + unset($this->users[$name]); |
|
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | /** |
@@ -72,7 +70,7 @@ discard block |
||
| 72 | 70 | /** |
| 73 | 71 | * @param string $title |
| 74 | 72 | */ |
| 75 | - public function addCreatedPages( string $title ) { |
|
| 73 | + public function addCreatedPages(string $title) { |
|
| 76 | 74 | $this->createdPages[] = $title; |
| 77 | 75 | } |
| 78 | 76 | } |
@@ -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 | |
@@ -6,9 +6,9 @@ discard block |
||
| 6 | 6 | /** |
| 7 | 7 | * @param string|null $title |
| 8 | 8 | */ |
| 9 | - public function __construct( string $title = null ) { |
|
| 10 | - if ( $title ) { |
|
| 11 | - parent::__construct( "The specified page doesn't exist: $title" ); |
|
| 9 | + public function __construct(string $title = null) { |
|
| 10 | + if ($title) { |
|
| 11 | + parent::__construct("The specified page doesn't exist: $title"); |
|
| 12 | 12 | } else { |
| 13 | 13 | parent::__construct(); |
| 14 | 14 | } |
@@ -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 | |
@@ -6,9 +6,9 @@ discard block |
||
| 6 | 6 | /** |
| 7 | 7 | * @param string|null $title |
| 8 | 8 | */ |
| 9 | - public function __construct( string $title = null ) { |
|
| 10 | - if ( $title ) { |
|
| 11 | - parent::__construct( "The specified page is protected: $title" ); |
|
| 9 | + public function __construct(string $title = null) { |
|
| 10 | + if ($title) { |
|
| 11 | + parent::__construct("The specified page is protected: $title"); |
|
| 12 | 12 | } else { |
| 13 | 13 | parent::__construct(); |
| 14 | 14 | } |
@@ -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 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | /** |
| 9 | 9 | * @inheritDoc |
| 10 | 10 | */ |
| 11 | - public function log( $level, $message, array $context = [] ) { |
|
| 12 | - error_log( "$level - $message" ); |
|
| 11 | + public function log($level, $message, array $context = []) { |
|
| 12 | + error_log("$level - $message"); |
|
| 13 | 13 | } |
| 14 | 14 | } |
@@ -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 | |
@@ -9,39 +9,39 @@ discard block |
||
| 9 | 9 | * @inheritDoc |
| 10 | 10 | */ |
| 11 | 11 | public function run() : TaskResult { |
| 12 | - $this->getLogger()->info( 'Starting task UserNotice' ); |
|
| 12 | + $this->getLogger()->info('Starting task UserNotice'); |
|
| 13 | 13 | |
| 14 | 14 | $ricNums = []; |
| 15 | - foreach ( $this->getDataProvider()->getCreatedPages() as $page ) { |
|
| 16 | - $bits = explode( '/', $page ); |
|
| 17 | - $num = intval( array_pop( $bits ) ); |
|
| 18 | - $ricNums[ array_pop( $bits ) ] = $num; |
|
| 15 | + foreach ($this->getDataProvider()->getCreatedPages() as $page) { |
|
| 16 | + $bits = explode('/', $page); |
|
| 17 | + $num = intval(array_pop($bits)); |
|
| 18 | + $ricNums[array_pop($bits)] = $num; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - foreach ( $this->getDataProvider()->getUsersToProcess() as $user => $_ ) { |
|
| 22 | - $this->addMsg( $user, $ricNums[ $user ] ); |
|
| 21 | + foreach ($this->getDataProvider()->getUsersToProcess() as $user => $_) { |
|
| 22 | + $this->addMsg($user, $ricNums[$user]); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - $this->getLogger()->info( 'Task UserNotice completed successfully' ); |
|
| 26 | - return new TaskResult( self::STATUS_OK ); |
|
| 25 | + $this->getLogger()->info('Task UserNotice completed successfully'); |
|
| 26 | + return new TaskResult(self::STATUS_OK); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @param string $user |
| 31 | 31 | * @param int $ricNum |
| 32 | 32 | */ |
| 33 | - protected function addMsg( string $user, int $ricNum ) { |
|
| 34 | - $this->getLogger()->info( "Leaving msg to $user" ); |
|
| 35 | - $msg = str_replace( '$num', "$ricNum", $this->getConfig()->get( 'user-notice-msg' ) ); |
|
| 33 | + protected function addMsg(string $user, int $ricNum) { |
|
| 34 | + $this->getLogger()->info("Leaving msg to $user"); |
|
| 35 | + $msg = str_replace('$num', "$ricNum", $this->getConfig()->get('user-notice-msg')); |
|
| 36 | 36 | |
| 37 | 37 | $params = [ |
| 38 | 38 | 'title' => "User talk:$user", |
| 39 | 39 | 'section' => 'new', |
| 40 | 40 | 'text' => $msg, |
| 41 | - 'sectiontitle' => $this->getConfig()->get( 'user-notice-title' ), |
|
| 42 | - 'summary' => $this->getConfig()->get( 'user-notice-summary' ) |
|
| 41 | + 'sectiontitle' => $this->getConfig()->get('user-notice-title'), |
|
| 42 | + 'summary' => $this->getConfig()->get('user-notice-summary') |
|
| 43 | 43 | ]; |
| 44 | 44 | |
| 45 | - $this->getController()->editPage( $params ); |
|
| 45 | + $this->getController()->editPage($params); |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -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 | |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @param TaskDataProvider $dataProvider |
| 20 | 20 | */ |
| 21 | - public function __construct( TaskDataProvider $dataProvider ) { |
|
| 22 | - set_exception_handler( [ $this, 'handleException' ] ); |
|
| 23 | - set_error_handler( [ $this, 'handleError' ] ); |
|
| 21 | + public function __construct(TaskDataProvider $dataProvider) { |
|
| 22 | + set_exception_handler([$this, 'handleException']); |
|
| 23 | + set_error_handler([$this, 'handleError']); |
|
| 24 | 24 | parent::__construct(); |
| 25 | 25 | $this->dataProvider = $dataProvider; |
| 26 | 26 | } |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param \Throwable $ex |
| 44 | 44 | * @protected |
| 45 | 45 | */ |
| 46 | - public function handleException( \Throwable $ex ) { |
|
| 46 | + public function handleException(\Throwable $ex) { |
|
| 47 | 47 | $this->getLogger()->error( |
| 48 | - get_class( $ex ) . ': ' . |
|
| 48 | + get_class($ex) . ': ' . |
|
| 49 | 49 | $ex->getMessage() . "\nTrace:\n" . |
| 50 | 50 | $ex->getTraceAsString() |
| 51 | 51 | ); |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * @param int $errline |
| 61 | 61 | * @protected |
| 62 | 62 | */ |
| 63 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
| 64 | - throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
|
| 63 | + public function handleError($errno, $errstr, $errfile, $errline) { |
|
| 64 | + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -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 | } |