Remove a few obscure "done" and "empty" comments
[lhc/web/wiklou.git] / includes / block / BlockRestriction.php
index 5bf286d..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,15 +30,24 @@ 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.
         *
+        * @since 1.33
         * @param int|array $blockId
         * @param IDatabase|null $db
         * @return Restriction[]
         */
        public static function loadByBlockId( $blockId, IDatabase $db = null ) {
-               if ( is_null( $blockId ) || $blockId === [] ) {
+               if ( $blockId === null || $blockId === [] ) {
                        return [];
                }
 
@@ -58,6 +68,7 @@ class BlockRestriction {
        /**
         * Inserts the restrictions into the database.
         *
+        * @since 1.33
         * @param Restriction[] $restrictions
         * @return bool
         */
@@ -92,6 +103,7 @@ class BlockRestriction {
         * Updates the list of restrictions. This method does not allow removing all
         * of the restrictions. To do that, use ::deleteByBlockId().
         *
+        * @since 1.33
         * @param Restriction[] $restrictions
         * @return bool
         */
@@ -137,7 +149,6 @@ class BlockRestriction {
                                $restrictions
                        );
 
-                       // Nothing to remove.
                        if ( empty( $restrictionsToRemove ) ) {
                                continue;
                        }
@@ -156,6 +167,7 @@ class BlockRestriction {
        /**
         * Updates the list of restrictions by parent id.
         *
+        * @since 1.33
         * @param int $parentBlockId
         * @param Restriction[] $restrictions
         * @return bool
@@ -195,6 +207,7 @@ class BlockRestriction {
        /**
         * Delete the restrictions.
         *
+        * @since 1.33
         * @param Restriction[]|null $restrictions
         * @throws MWException
         * @return bool
@@ -224,6 +237,7 @@ class BlockRestriction {
        /**
         * Delete the restrictions by Block ID.
         *
+        * @since 1.33
         * @param int|array $blockId
         * @throws MWException
         * @return bool
@@ -240,6 +254,7 @@ class BlockRestriction {
        /**
         * Delete the restrictions by Parent Block ID.
         *
+        * @since 1.33
         * @param int|array $parentBlockId
         * @throws MWException
         * @return bool
@@ -261,6 +276,7 @@ class BlockRestriction {
         * equality check as the restrictions do not have to contain the same block
         * ids.
         *
+        * @since 1.33
         * @param Restriction[] $a
         * @param Restriction[] $b
         * @return bool
@@ -305,6 +321,7 @@ class BlockRestriction {
        /**
         * Set the blockId on a set of restrictions and return a new set.
         *
+        * @since 1.33
         * @param int $blockId
         * @param Restriction[] $restrictions
         * @return Restriction[]
@@ -406,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;
        }
 }