resourceloader: Simplify makeLoaderStateScript and makeLoaderSourcesScript
authorFomafix <fomafix@googlemail.com>
Sat, 28 Sep 2019 11:32:29 +0000 (13:32 +0200)
committerKrinkle <krinklemail@gmail.com>
Sat, 28 Sep 2019 18:26:40 +0000 (18:26 +0000)
The signatures without array are not used anymore.

Change-Id: Ice6a09ff6cba0c605ed1c89a25fd8e02af041b05

includes/resourceloader/ResourceLoader.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 5d104d3..c69d4ec 100644 (file)
@@ -1366,27 +1366,20 @@ MESSAGE;
        }
 
        /**
        }
 
        /**
-        * Returns a JS call to mw.loader.state, which sets the state of one
-        * ore more modules to a given value. Has two calling conventions:
-        *
-        *    - ResourceLoader::makeLoaderStateScript( $context, $name, $state ):
-        *         Set the state of a single module called $name to $state
+        * Returns a JS call to mw.loader.state, which sets the state of modules
+        * to a given value:
         *
         *    - ResourceLoader::makeLoaderStateScript( $context, [ $name => $state, ... ] ):
         *         Set the state of modules with the given names to the given states
         *
         * @internal
         * @param ResourceLoaderContext $context
         *
         *    - ResourceLoader::makeLoaderStateScript( $context, [ $name => $state, ... ] ):
         *         Set the state of modules with the given names to the given states
         *
         * @internal
         * @param ResourceLoaderContext $context
-        * @param array|string $states
-        * @param string|null $state
+        * @param array $states
         * @return string JavaScript code
         */
        public static function makeLoaderStateScript(
         * @return string JavaScript code
         */
        public static function makeLoaderStateScript(
-               ResourceLoaderContext $context, $states, $state = null
+               ResourceLoaderContext $context, array $states
        ) {
        ) {
-               if ( !is_array( $states ) ) {
-                       $states = [ $states => $state ];
-               }
                return 'mw.loader.state('
                        . $context->encodeJson( $states )
                        . ');';
                return 'mw.loader.state('
                        . $context->encodeJson( $states )
                        . ');';
@@ -1482,10 +1475,7 @@ MESSAGE;
 
        /**
         * Returns JS code which calls mw.loader.addSource() with the given
 
        /**
         * Returns JS code which calls mw.loader.addSource() with the given
-        * parameters. Has two calling conventions:
-        *
-        *   - ResourceLoader::makeLoaderSourcesScript( $context, $id, $properties ):
-        *       Register a single source
+        * parameters.
         *
         *   - ResourceLoader::makeLoaderSourcesScript( $context,
         *         [ $id1 => $loadUrl, $id2 => $loadUrl, ... ]
         *
         *   - ResourceLoader::makeLoaderSourcesScript( $context,
         *         [ $id1 => $loadUrl, $id2 => $loadUrl, ... ]
@@ -1494,16 +1484,12 @@ MESSAGE;
         *
         * @internal For use by ResourceLoaderStartUpModule only
         * @param ResourceLoaderContext $context
         *
         * @internal For use by ResourceLoaderStartUpModule only
         * @param ResourceLoaderContext $context
-        * @param string|array $sources Source ID
-        * @param string|null $loadUrl load.php url
+        * @param array $sources
         * @return string JavaScript code
         */
        public static function makeLoaderSourcesScript(
         * @return string JavaScript code
         */
        public static function makeLoaderSourcesScript(
-               ResourceLoaderContext $context, $sources, $loadUrl = null
+               ResourceLoaderContext $context, array $sources
        ) {
        ) {
-               if ( !is_array( $sources ) ) {
-                       $sources = [ $sources => $loadUrl ];
-               }
                return 'mw.loader.addSource('
                        . $context->encodeJson( $sources )
                        . ');';
                return 'mw.loader.addSource('
                        . $context->encodeJson( $sources )
                        . ');';
index f0c97f4..99f4347 100644 (file)
@@ -626,12 +626,6 @@ END
                $this->assertEquals(
                        'mw.loader.addSource({
     "local": "/w/load.php"
                $this->assertEquals(
                        'mw.loader.addSource({
     "local": "/w/load.php"
-});',
-                       ResourceLoader::makeLoaderSourcesScript( $context, 'local', '/w/load.php' )
-               );
-               $this->assertEquals(
-                       'mw.loader.addSource({
-    "local": "/w/load.php"
 });',
                        ResourceLoader::makeLoaderSourcesScript( $context, [ 'local' => '/w/load.php' ] )
                );
 });',
                        ResourceLoader::makeLoaderSourcesScript( $context, [ 'local' => '/w/load.php' ] )
                );