X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Futils%2FMWRestrictions.php;h=caf88a15f1c83e3d7cd8f9c6b8a4c6a3dd90494c;hb=86d7bd86fa08db2dbf3651a656d8238a34703c4f;hp=3b4dc114eb7b37bf10a9b58f86e16457fe56816b;hpb=f875f3d31867067116641af987dea4511324e96b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/utils/MWRestrictions.php b/includes/utils/MWRestrictions.php index 3b4dc114eb..caf88a15f1 100644 --- a/includes/utils/MWRestrictions.php +++ b/includes/utils/MWRestrictions.php @@ -23,10 +23,11 @@ */ class MWRestrictions { - private $ipAddresses = array( '0.0.0.0/0', '::/0' ); + private $ipAddresses = [ '0.0.0.0/0', '::/0' ]; /** * @param array $restrictions + * @throws InvalidArgumentException */ protected function __construct( array $restrictions = null ) { if ( $restrictions !== null ) { @@ -44,6 +45,7 @@ class MWRestrictions { /** * @param array $restrictions * @return MWRestrictions + * @throws InvalidArgumentException */ public static function newFromArray( array $restrictions ) { return new self( $restrictions ); @@ -52,6 +54,7 @@ class MWRestrictions { /** * @param string $json JSON representation of the restrictions * @return MWRestrictions + * @throws InvalidArgumentException */ public static function newFromJson( $json ) { $restrictions = FormatJson::decode( $json, true ); @@ -62,20 +65,20 @@ class MWRestrictions { } private function loadFromArray( array $restrictions ) { - static $validKeys = array( 'IPAddresses' ); - static $neededKeys = array( 'IPAddresses' ); + static $validKeys = [ 'IPAddresses' ]; + static $neededKeys = [ 'IPAddresses' ]; $keys = array_keys( $restrictions ); $invalidKeys = array_diff( $keys, $validKeys ); if ( $invalidKeys ) { throw new InvalidArgumentException( - 'Array contains invalid keys: ' . join( ', ', $invalidKeys ) + 'Array contains invalid keys: ' . implode( ', ', $invalidKeys ) ); } $missingKeys = array_diff( $neededKeys, $keys ); if ( $missingKeys ) { throw new InvalidArgumentException( - 'Array is missing required keys: ' . join( ', ', $missingKeys ) + 'Array is missing required keys: ' . implode( ', ', $missingKeys ) ); } @@ -95,9 +98,9 @@ class MWRestrictions { * @return array */ public function toArray() { - return array( + return [ 'IPAddresses' => $this->ipAddresses, - ); + ]; } /** @@ -119,9 +122,9 @@ class MWRestrictions { * @return Status */ public function check( WebRequest $request ) { - $ok = array( + $ok = [ 'ip' => $this->checkIP( $request->getIP() ), - ); + ]; $status = Status::newGood(); $status->setResult( $ok === array_filter( $ok ), $ok ); return $status;