resourceloader: Throw InvalidArgumentException for invalid constructor arguments
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 Mar 2015 16:51:10 +0000 (18:51 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 Mar 2015 17:15:36 +0000 (19:15 +0200)
(But not for exceptions about missing files.)

Per Legoktm's comments on 8edbfb5feb708f80d63f118f9b00eb341278f68a.

Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb

includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderImage.php
includes/resourceloader/ResourceLoaderImageModule.php

index a46c931..db10b2c 100644 (file)
@@ -174,7 +174,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         *     to $wgResourceBasePath
         *
         * Below is a description for the $options array:
         *     to $wgResourceBasePath
         *
         * Below is a description for the $options array:
-        * @throws MWException
+        * @throws InvalidArgumentException
         * @par Construction options:
         * @code
         *     array(
         * @par Construction options:
         * @code
         *     array(
@@ -255,14 +255,14 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                case 'skinScripts':
                                case 'skinStyles':
                                        if ( !is_array( $option ) ) {
                                case 'skinScripts':
                                case 'skinStyles':
                                        if ( !is_array( $option ) ) {
-                                               throw new MWException(
+                                               throw new InvalidArgumentException(
                                                        "Invalid collated file path list error. " .
                                                        "'$option' given, array expected."
                                                );
                                        }
                                        foreach ( $option as $key => $value ) {
                                                if ( !is_string( $key ) ) {
                                                        "Invalid collated file path list error. " .
                                                        "'$option' given, array expected."
                                                );
                                        }
                                        foreach ( $option as $key => $value ) {
                                                if ( !is_string( $key ) ) {
-                                                       throw new MWException(
+                                                       throw new InvalidArgumentException(
                                                                "Invalid collated file path list key error. " .
                                                                "'$key' given, string expected."
                                                        );
                                                                "Invalid collated file path list key error. " .
                                                                "'$key' given, string expected."
                                                        );
index 4b16a12..d12975a 100644 (file)
@@ -44,7 +44,7 @@ class ResourceLoaderImage {
         * @param string|array $descriptor Path to image file, or array structure containing paths
         * @param string $basePath Directory to which paths in descriptor refer
         * @param array $variants
         * @param string|array $descriptor Path to image file, or array structure containing paths
         * @param string $basePath Directory to which paths in descriptor refer
         * @param array $variants
-        * @throws MWException
+        * @throws InvalidArgumentException
         */
        public function __construct( $name, $module, $descriptor, $basePath, $variants ) {
                $this->name = $name;
         */
        public function __construct( $name, $module, $descriptor, $basePath, $variants ) {
                $this->name = $name;
@@ -61,11 +61,11 @@ class ResourceLoaderImage {
                } );
                $extensions = array_unique( $extensions );
                if ( count( $extensions ) !== 1 ) {
                } );
                $extensions = array_unique( $extensions );
                if ( count( $extensions ) !== 1 ) {
-                       throw new MWException( "File type for different image files of '$name' not the same." );
+                       throw new InvalidArgumentException( "File type for different image files of '$name' not the same." );
                }
                $ext = $extensions[0];
                if ( !isset( self::$fileTypes[$ext] ) ) {
                }
                $ext = $extensions[0];
                if ( !isset( self::$fileTypes[$ext] ) ) {
-                       throw new MWException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." );
+                       throw new InvalidArgumentException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." );
                }
                $this->extension = $ext;
        }
                }
                $this->extension = $ext;
        }
index 28aebdf..88ba597 100644 (file)
@@ -85,7 +85,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
         *         ),
         *     )
         * @endcode
         *         ),
         *     )
         * @endcode
-        * @throws MWException
+        * @throws InvalidArgumentException
         */
        public function __construct( $options = array(), $localBasePath = null ) {
                $this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
         */
        public function __construct( $options = array(), $localBasePath = null ) {
                $this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
@@ -103,16 +103,16 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                $selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant'];
 
                if ( $selectorWithoutVariant && !$selectorWithVariant ) {
                $selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant'];
 
                if ( $selectorWithoutVariant && !$selectorWithVariant ) {
-                       throw new MWException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
+                       throw new InvalidArgumentException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
                }
                if ( $selectorWithVariant && !$selectorWithoutVariant ) {
                }
                if ( $selectorWithVariant && !$selectorWithoutVariant ) {
-                       throw new MWException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
+                       throw new InvalidArgumentException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
                }
                if ( $selector && $selectorWithVariant ) {
                }
                if ( $selector && $selectorWithVariant ) {
-                       throw new MWException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
+                       throw new InvalidArgumentException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
                }
                if ( !$prefix && !$selector && !$selectorWithVariant ) {
                }
                if ( !$prefix && !$selector && !$selectorWithVariant ) {
-                       throw new MWException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
+                       throw new InvalidArgumentException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
                }
 
                foreach ( $options as $member => $option ) {
                }
 
                foreach ( $options as $member => $option ) {
@@ -120,7 +120,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
                                case 'images':
                                case 'variants':
                                        if ( !is_array( $option ) ) {
                                case 'images':
                                case 'variants':
                                        if ( !is_array( $option ) ) {
-                                               throw new MWException(
+                                               throw new InvalidArgumentException(
                                                        "Invalid list error. '$option' given, array expected."
                                                );
                                        }
                                                        "Invalid list error. '$option' given, array expected."
                                                );
                                        }