@@ -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,7 +13,7 @@ discard block |
||
| 13 | 13 | /** @var self */ |
| 14 | 14 | private static $instance; |
| 15 | 15 | /** @var array */ |
| 16 | - private $opts = []; |
|
| 16 | + private $opts = [ ]; |
|
| 17 | 17 | /** @var Wiki */ |
| 18 | 18 | private $wiki; |
| 19 | 19 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param Wiki $wiki |
| 24 | 24 | */ |
| 25 | - private function __construct( Wiki $wiki ) { |
|
| 25 | + private function __construct ( Wiki $wiki ) { |
|
| 26 | 26 | $this->wiki = $wiki; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param Wiki $wiki |
| 34 | 34 | * @throws ConfigException |
| 35 | 35 | */ |
| 36 | - public static function init( string $configTitle, Wiki $wiki ) : void { |
|
| 36 | + public static function init ( string $configTitle, Wiki $wiki ) : void { |
|
| 37 | 37 | if ( self::$instance ) { |
| 38 | 38 | throw new ConfigException( 'Config was already initialized' ); |
| 39 | 39 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param string $key |
| 60 | 60 | * @param mixed $value |
| 61 | 61 | */ |
| 62 | - protected function set( string $key, $value ) : void { |
|
| 62 | + protected function set ( string $key, $value ) : void { |
|
| 63 | 63 | $this->opts[ $key ] = $value; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return self |
| 70 | 70 | * @throws ConfigException |
| 71 | 71 | */ |
| 72 | - public static function getInstance() : self { |
|
| 72 | + public static function getInstance () : self { |
|
| 73 | 73 | if ( !self::$instance ) { |
| 74 | 74 | throw new ConfigException( 'Config not yet initialized' ); |
| 75 | 75 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return mixed |
| 84 | 84 | * @throws ConfigException |
| 85 | 85 | */ |
| 86 | - public function get( string $opt ) { |
|
| 86 | + public function get ( string $opt ) { |
|
| 87 | 87 | if ( !isset( $this->opts[ $opt ] ) ) { |
| 88 | 88 | throw new ConfigException( "Config option '$opt' not set." ); |
| 89 | 89 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Wiki\Page; |
| 4 | 4 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @private Use self::get() |
| 19 | 19 | * @param Wiki $wiki |
| 20 | 20 | */ |
| 21 | - public function __construct( Wiki $wiki ) { |
|
| 21 | + public function __construct ( Wiki $wiki ) { |
|
| 22 | 22 | // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix |
| 23 | 23 | global $globalListTitle; |
| 24 | 24 | parent::__construct( $globalListTitle, $wiki ); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param Wiki $wiki |
| 31 | 31 | * @return self |
| 32 | 32 | */ |
| 33 | - public static function get( Wiki $wiki ) : self { |
|
| 33 | + public static function get ( Wiki $wiki ) : self { |
|
| 34 | 34 | static $instance = null; |
| 35 | 35 | if ( $instance === null ) { |
| 36 | 36 | $instance = new self( $wiki ); |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | * @param string[] $groups |
| 43 | 43 | * @return int|null |
| 44 | 44 | */ |
| 45 | - public static function getOverrideTimestamp( array $groups ) : ?int { |
|
| 45 | + public static function getOverrideTimestamp ( array $groups ) : ?int { |
|
| 46 | 46 | if ( !array_intersect_key( $groups, [ 'override-perm' => true, 'override' => true ] ) ) { |
| 47 | 47 | return null; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // A one-time override takes precedence |
| 51 | 51 | if ( array_key_exists( 'override', $groups ) ) { |
| 52 | - $date = $groups['override']; |
|
| 52 | + $date = $groups[ 'override' ]; |
|
| 53 | 53 | } else { |
| 54 | - $date = $groups['override-prem'] . '/' . date( 'Y' ); |
|
| 54 | + $date = $groups[ 'override-prem' ] . '/' . date( 'Y' ); |
|
| 55 | 55 | } |
| 56 | 56 | return \DateTime::createFromFormat( 'd/m/Y', $date )->getTimestamp(); |
| 57 | 57 | } |
@@ -62,17 +62,15 @@ discard block |
||
| 62 | 62 | * @param array $groups |
| 63 | 63 | * @return int |
| 64 | 64 | */ |
| 65 | - public static function getValidFlagTimestamp( array $groups ): int { |
|
| 66 | - $checkuser = isset( $groups['checkuser'] ) ? |
|
| 67 | - \DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() : |
|
| 68 | - 0; |
|
| 69 | - $bureaucrat = isset( $groups['bureaucrat'] ) ? |
|
| 70 | - \DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() : |
|
| 71 | - 0; |
|
| 65 | + public static function getValidFlagTimestamp ( array $groups ): int { |
|
| 66 | + $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 67 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : 0; |
|
| 68 | + $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 69 | + \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : 0; |
|
| 72 | 70 | |
| 73 | 71 | $timestamp = max( $bureaucrat, $checkuser ); |
| 74 | 72 | if ( $timestamp === 0 ) { |
| 75 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp(); |
|
| 73 | + $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 76 | 74 | } |
| 77 | 75 | return $timestamp; |
| 78 | 76 | } |
@@ -81,14 +79,14 @@ discard block |
||
| 81 | 79 | * @param array $groups |
| 82 | 80 | * @return bool |
| 83 | 81 | */ |
| 84 | - public static function isOverrideExpired( array $groups ) : bool { |
|
| 85 | - if ( !isset( $groups['override'] ) ) { |
|
| 82 | + public static function isOverrideExpired ( array $groups ) : bool { |
|
| 83 | + if ( !isset( $groups[ 'override' ] ) ) { |
|
| 86 | 84 | return false; |
| 87 | 85 | } |
| 88 | 86 | |
| 89 | 87 | $flagTS = self::getValidFlagTimestamp( $groups ); |
| 90 | 88 | $usualTS = strtotime( date( 'Y' ) . '-' . date( 'm-d', $flagTS ) ); |
| 91 | - $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups['override'] )->getTimestamp(); |
|
| 89 | + $overrideTS = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'override' ] )->getTimestamp(); |
|
| 92 | 90 | $delay = 60 * 60 * 24 * 3; |
| 93 | 91 | |
| 94 | 92 | return time() > $usualTS + $delay && time() > $overrideTS + $delay; |
@@ -99,9 +97,9 @@ discard block |
||
| 99 | 97 | * |
| 100 | 98 | * @return User[] |
| 101 | 99 | */ |
| 102 | - public function getAdminsList() : array { |
|
| 100 | + public function getAdminsList () : array { |
|
| 103 | 101 | if ( $this->adminsList === null ) { |
| 104 | - $this->adminsList = []; |
|
| 102 | + $this->adminsList = [ ]; |
|
| 105 | 103 | foreach ( $this->getDecodedContent() as $user => $info ) { |
| 106 | 104 | $userObj = new User( $user, $this->wiki ); |
| 107 | 105 | $userObj->setInfo( $info ); |
@@ -116,7 +114,7 @@ discard block |
||
| 116 | 114 | * |
| 117 | 115 | * @return array[] |
| 118 | 116 | */ |
| 119 | - public function getDecodedContent() : array { |
|
| 117 | + public function getDecodedContent () : array { |
|
| 120 | 118 | return json_decode( $this->getContent(), true ); |
| 121 | 119 | } |
| 122 | 120 | } |
@@ -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 | |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public static function isCLI() : bool { |
|
| 60 | + public static function isCLI () : bool { |
|
| 61 | 61 | return PHP_SAPI === 'cli'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Populate options and check for required ones |
| 66 | 66 | */ |
| 67 | - public function __construct() { |
|
| 67 | + public function __construct () { |
|
| 68 | 68 | $opts = getopt( self::SHORT_OPTS, self::LONG_OPTS ); |
| 69 | 69 | $this->checkRequiredOpts( $opts ); |
| 70 | 70 | $this->checkConflictingOpts( $opts ); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * @param array $opts |
| 77 | 77 | */ |
| 78 | - private function checkRequiredOpts( array $opts ) : void { |
|
| 78 | + private function checkRequiredOpts ( array $opts ) : void { |
|
| 79 | 79 | $missingOpts = array_diff( self::REQUIRED_OPTS, array_keys( $opts ) ); |
| 80 | 80 | if ( $missingOpts ) { |
| 81 | 81 | exit( 'Required options missing: ' . implode( ', ', $missingOpts ) ); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * @param array $opts |
| 93 | 93 | */ |
| 94 | - private function checkConflictingOpts( array $opts ) : void { |
|
| 94 | + private function checkConflictingOpts ( array $opts ) : void { |
|
| 95 | 95 | $hasPw = array_key_exists( 'password', $opts ); |
| 96 | 96 | $hasPwFile = array_key_exists( 'use-password-file', $opts ); |
| 97 | 97 | if ( $hasPw && $hasPwFile ) { |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * @param array &$opts |
| 110 | 110 | */ |
| 111 | - private function canonicalize( array &$opts ) : void { |
|
| 111 | + private function canonicalize ( array &$opts ) : void { |
|
| 112 | 112 | if ( array_key_exists( 'use-password-file', $opts ) ) { |
| 113 | 113 | $pw = trim( file_get_contents( self::PASSWORD_FILE ) ); |
| 114 | - $opts['password'] = $pw; |
|
| 115 | - unset( $opts['use-password-file'] ); |
|
| 114 | + $opts[ 'password' ] = $pw; |
|
| 115 | + unset( $opts[ 'use-password-file' ] ); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | * @param mixed|null $default |
| 122 | 122 | * @return mixed |
| 123 | 123 | */ |
| 124 | - public function getOpt( string $opt, $default = null ) { |
|
| 125 | - return $this->opts[$opt] ?? $default; |
|
| 124 | + public function getOpt ( string $opt, $default = null ) { |
|
| 125 | + return $this->opts[ $opt ] ?? $default; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * @return array Either [ 'task' => taskname ] or [ 'subtask' => subtaskname ] |
| 130 | 130 | */ |
| 131 | - public function getTaskOpt() : array { |
|
| 131 | + public function getTaskOpt () : array { |
|
| 132 | 132 | return array_intersect_key( |
| 133 | 133 | $this->opts, |
| 134 | 134 | [ 'task' => true, 'subtask' => true ] |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | /** |
| 139 | 139 | * @return string|null |
| 140 | 140 | */ |
| 141 | - public function getURL() : ?string { |
|
| 141 | + public function getURL () : ?string { |
|
| 142 | 142 | return $this->getOpt( 'force-url' ); |
| 143 | 143 | } |
| 144 | 144 | } |