Use static::class instead of get_called_class()
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 25 Feb 2016 20:00:22 +0000 (20:00 +0000)
committerKrinkle <krinklemail@gmail.com>
Mon, 29 Feb 2016 22:43:58 +0000 (22:43 +0000)
Available as of PHP 5.5 and more idomatic. Foo::class (explicit),
self::class (defined), and static::class (late bound).

Change-Id: I66937f32095a4e4ecde94ca20a935a3c3efc9cee

includes/libs/GenericArrayObject.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/actions/ActionTest.php
tests/phpunit/languages/LanguageClassesTestCase.php

index dec55c9..76e23cf 100644 (file)
@@ -144,7 +144,7 @@ abstract class GenericArrayObject extends ArrayObject {
                if ( !$this->hasValidType( $value ) ) {
                        throw new InvalidArgumentException(
                                'Can only add ' . $this->getObjectType() . ' implementing objects to '
-                               . get_called_class() . '.'
+                               . static::class . '.'
                        );
                }
 
index da9c03a..d5192ac 100644 (file)
@@ -102,7 +102,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                // Complain if self::setUp() was called, but not self::tearDown()
                // $this->called['setUp'] will be checked by self::testMediaWikiTestCaseParentSetupCalled()
                if ( isset( $this->called['setUp'] ) && !isset( $this->called['tearDown'] ) ) {
-                       throw new MWException( get_called_class() . "::tearDown() must call parent::tearDown()" );
+                       throw new MWException( static::class . "::tearDown() must call parent::tearDown()" );
                }
        }
 
@@ -294,7 +294,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         */
        final public function testMediaWikiTestCaseParentSetupCalled() {
                $this->assertArrayHasKey( 'setUp', $this->called,
-                       get_called_class() . "::setUp() must call parent::setUp()"
+                       static::class . '::setUp() must call parent::setUp()'
                );
        }
 
index 462c715..4a30292 100644 (file)
@@ -187,7 +187,7 @@ class ActionTest extends MediaWikiTestCase {
 class DummyAction extends Action {
 
        public function getName() {
-               return get_called_class();
+               return static::class;
        }
 
        public function show() {
index f93ff7d..2216ba4 100644 (file)
@@ -47,7 +47,7 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase {
         */
        protected function setUp() {
                parent::setUp();
-               $found = preg_match( '/Language(.+)Test/', get_called_class(), $m );
+               $found = preg_match( '/Language(.+)Test/', static::class, $m );
                if ( $found ) {
                        # Normalize language code since classes uses underscores
                        $m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
@@ -55,8 +55,8 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase {
                        # Fallback to english language
                        $m[1] = 'en';
                        wfDebug(
-                               __METHOD__ . " could not extract a language name "
-                                       . "out of " . get_called_class() . " failling back to 'en'\n"
+                               __METHOD__ . ' could not extract a language name '
+                                       . 'out of ' . static::class . " failling back to 'en'\n"
                        );
                }
                // @todo validate $m[1] which should be a valid language code