From: Timo Tijhof
Date: Tue, 7 Mar 2017 02:14:14 +0000 (-0800)
Subject: Clean up remaining get_class() uses
X-Git-Tag: 1.31.0-rc.0~3850
X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=3a2a707546344574c33f7ad7cbff46bfa2b74443;p=lhc%2Fweb%2Fwiklou.git
Clean up remaining get_class() uses
* get_class() -> __CLASS__ (same as self::class)
* get_called_class() -> static::class
* get_class($this) -> static::class
Change-Id: I1888a1897ecf4548a2e5a67a942e5c080dd7e3d3
---
diff --git a/includes/collation/IcuCollation.php b/includes/collation/IcuCollation.php
index bf1fe74d5e..e0eb1c13c8 100644
--- a/includes/collation/IcuCollation.php
+++ b/includes/collation/IcuCollation.php
@@ -330,7 +330,7 @@ class IcuCollation extends Collation {
$cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
$cacheKey = $cache->makeKey(
'first-letters',
- get_class( $this ),
+ static::class,
$this->locale,
$this->digitTransformLanguage->getCode(),
self::getICUVersion(),
diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php
index 829dd73f0b..ea5278fc06 100644
--- a/includes/context/ContextSource.php
+++ b/includes/context/ContextSource.php
@@ -39,7 +39,7 @@ abstract class ContextSource implements IContextSource {
*/
public function getContext() {
if ( $this->context === null ) {
- $class = get_class( $this );
+ $class = static::class;
wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
"Using RequestContext::getMain() for sanity\n" );
$this->context = RequestContext::getMain();
diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php
index e958c9449f..4ff8636e2e 100644
--- a/includes/exception/MWException.php
+++ b/includes/exception/MWException.php
@@ -112,7 +112,7 @@ class MWException extends Exception {
"
\n";
} else {
$logId = WebRequest::getRequestId();
- $type = get_class( $this );
+ $type = static::class;
return "" .
'[' . $logId . '] ' .
gmdate( 'Y-m-d H:i:s' ) . ": " .
@@ -164,7 +164,7 @@ class MWException extends Exception {
if ( $this->useOutputPage() ) {
$wgOut->prepareErrorPage( $this->getPageTitle() );
- $hookResult = $this->runHooks( get_class( $this ) );
+ $hookResult = $this->runHooks( static::class );
if ( $hookResult ) {
$wgOut->addHTML( $hookResult );
} else {
@@ -183,7 +183,7 @@ class MWException extends Exception {
'' .
"\n";
- $hookResult = $this->runHooks( get_class( $this ) . 'Raw' );
+ $hookResult = $this->runHooks( static::class . 'Raw' );
if ( $hookResult ) {
echo $hookResult;
} else {
@@ -203,7 +203,7 @@ class MWException extends Exception {
if ( defined( 'MW_API' ) ) {
// Unhandled API exception, we can't be sure that format printer is alive
- self::header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $this ) );
+ self::header( 'MediaWiki-API-Error: internal_api_error_' . static::class );
wfHttpError( 500, 'Internal Server Error', $this->getText() );
} elseif ( self::isCommandLine() ) {
$message = $this->getText();
diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php
index 487d6f647b..3a3146bc22 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -475,7 +475,7 @@ abstract class HTMLFormField {
public function getTableRow( $value ) {
list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
$inputHtml = $this->getInputHTML( $value );
- $fieldType = get_class( $this );
+ $fieldType = static::class;
$helptext = $this->getHelpTextHtmlTable( $this->getHelpText() );
$cellAttributes = [];
$rowAttributes = [];
@@ -533,7 +533,7 @@ abstract class HTMLFormField {
public function getDiv( $value ) {
list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
$inputHtml = $this->getInputHTML( $value );
- $fieldType = get_class( $this );
+ $fieldType = static::class;
$helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
$cellAttributes = [];
$label = $this->getLabelHtml( $cellAttributes );
@@ -601,7 +601,7 @@ abstract class HTMLFormField {
$infusable = false;
}
- $fieldType = get_class( $this );
+ $fieldType = static::class;
$help = $this->getHelpText();
$errors = $this->getErrorsRaw( $value );
foreach ( $errors as &$error ) {
diff --git a/includes/htmlform/fields/HTMLCheckMatrix.php b/includes/htmlform/fields/HTMLCheckMatrix.php
index 46172a581b..fa18a3cdad 100644
--- a/includes/htmlform/fields/HTMLCheckMatrix.php
+++ b/includes/htmlform/fields/HTMLCheckMatrix.php
@@ -189,7 +189,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
public function getTableRow( $value ) {
list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
$inputHtml = $this->getInputHTML( $value );
- $fieldType = get_class( $this );
+ $fieldType = static::class;
$helptext = $this->getHelpTextHtmlTable( $this->getHelpText() );
$cellAttributes = [ 'colspan' => 2 ];
diff --git a/includes/htmlform/fields/HTMLFormFieldCloner.php b/includes/htmlform/fields/HTMLFormFieldCloner.php
index 8fb840a136..dd9184bf33 100644
--- a/includes/htmlform/fields/HTMLFormFieldCloner.php
+++ b/includes/htmlform/fields/HTMLFormFieldCloner.php
@@ -46,7 +46,7 @@ class HTMLFormFieldCloner extends HTMLFormField {
protected $uniqueId;
public function __construct( $params ) {
- $this->uniqueId = get_class( $this ) . ++self::$counter . 'x';
+ $this->uniqueId = static::class . ++self::$counter . 'x';
parent::__construct( $params );
if ( empty( $this->mParams['fields'] ) || !is_array( $this->mParams['fields'] ) ) {
diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php
index 7a41cebe65..3aad6f8793 100644
--- a/includes/installer/WebInstallerPage.php
+++ b/includes/installer/WebInstallerPage.php
@@ -133,7 +133,7 @@ abstract class WebInstallerPage {
* @return string
*/
public function getName() {
- return str_replace( 'WebInstaller', '', get_class( $this ) );
+ return str_replace( 'WebInstaller', '', static::class );
}
/**
diff --git a/includes/jobqueue/JobSpecification.php b/includes/jobqueue/JobSpecification.php
index d636dc6516..d844795143 100644
--- a/includes/jobqueue/JobSpecification.php
+++ b/includes/jobqueue/JobSpecification.php
@@ -128,7 +128,7 @@ class JobSpecification implements IJobSpecification {
$this->type = $type;
$this->params = $params;
- $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . get_class( $this ) );
+ $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . static::class );
$this->opts = $opts;
}
diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php
index 60aec45729..1ab0f369db 100644
--- a/includes/media/TransformationalImageHandler.php
+++ b/includes/media/TransformationalImageHandler.php
@@ -569,7 +569,7 @@ abstract class TransformationalImageHandler extends ImageHandler {
*/
public function rotate( $file, $params ) {
return new MediaTransformError( 'thumbnail_error', 0, 0,
- get_class( $this ) . ' rotation not implemented' );
+ static::class . ' rotation not implemented' );
}
/**
diff --git a/includes/pager/IndexPager.php b/includes/pager/IndexPager.php
index dc302a2d62..46948909c6 100644
--- a/includes/pager/IndexPager.php
+++ b/includes/pager/IndexPager.php
@@ -197,7 +197,7 @@ abstract class IndexPager extends ContextSource implements Pager {
*/
public function doQuery() {
# Use the child class name for profiling
- $fname = __METHOD__ . ' (' . get_class( $this ) . ')';
+ $fname = __METHOD__ . ' (' . static::class . ')';
$section = Profiler::instance()->scopedProfileIn( $fname );
// @todo This should probably compare to DIR_DESCENDING and DIR_ASCENDING constants
@@ -348,7 +348,7 @@ abstract class IndexPager extends ContextSource implements Pager {
* @return string
*/
function getSqlComment() {
- return get_class( $this );
+ return static::class;
}
/**
diff --git a/includes/session/SessionProvider.php b/includes/session/SessionProvider.php
index e8d81cbfba..3cf69b7b33 100644
--- a/includes/session/SessionProvider.php
+++ b/includes/session/SessionProvider.php
@@ -455,7 +455,7 @@ abstract class SessionProvider implements SessionProviderInterface, LoggerAwareI
* @return string
*/
public function __toString() {
- return get_class( $this );
+ return static::class;
}
/**
@@ -475,7 +475,7 @@ abstract class SessionProvider implements SessionProviderInterface, LoggerAwareI
*/
protected function describeMessage() {
return wfMessage(
- 'sessionprovider-' . str_replace( '\\', '-', strtolower( get_class( $this ) ) )
+ 'sessionprovider-' . str_replace( '\\', '-', strtolower( static::class ) )
);
}
diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php
index a7740a093d..3ef646aec9 100644
--- a/includes/skins/Skin.php
+++ b/includes/skins/Skin.php
@@ -1038,7 +1038,7 @@ abstract class Skin extends ContextSource {
global $wgStylePath, $wgStyleVersion;
if ( $this->stylename === null ) {
- $class = get_class( $this );
+ $class = static::class;
throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
}
diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php
index 780fac4964..61dbf2b1c1 100644
--- a/includes/skins/SkinTemplate.php
+++ b/includes/skins/SkinTemplate.php
@@ -344,7 +344,7 @@ class SkinTemplate extends Skin {
$tpl->set( 'charset', 'UTF-8' );
$tpl->setRef( 'wgScript', $wgScript );
$tpl->setRef( 'skinname', $this->skinname );
- $tpl->set( 'skinclass', get_class( $this ) );
+ $tpl->set( 'skinclass', static::class );
$tpl->setRef( 'skin', $this );
$tpl->setRef( 'stylename', $this->stylename );
$tpl->set( 'printable', $out->isPrintable() );
diff --git a/includes/specialpage/QueryPage.php b/includes/specialpage/QueryPage.php
index 40f82f5588..65e82e86f7 100644
--- a/includes/specialpage/QueryPage.php
+++ b/includes/specialpage/QueryPage.php
@@ -304,7 +304,7 @@ abstract class QueryPage extends SpecialPage {
return 0;
}
- $fname = get_class( $this ) . '::recache';
+ $fname = static::class . '::recache';
$dbw = wfGetDB( DB_MASTER );
if ( !$dbw ) {
return false;
@@ -389,7 +389,7 @@ abstract class QueryPage extends SpecialPage {
* @since 1.18
*/
public function reallyDoQuery( $limit, $offset = false ) {
- $fname = get_class( $this ) . "::reallyDoQuery";
+ $fname = static::class . '::reallyDoQuery';
$dbr = $this->getRecacheDB();
$query = $this->getQueryInfo();
$order = $this->getOrderFields();
@@ -480,7 +480,7 @@ abstract class QueryPage extends SpecialPage {
public function getCachedTimestamp() {
if ( is_null( $this->cachedTimestamp ) ) {
$dbr = wfGetDB( DB_REPLICA );
- $fname = get_class( $this ) . '::getCachedTimestamp';
+ $fname = static::class . '::getCachedTimestamp';
$this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
[ 'qci_type' => $this->getName() ], $fname );
}
diff --git a/includes/specialpage/RedirectSpecialPage.php b/includes/specialpage/RedirectSpecialPage.php
index ea7d783148..b1ddacfb2f 100644
--- a/includes/specialpage/RedirectSpecialPage.php
+++ b/includes/specialpage/RedirectSpecialPage.php
@@ -52,7 +52,7 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
return $redirect;
} else {
- $class = get_class( $this );
+ $class = static::class;
throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
}
}
diff --git a/includes/tidy/TidyDriverBase.php b/includes/tidy/TidyDriverBase.php
index 96ee8c394f..d3f9d48591 100644
--- a/includes/tidy/TidyDriverBase.php
+++ b/includes/tidy/TidyDriverBase.php
@@ -27,7 +27,7 @@ abstract class TidyDriverBase {
* @return bool Whether the HTML is valid
*/
public function validate( $text, &$errorStr ) {
- throw new \MWException( get_class( $this ) . " does not support validate()" );
+ throw new \MWException( static::class . ' does not support validate()' );
}
/**
diff --git a/languages/Language.php b/languages/Language.php
index 2ec2d54e73..067231557b 100644
--- a/languages/Language.php
+++ b/languages/Language.php
@@ -415,10 +415,10 @@ class Language {
function __construct() {
$this->mConverter = new FakeConverter( $this );
// Set the code to the name of the descendant
- if ( get_class( $this ) == 'Language' ) {
+ if ( static::class === 'Language' ) {
$this->mCode = 'en';
} else {
- $this->mCode = str_replace( '_', '-', strtolower( substr( get_class( $this ), 8 ) ) );
+ $this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
}
self::getLocalisationCache();
}
diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php
index 6a426e5671..77210155fc 100644
--- a/languages/LanguageConverter.php
+++ b/languages/LanguageConverter.php
@@ -845,9 +845,8 @@ class LanguageConverter {
* @throws MWException
*/
function loadDefaultTables() {
- $name = get_class( $this );
-
- throw new MWException( "Must implement loadDefaultTables() method in class $name" );
+ $class = static::class;
+ throw new MWException( "Must implement loadDefaultTables() method in class $class" );
}
/**
diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php
index 37f76ff4d1..419ff00f85 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -439,7 +439,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
* @return string Absolute name of the temporary file
*/
protected function getNewTempFile() {
- $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
+ $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . static::class . '_' );
$this->tmpFiles[] = $fileName;
return $fileName;
@@ -1304,8 +1304,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
if ( isset( $compatibility[$func] ) ) {
return call_user_func_array( [ $this, $compatibility[$func] ], $args );
} else {
- throw new MWException( "Called non-existent $func method on "
- . get_class( $this ) );
+ throw new MWException( "Called non-existent $func method on " . static::class );
}
}
diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php
index 6b299c98c8..abef1c9206 100644
--- a/tests/phpunit/includes/api/ApiTestCase.php
+++ b/tests/phpunit/includes/api/ApiTestCase.php
@@ -219,7 +219,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
}
public function testApiTestGroup() {
- $groups = PHPUnit_Util_Test::getGroups( get_class( $this ) );
+ $groups = PHPUnit_Util_Test::getGroups( static::class );
$constraint = PHPUnit_Framework_Assert::logicalOr(
$this->contains( 'medium' ),
$this->contains( 'large' )