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
This commit is contained in:
Timo Tijhof 2016-02-25 20:00:22 +00:00 committed by Krinkle
parent ba9333f79f
commit 46b04ec7ae
4 changed files with 7 additions and 7 deletions

View 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 . '.'
);
}

View 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()'
);
}

View 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() {

View 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