Use the instanceof and ::class features instead of strings
This makes it much easier for IDEs and tools like Phan to understand what's going on. Note this syntax is perfectly valid even if a class is undefined. Language features like `use`, `instanceof`, and `class_exists` work perfectly fine. We do this a lot in existing code. Change-Id: I4d397621ebcc6a7e842150f7641c1b23d082b730
This commit is contained in:
parent
5dca00526a
commit
7e70b8042c
6 changed files with 12 additions and 11 deletions
|
|
@ -22,6 +22,7 @@ namespace MediaWiki\Logger;
|
|||
|
||||
use DateTimeZone;
|
||||
use MediaWiki\Logger\Monolog\BufferHandler;
|
||||
use Monolog\Handler\FormattableHandlerInterface;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
@ -262,7 +263,7 @@ class MonologSpi implements Spi {
|
|||
$handler = ObjectFactory::getObjectFromSpec( $spec );
|
||||
if (
|
||||
isset( $spec['formatter'] ) &&
|
||||
is_subclass_of( $handler, 'Monolog\Handler\FormattableHandlerInterface' )
|
||||
$handler instanceof FormattableHandlerInterface
|
||||
) {
|
||||
$handler->setFormatter(
|
||||
$this->getFormatter( $spec['formatter'] )
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\CurlHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\MessageFormatter;
|
||||
use GuzzleHttp\Middleware;
|
||||
|
|
@ -271,11 +272,8 @@ class GuzzleHttpRequest extends MWHttpRequest {
|
|||
parent::prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function usingCurl() {
|
||||
return ( $this->handler && is_a( $this->handler, 'GuzzleHttp\Handler\CurlHandler' ) ) ||
|
||||
protected function usingCurl(): bool {
|
||||
return $this->handler instanceof CurlHandler ||
|
||||
( !$this->handler && extension_loaded( 'curl' ) );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class PageBundleJsonTraitTest extends MediaWikiIntegrationTestCase {
|
|||
};
|
||||
$bundle = new PageBundle( ...array_values( $this->bundleData ) );
|
||||
$json = $trait->jsonSerializePageBundle( $bundle );
|
||||
$this->assertEquals( 'Wikimedia\Parsoid\Core\PageBundle', $json['_type_'] );
|
||||
$this->assertEquals( PageBundle::class, $json['_type_'] );
|
||||
$this->assertEquals( '<h1>woohoo</h1>', $json['html'] );
|
||||
$this->assertNull( $json['mw'] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use MediaWiki\Deferred\DeferredUpdates;
|
|||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MainConfigSchema;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidParser;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidParserFactory;
|
||||
use MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper;
|
||||
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
|
||||
|
|
@ -259,7 +260,7 @@ class RevisionHTMLHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
->willThrowException( $parsoidException );
|
||||
|
||||
// Install it in the ParsoidParser object
|
||||
$reflector = new ReflectionClass( 'MediaWiki\Parser\Parsoid\ParsoidParser' );
|
||||
$reflector = new ReflectionClass( ParsoidParser::class );
|
||||
$prop = $reflector->getProperty( 'parsoid' );
|
||||
$prop->setAccessible( true );
|
||||
$prop->setValue( $parsoidParser, $mockParsoid );
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class CachedSourceTest extends TestCase {
|
|||
array_merge( [ 'get', 'makeGlobalKey', 'set' ], $methods )
|
||||
);
|
||||
|
||||
$key = 'global:MediaWiki\Tests\Unit\Settings\Cache\CachedSourceTest:' . $hashKey;
|
||||
$key = 'global:' . self::class . ':' . $hashKey;
|
||||
|
||||
$cache
|
||||
->expects( $this->once() )
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use InvalidArgumentException;
|
|||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MainConfigSchema;
|
||||
use MediaWiki\Settings\Cache\CacheableSource;
|
||||
use MediaWiki\Settings\Cache\CachedSource;
|
||||
use MediaWiki\Settings\Config\ArrayConfigBuilder;
|
||||
use MediaWiki\Settings\Config\MergeStrategy;
|
||||
use MediaWiki\Settings\Config\PhpIniSink;
|
||||
|
|
@ -529,7 +530,7 @@ class SettingsBuilderTest extends TestCase {
|
|||
->load( $mockSource );
|
||||
|
||||
$hashKey = 'abc123';
|
||||
$key = 'global:MediaWiki\Tests\Unit\Settings\Cache\CachedSourceTest:' . $hashKey;
|
||||
$key = 'global:' . self::class . ':' . $hashKey;
|
||||
|
||||
// Mock a cache miss
|
||||
$mockSource
|
||||
|
|
@ -540,7 +541,7 @@ class SettingsBuilderTest extends TestCase {
|
|||
$mockCache
|
||||
->expects( $this->once() )
|
||||
->method( 'makeGlobalKey' )
|
||||
->with( 'MediaWiki\Settings\Cache\CachedSource', $hashKey )
|
||||
->with( CachedSource::class, $hashKey )
|
||||
->willReturn( $key );
|
||||
|
||||
$mockCache
|
||||
|
|
|
|||
Loading…
Reference in a new issue