Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356351 )

Change subject: Make use of …::class language feature
......................................................................

Make use of …::class language feature

You might wonder how class_exists( ActualClass::class ) can work. It
does. This does not need the class to be loaded. For what PHP cares
about this is still a string. But the …::class syntax makes it possible
to find usages of a class much, much easier with the tools IDEs provide.

Change-Id: If2ae66eca264278ae503e59c96a0494f142b92a9
---
M composer.json
M includes/WikidataPageBanner.functions.php
M includes/WikidataPageBanner.hooks.php
M tests/phpunit/BannerMFTest.php
M tests/phpunit/BannerOptionsTest.php
M tests/phpunit/BannerTest.php
6 files changed, 23 insertions(+), 17 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/51/356351/1

diff --git a/composer.json b/composer.json
index bd28283..0e05626 100644
--- a/composer.json
+++ b/composer.json
@@ -7,6 +7,9 @@
        ],
        "type": "mediawiki-extension",
        "license": "GPL-2.0",
+       "require": {
+               "php": ">=5.5.9",
+       },
        "require-dev": {
                "jakub-onderka/php-parallel-lint": "0.9.2",
                "mediawiki/mediawiki-codesniffer": "0.7.2",
diff --git a/includes/WikidataPageBanner.functions.php 
b/includes/WikidataPageBanner.functions.php
index 9bb6ef8..98e2ba1 100755
--- a/includes/WikidataPageBanner.functions.php
+++ b/includes/WikidataPageBanner.functions.php
@@ -274,14 +274,14 @@
        public static function getPageImagesBanner( $title ) {
                $config = self::getWPBConfig();
 
-               // Ensure PageImages client is installed
-               if ( class_exists( 'PageImages' ) && $config->get( 
'WPBEnablePageImagesBanners' ) ) {
+               if ( class_exists( PageImages::class ) && $config->get( 
'WPBEnablePageImagesBanners' ) ) {
                        $pi = PageImages::getPageImage( $title );
                        // getPageImage returns false if no page image.
                        if ( $pi ) {
                                return $pi->getTitle()->getDBkey();
                        }
                }
+
                return null;
        }
 
@@ -299,8 +299,7 @@
                        return null;
                }
 
-               // Ensure Wikibase client is installed
-               if ( class_exists( 'Wikibase\Client\WikibaseClient' ) ) {
+               if ( class_exists( Wikibase\Client\WikibaseClient::class ) ) {
                        $entityIdLookup = 
Wikibase\Client\WikibaseClient::getDefaultInstance()
                        ->getStore()
                        ->getEntityIdLookup();
diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
index 4bc2c4a..baaf837 100755
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -76,12 +76,13 @@
         */
        public static function onBeforePageDisplay( OutputPage $out, Skin $skin 
) {
                // if images are disabled on Minerva skin, then do nothing
-               if ( class_exists( 'MobileContext' )
-                               && 
MobileContext::singleton()->shouldDisplayMobileView()
-                               && MobileContext::singleton()->imagesDisabled() 
=== true
-                       ) {
+               if ( class_exists( MobileContext::class )
+                       && MobileContext::singleton()->shouldDisplayMobileView()
+                       && MobileContext::singleton()->imagesDisabled() === true
+               ) {
                        return true;
                }
+
                $config = WikidataPageBannerFunctions::getWPBConfig();
                $title = $out->getTitle();
                $isDiff = $out->getRequest()->getCheck( 'diff' );
diff --git a/tests/phpunit/BannerMFTest.php b/tests/phpunit/BannerMFTest.php
index c4be57e..031c5e1 100644
--- a/tests/phpunit/BannerMFTest.php
+++ b/tests/phpunit/BannerMFTest.php
@@ -9,9 +9,9 @@
 class BannerMFTest extends MediaWikiTestCase {
        /**
         * Stores the original value for MobileContext
-        * @var bool $oldDisableImages;
+        * @var MobileContext|null
         */
-       private static $oldMobileContext = null;
+       private static $oldMobileContext;
 
        /**
         * Add test pages to database
@@ -28,7 +28,8 @@
 
        protected function setUp() {
                parent::setUp();
-               if ( class_exists( 'MobileContext' ) ) {
+
+               if ( class_exists( MobileContext::class ) ) {
                        self::$oldMobileContext = MobileContext::singleton();
                        $mobileContext = $this->makeContext();
                        $mobileContext->setForceMobileView( true );
@@ -39,16 +40,18 @@
                        $reflectionProperty->setAccessible( true );
                        $reflectionProperty->setValue( $mobileContext, true );
                }
+
                $this->addDBData();
                $this->setMwGlobals( 'wgWPBImage', "DefaultBanner" );
                $this->setMwGlobals( 'wgWPBEnableDefaultBanner', true );
        }
 
        protected function tearDown() {
-               if ( class_exists( 'MobileContext' ) ) {
+               if ( class_exists( MobileContext::class ) ) {
                        // restore old mobile context class
                        MobileContext::setInstance( self::$oldMobileContext );
                }
+
                parent::tearDown();
        }
 
@@ -56,8 +59,8 @@
         * Test banner addition on disabling images in MobileFrontend
         */
        public function testMFBannerWithImageDisabled() {
-               if ( class_exists( 'MobileContext' ) ) {
-                       $skin = $this->getMock( "Skin" );
+               if ( class_exists( MobileContext::class ) ) {
+                       $skin = $this->getMock( Skin::class );
                        $out = $this->createPage( 'PageWithoutCustomBanner', 
NS_MAIN );
                        WikidataPageBanner::onBeforePageDisplay( $out, $skin );
                        $this->assertNull( $out->getProperty( 
'articlebanner-name' ) );
diff --git a/tests/phpunit/BannerOptionsTest.php 
b/tests/phpunit/BannerOptionsTest.php
index a6d155f..834104e 100644
--- a/tests/phpunit/BannerOptionsTest.php
+++ b/tests/phpunit/BannerOptionsTest.php
@@ -167,7 +167,7 @@
         * @return Parser Parser object associated with test pages
         */
        protected function createParser( $title, $namespace ) {
-               $parser = $this->getMock( 'Parser' );
+               $parser = $this->getMock( Parser::class );
 
                $parserOutput = new ParserOutput();
                $parser->expects( $this->any() )->method( 'getOutput' )
diff --git a/tests/phpunit/BannerTest.php b/tests/phpunit/BannerTest.php
index 589b4cf..39f33f2 100644
--- a/tests/phpunit/BannerTest.php
+++ b/tests/phpunit/BannerTest.php
@@ -97,7 +97,7 @@
                // store a mock object in $wpbFunctionsClass static variable so 
that hooks call mock functions
                // through this variable when performing tests
                WikidataPageBanner::$wpbFunctionsClass = 
"MockWikidataPageBannerFunctions";
-               $skin = $this->getMock( "Skin" );
+               $skin = $this->getMock( Skin::class );
                $skin->expects( $this->any() )->method( 'getSkinName' )
                        ->will( $this->returnValue( "vector" ) );
                WikidataPageBanner::onBeforePageDisplay( $out, $skin );
@@ -174,7 +174,7 @@
         * @return Parser Parser object associated with test pages
         */
        protected function createParser( $title, $namespace ) {
-               $parser = $this->getMock( 'Parser' );
+               $parser = $this->getMock( Parser::class );
 
                $parserOutput = new ParserOutput();
                $parser->expects( $this->any() )->method( 'getOutput' )

-- 
To view, visit https://gerrit.wikimedia.org/r/356351
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If2ae66eca264278ae503e59c96a0494f142b92a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to