From 46b04ec7ae8f7160ee9ac503a57dfad9cf78bc51 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 25 Feb 2016 20:00:22 +0000 Subject: [PATCH] Use static::class instead of get_called_class() 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 | 2 +- tests/phpunit/MediaWikiTestCase.php | 4 ++-- tests/phpunit/includes/actions/ActionTest.php | 2 +- tests/phpunit/languages/LanguageClassesTestCase.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/libs/GenericArrayObject.php b/includes/libs/GenericArrayObject.php index dec55c9540..76e23cfd50 100644 --- a/includes/libs/GenericArrayObject.php +++ b/includes/libs/GenericArrayObject.php @@ -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 . '.' ); } diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index da9c03a0d3..d5192ace38 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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()' ); } diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index 462c715168..4a302920e1 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -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() { diff --git a/tests/phpunit/languages/LanguageClassesTestCase.php b/tests/phpunit/languages/LanguageClassesTestCase.php index f93ff7d388..2216ba40b1 100644 --- a/tests/phpunit/languages/LanguageClassesTestCase.php +++ b/tests/phpunit/languages/LanguageClassesTestCase.php @@ -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 -- 2.20.1