Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / exception / PermissionsError.php
index bfba7b2..e31374c 100644 (file)
 class PermissionsError extends ErrorPageError {
        public $permission, $errors;
 
-       public function __construct( $permission, $errors = array() ) {
+       /**
+        * @param string|null $permission A permission name or null if unknown
+        * @param array $errors Error message keys or [key, param...] arrays; must not be empty if
+        *   $permission is null
+        * @throws \InvalidArgumentException
+        */
+       public function __construct( $permission, $errors = [] ) {
                global $wgLang;
 
+               if ( $permission === null && !$errors ) {
+                       throw new \InvalidArgumentException( __METHOD__ .
+                               ': $permission and $errors cannot both be empty' );
+               }
+
                $this->permission = $permission;
 
                if ( !count( $errors ) ) {
                        $groups = array_map(
-                               array( 'User', 'makeGroupLinkWiki' ),
+                               [ 'User', 'makeGroupLinkWiki' ],
                                User::getGroupsWithPermission( $this->permission )
                        );
 
                        if ( $groups ) {
-                               $errors[] = array( 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) );
+                               $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
                        } else {
-                               $errors[] = array( 'badaccess-group0' );
+                               $errors[] = [ 'badaccess-group0' ];
                        }
                }