Clean up remaining get_class() uses
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 7 Mar 2017 02:14:14 +0000 (18:14 -0800)
committerReedy <reedy@wikimedia.org>
Tue, 7 Mar 2017 22:03:47 +0000 (22:03 +0000)
* get_class()        -> __CLASS__ (same as self::class)
* get_called_class() -> static::class
* get_class($this)   -> static::class

Change-Id: I1888a1897ecf4548a2e5a67a942e5c080dd7e3d3

20 files changed:
includes/collation/IcuCollation.php
includes/context/ContextSource.php
includes/exception/MWException.php
includes/htmlform/HTMLFormField.php
includes/htmlform/fields/HTMLCheckMatrix.php
includes/htmlform/fields/HTMLFormFieldCloner.php
includes/installer/WebInstallerPage.php
includes/jobqueue/JobSpecification.php
includes/media/TransformationalImageHandler.php
includes/pager/IndexPager.php
includes/session/SessionProvider.php
includes/skins/Skin.php
includes/skins/SkinTemplate.php
includes/specialpage/QueryPage.php
includes/specialpage/RedirectSpecialPage.php
includes/tidy/TidyDriverBase.php
languages/Language.php
languages/LanguageConverter.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/api/ApiTestCase.php

index bf1fe74..e0eb1c1 100644 (file)
@@ -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(),
index 829dd73..ea5278f 100644 (file)
@@ -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();
index e958c94..4ff8636 100644 (file)
@@ -112,7 +112,7 @@ class MWException extends Exception {
                        "</p>\n";
                } else {
                        $logId = WebRequest::getRequestId();
-                       $type = get_class( $this );
+                       $type = static::class;
                        return "<div class=\"errorbox\">" .
                        '[' . $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 {
                                '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\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();
index 487d6f6..3a3146b 100644 (file)
@@ -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 ) {
index 46172a5..fa18a3c 100644 (file)
@@ -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 ];
 
index 8fb840a..dd9184b 100644 (file)
@@ -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'] ) ) {
index 7a41ceb..3aad6f8 100644 (file)
@@ -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 );
        }
 
        /**
index d636dc6..d844795 100644 (file)
@@ -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;
        }
 
index 60aec45..1ab0f36 100644 (file)
@@ -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' );
        }
 
        /**
index dc302a2..4694890 100644 (file)
@@ -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;
        }
 
        /**
index e8d81cb..3cf69b7 100644 (file)
@@ -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 ) )
                );
        }
 
index a7740a0..3ef646a 100644 (file)
@@ -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()" );
                }
 
index 780fac4..61dbf2b 100644 (file)
@@ -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() );
index 40f82f5..65e82e8 100644 (file)
@@ -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 );
                }
index ea7d783..b1ddacf 100644 (file)
@@ -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!" );
                }
        }
index 96ee8c3..d3f9d48 100644 (file)
@@ -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()' );
        }
 
        /**
index 2ec2d54..0672315 100644 (file)
@@ -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();
        }
index 6a426e5..7721015 100644 (file)
@@ -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" );
        }
 
        /**
index 37f76ff..419ff00 100644 (file)
@@ -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 );
                }
        }
 
index 6b299c9..abef1c9 100644 (file)
@@ -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' )