Merge "Improve documentation of constants throughout the codebase"
[lhc/web/wiklou.git] / includes / block / Restriction / AbstractRestriction.php
index 88a6a0f..a010e83 100644 (file)
@@ -24,6 +24,18 @@ namespace MediaWiki\Block\Restriction;
 
 abstract class AbstractRestriction implements Restriction {
 
+       /**
+        * String constant identifying the type of restriction. Expected to be overriden in subclasses
+        * with a non-empty string value.
+        */
+       const TYPE = '';
+
+       /**
+        * Numeric type identifier. Expected to be overriden in subclasses with a non-zero integer
+        * number. Must not exceed 127 to fit into a TINYINT database field.
+        */
+       const TYPE_ID = 0;
+
        /**
         * @var int
         */
@@ -37,6 +49,7 @@ abstract class AbstractRestriction implements Restriction {
        /**
         * Create Restriction.
         *
+        * @since 1.33
         * @param int $blockId
         * @param int $value
         */
@@ -46,14 +59,28 @@ abstract class AbstractRestriction implements Restriction {
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
+        */
+       public static function getType() {
+               return static::TYPE;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public static function getTypeId() {
+               return static::TYPE_ID;
+       }
+
+       /**
+        * @inheritDoc
         */
        public function getBlockId() {
                return $this->blockId;
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public function setBlockId( $blockId ) {
                $this->blockId = (int)$blockId;
@@ -62,21 +89,22 @@ abstract class AbstractRestriction implements Restriction {
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public function getValue() {
                return $this->value;
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public static function newFromRow( \stdClass $row ) {
+               // @phan-suppress-next-line PhanTypeInstantiateAbstract
                return new static( $row->ir_ipb_id, $row->ir_value );
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public function toRow() {
                return [
@@ -87,14 +115,14 @@ abstract class AbstractRestriction implements Restriction {
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public function equals( Restriction $other ) {
                return $this->getHash() === $other->getHash();
        }
 
        /**
-        * {@inheritdoc}
+        * @inheritDoc
         */
        public function getHash() {
                return $this->getType() . '-' . $this->getValue();