From d741d0d962d3cd8a8c403c1508f8fed51846be2f Mon Sep 17 00:00:00 2001 From: Reedy Date: Fri, 25 May 2018 02:03:07 +0100 Subject: [PATCH] Split ApiUsageException and UsageException to class per file Change-Id: I54c7d5e6616ac1a23082cc72e60ed92cb7eef715 --- .phpcs.xml | 1 - autoload.php | 2 +- includes/api/ApiUsageException.php | 71 ----------------------- includes/api/UsageException.php | 90 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 includes/api/UsageException.php diff --git a/.phpcs.xml b/.phpcs.xml index e86855606d..bdfb12545e 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -72,7 +72,6 @@ Whitelist existing violations, but enable the sniff to prevent any new occurrences. --> - */includes/api/ApiUsageException\.php */includes/media/XCF\.php */includes/Feed\.php */includes/libs/xmp/XMP\.php diff --git a/autoload.php b/autoload.php index 6c484768f9..045045f685 100644 --- a/autoload.php +++ b/autoload.php @@ -1564,7 +1564,7 @@ $wgAutoloadLocalClasses = [ 'UploadStashWrongOwnerException' => __DIR__ . '/includes/upload/UploadStash.php', 'UploadStashZeroLengthFileException' => __DIR__ . '/includes/upload/UploadStash.php', 'UppercaseCollation' => __DIR__ . '/includes/collation/UppercaseCollation.php', - 'UsageException' => __DIR__ . '/includes/api/ApiUsageException.php', + 'UsageException' => __DIR__ . '/includes/api/UsageException.php', 'User' => __DIR__ . '/includes/user/User.php', 'UserArray' => __DIR__ . '/includes/user/UserArray.php', 'UserArrayFromResult' => __DIR__ . '/includes/user/UserArrayFromResult.php', diff --git a/includes/api/ApiUsageException.php b/includes/api/ApiUsageException.php index c200dcba6f..7f8a26b89a 100644 --- a/includes/api/ApiUsageException.php +++ b/includes/api/ApiUsageException.php @@ -18,77 +18,6 @@ * @file */ -/** - * This exception will be thrown when dieUsage is called to stop module execution. - * - * @ingroup API - * @deprecated since 1.29, use ApiUsageException instead - */ -class UsageException extends MWException { - - private $mCodestr; - - /** - * @var null|array - */ - private $mExtraData; - - /** - * @param string $message - * @param string $codestr - * @param int $code - * @param array|null $extradata - */ - public function __construct( $message, $codestr, $code = 0, $extradata = null ) { - parent::__construct( $message, $code ); - $this->mCodestr = $codestr; - $this->mExtraData = $extradata; - - if ( !$this instanceof ApiUsageException ) { - wfDeprecated( __METHOD__, '1.29' ); - } - - // This should never happen, so throw an exception about it that will - // hopefully get logged with a backtrace (T138585) - if ( !is_string( $codestr ) || $codestr === '' ) { - throw new InvalidArgumentException( 'Invalid $codestr, was ' . - ( $codestr === '' ? 'empty string' : gettype( $codestr ) ) - ); - } - } - - /** - * @return string - */ - public function getCodeString() { - wfDeprecated( __METHOD__, '1.29' ); - return $this->mCodestr; - } - - /** - * @return array - */ - public function getMessageArray() { - wfDeprecated( __METHOD__, '1.29' ); - $result = [ - 'code' => $this->mCodestr, - 'info' => $this->getMessage() - ]; - if ( is_array( $this->mExtraData ) ) { - $result = array_merge( $result, $this->mExtraData ); - } - - return $result; - } - - /** - * @return string - */ - public function __toString() { - return "{$this->getCodeString()}: {$this->getMessage()}"; - } -} - /** * Exception used to abort API execution with an error * diff --git a/includes/api/UsageException.php b/includes/api/UsageException.php new file mode 100644 index 0000000000..426ce91cef --- /dev/null +++ b/includes/api/UsageException.php @@ -0,0 +1,90 @@ +mCodestr = $codestr; + $this->mExtraData = $extradata; + + if ( !$this instanceof ApiUsageException ) { + wfDeprecated( __METHOD__, '1.29' ); + } + + // This should never happen, so throw an exception about it that will + // hopefully get logged with a backtrace (T138585) + if ( !is_string( $codestr ) || $codestr === '' ) { + throw new InvalidArgumentException( 'Invalid $codestr, was ' . + ( $codestr === '' ? 'empty string' : gettype( $codestr ) ) + ); + } + } + + /** + * @return string + */ + public function getCodeString() { + wfDeprecated( __METHOD__, '1.29' ); + return $this->mCodestr; + } + + /** + * @return array + */ + public function getMessageArray() { + wfDeprecated( __METHOD__, '1.29' ); + $result = [ + 'code' => $this->mCodestr, + 'info' => $this->getMessage() + ]; + if ( is_array( $this->mExtraData ) ) { + $result = array_merge( $result, $this->mExtraData ); + } + + return $result; + } + + /** + * @return string + */ + public function __toString() { + return "{$this->getCodeString()}: {$this->getMessage()}"; + } +} -- 2.20.1