Remove a few obscure "done" and "empty" comments
[lhc/web/wiklou.git] / includes / block / BlockRestriction.php
index 3baa063..72f6eaa 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace MediaWiki\Block;
 
+use MediaWiki\Block\Restriction\NamespaceRestriction;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\Block\Restriction\Restriction;
 use Wikimedia\Rdbms\IResultWrapper;
@@ -29,6 +30,14 @@ use Wikimedia\Rdbms\IDatabase;
 
 class BlockRestriction {
 
+       /**
+        * Map of all of the restriction types.
+        */
+       private static $types = [
+               PageRestriction::TYPE_ID => PageRestriction::class,
+               NamespaceRestriction::TYPE_ID => NamespaceRestriction::class,
+       ];
+
        /**
         * Retrieves the restrictions from the database by block id.
         *
@@ -140,7 +149,6 @@ class BlockRestriction {
                                $restrictions
                        );
 
-                       // Nothing to remove.
                        if ( empty( $restrictionsToRemove ) ) {
                                continue;
                        }
@@ -415,11 +423,11 @@ class BlockRestriction {
         * @return Restriction|null
         */
        private static function rowToRestriction( \stdClass $row ) {
-               switch ( $row->ir_type ) {
-                       case PageRestriction::TYPE_ID:
-                               return PageRestriction::newFromRow( $row );
-                       default:
-                               return null;
+               if ( array_key_exists( (int)$row->ir_type, self::$types ) ) {
+                       $class = self::$types[ (int)$row->ir_type ];
+                       return call_user_func( [ $class, 'newFromRow' ], $row );
                }
+
+               return null;
        }
 }