objectcache: Use variadic signature for makeKey()
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 20 Jul 2019 16:49:06 +0000 (17:49 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 23 Jul 2019 18:44:06 +0000 (20:44 +0200)
This should help fix the following issues that various repos
are getting from Phan as of late:

> Call with 5 arg(s) to \BagOStuff::makeKey() which only takes 2 arg(s)
> defined at ../../includes/libs/objectcache/BagOStuff.php:456
> <source="PhanParamTooMany"/>

Bug: T228563
Depends-On: I5cfba063821101325a5a7359e6b8ad71a0fb1b2f
Depends-On: Ifa5b96735376f2fbe3680799f960616ba8d357ff
Change-Id: Ic9df7f3ad7f356c7cbdfe1edfbe35821b931dda6

12 files changed:
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/CachedBagOStuff.php
includes/libs/objectcache/IStoreKeyEncoder.php
includes/libs/objectcache/MediumSpecificBagOStuff.php
includes/libs/objectcache/MultiWriteBagOStuff.php
includes/libs/objectcache/ReplicatedBagOStuff.php
includes/libs/objectcache/WANObjectCache.php
tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php
tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php
tests/phpunit/unit/includes/objectcache/RedisBagOStuffTest.php

index 906e955..8c99532 100644 (file)
@@ -440,20 +440,20 @@ abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwar
         *
         * @since 1.27
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       abstract public function makeGlobalKey( $class, $component = null );
+       abstract public function makeGlobalKey( $class, ...$components );
 
        /**
         * Make a cache key, scoped to this instance's keyspace.
         *
         * @since 1.27
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       abstract public function makeKey( $class, $component = null );
+       abstract public function makeKey( $class, ...$components );
 
        /**
         * @param int $flag ATTR_* class constant
index c97f56e..0ab26c9 100644 (file)
@@ -145,15 +145,15 @@ class CachedBagOStuff extends BagOStuff {
        }
 
        public function makeKeyInternal( $keyspace, $args ) {
-               return $this->backend->makeKeyInternal( ...func_get_args() );
+               return $this->backend->makeKeyInternal( $keyspace, $args );
        }
 
-       public function makeKey( $class, $component = null ) {
-               return $this->backend->makeKey( ...func_get_args() );
+       public function makeKey( $class, ...$components ) {
+               return $this->backend->makeKey( $class, ...$components );
        }
 
-       public function makeGlobalKey( $class, $component = null ) {
-               return $this->backend->makeGlobalKey( ...func_get_args() );
+       public function makeGlobalKey( $class, ...$components ) {
+               return $this->backend->makeGlobalKey( $class, ...$components );
        }
 
        public function getLastError() {
index da0686e..59e1c05 100644 (file)
@@ -11,17 +11,17 @@ interface IStoreKeyEncoder {
         * Make a global cache key.
         *
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       public function makeGlobalKey( $class, $component = null );
+       public function makeGlobalKey( $class, ...$components );
 
        /**
         * Make a cache key, scoped to this instance's keyspace.
         *
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         */
-       public function makeKey( $class, $component = null );
+       public function makeKey( $class, ...$components );
 }
index fb088c8..e742432 100644 (file)
@@ -858,11 +858,11 @@ abstract class MediumSpecificBagOStuff extends BagOStuff {
         * Make a global cache key.
         *
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         * @since 1.27
         */
-       public function makeGlobalKey( $class, $component = null ) {
+       public function makeGlobalKey( $class, ...$components ) {
                return $this->makeKeyInternal( 'global', func_get_args() );
        }
 
@@ -870,11 +870,11 @@ abstract class MediumSpecificBagOStuff extends BagOStuff {
         * Make a cache key, scoped to this instance's keyspace.
         *
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         * @since 1.27
         */
-       public function makeKey( $class, $component = null ) {
+       public function makeKey( $class, ...$components ) {
                return $this->makeKeyInternal( $this->keyspace, func_get_args() );
        }
 
index 6e9f387..d150880 100644 (file)
@@ -350,14 +350,14 @@ class MultiWriteBagOStuff extends BagOStuff {
        }
 
        public function makeKeyInternal( $keyspace, $args ) {
-               return $this->caches[0]->makeKeyInternal( ...func_get_args() );
+               return $this->caches[0]->makeKeyInternal( $keyspace, $args );
        }
 
-       public function makeKey( $class, $component = null ) {
+       public function makeKey( $class, ...$components ) {
                return $this->caches[0]->makeKey( ...func_get_args() );
        }
 
-       public function makeGlobalKey( $class, $component = null ) {
+       public function makeGlobalKey( $class, ...$components ) {
                return $this->caches[0]->makeGlobalKey( ...func_get_args() );
        }
 
index e49fa10..504d515 100644 (file)
@@ -162,11 +162,11 @@ class ReplicatedBagOStuff extends BagOStuff {
                return $this->writeStore->makeKeyInternal( ...func_get_args() );
        }
 
-       public function makeKey( $class, $component = null ) {
+       public function makeKey( $class, ...$components ) {
                return $this->writeStore->makeKey( ...func_get_args() );
        }
 
-       public function makeGlobalKey( $class, $component = null ) {
+       public function makeGlobalKey( $class, ...$components ) {
                return $this->writeStore->makeGlobalKey( ...func_get_args() );
        }
 
index f416ec5..0bc21a3 100644 (file)
@@ -1873,22 +1873,22 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt
        /**
         * @see BagOStuff::makeKey()
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         * @since 1.27
         */
-       public function makeKey( $class, $component = null ) {
+       public function makeKey( $class, ...$components ) {
                return $this->cache->makeKey( ...func_get_args() );
        }
 
        /**
         * @see BagOStuff::makeGlobalKey()
         * @param string $class Key class
-        * @param string|null $component [optional] Key component (starting with a key collection name)
-        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        * @param string ...$components Key components (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components
         * @since 1.27
         */
-       public function makeGlobalKey( $class, $component = null ) {
+       public function makeGlobalKey( $class, ...$components ) {
                return $this->cache->makeGlobalKey( ...func_get_args() );
        }
 
index f953319..8c53873 100644 (file)
@@ -125,6 +125,12 @@ class CachedBagOStuffTest extends PHPUnit\Framework\TestCase {
         * @covers CachedBagOStuff::makeKey
         */
        public function testMakeKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       // This works fine on HHVM (and verified by integration tests), but due to
+                       // a bug in HHVM's Reflection, PHPUnit 4 fails to create a mock (T228563)
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $backend = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeKey' ] )
                        ->getMock();
@@ -145,6 +151,10 @@ class CachedBagOStuffTest extends PHPUnit\Framework\TestCase {
         * @covers CachedBagOStuff::makeGlobalKey
         */
        public function testMakeGlobalKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $backend = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeGlobalKey' ] )
                        ->getMock();
index 9f88474..dc49a13 100644 (file)
@@ -107,6 +107,10 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
         * @covers MultiWriteBagOStuff::makeKey
         */
        public function testMakeKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $cache1 = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeKey' ] )->getMock();
                $cache1->expects( $this->once() )->method( 'makeKey' )
@@ -124,6 +128,10 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
         * @covers MultiWriteBagOStuff::makeGlobalKey
         */
        public function testMakeGlobalKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $cache1 = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeGlobalKey' ] )->getMock();
                $cache1->expects( $this->once() )->method( 'makeGlobalKey' )
index 890218c..bff45b5 100644 (file)
@@ -1865,6 +1865,10 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
         * @covers WANObjectCache::makeKey
         */
        public function testMakeKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $backend = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeKey' ] )->getMock();
                $backend->expects( $this->once() )->method( 'makeKey' )
@@ -1881,6 +1885,10 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
         * @covers WANObjectCache::makeGlobalKey
         */
        public function testMakeGlobalKey() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $backend = $this->getMockBuilder( HashBagOStuff::class )
                        ->setMethods( [ 'makeGlobalKey' ] )->getMock();
                $backend->expects( $this->once() )->method( 'makeGlobalKey' )
index 72db766..9616672 100644 (file)
@@ -86,6 +86,10 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
         * @return PHPUnit_Framework_MockObject_MockObject|HashBagOStuff
         */
        private function getMockCache() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $mock = $this->getMockBuilder( HashBagOStuff::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'get', 'set', 'delete', 'makeKey' ] )
index e35e373..7233b86 100644 (file)
@@ -12,6 +12,11 @@ class RedisBagOStuffTest extends MediaWikiUnitTestCase {
 
        protected function setUp() {
                parent::setUp();
+
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $cache = $this->getMockBuilder( RedisBagOStuff::class )
                        ->disableOriginalConstructor()
                        ->getMock();