*/
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 ) {
/**
* @param array $restrictions
* @return MWRestrictions
+ * @throws InvalidArgumentException
*/
public static function newFromArray( array $restrictions ) {
return new self( $restrictions );
/**
* @param string $json JSON representation of the restrictions
* @return MWRestrictions
+ * @throws InvalidArgumentException
*/
public static function newFromJson( $json ) {
$restrictions = FormatJson::decode( $json, true );
}
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 )
);
}
* @return array
*/
public function toArray() {
- return array(
+ return [
'IPAddresses' => $this->ipAddresses,
- );
+ ];
}
/**
* @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;