Add lots of @throws

Change-Id: I09d0c13070f966fcf23d2638d8fc1328279a5995
This commit is contained in:
Reedy 2014-12-24 13:49:20 +00:00
parent a3ce362ffd
commit 4d9143c7f5
48 changed files with 109 additions and 29 deletions

View file

@ -127,11 +127,12 @@ class Hooks {
* @param string|null $deprecatedVersion Optionally, mark hook as deprecated with version number
* @return bool True if no handler aborted the hook
*
* @throws Exception
* @throws FatalError
* @throws MWException
* @since 1.22 A hook function is not required to return a value for
* processing to continue. Not returning a value (or explicitly
* returning null) is equivalent to returning true.
* @throws MWException
* @throws FatalError
*/
public static function run( $event, array $args = array(), $deprecatedVersion = null ) {
$profiler = Profiler::instance();

View file

@ -322,6 +322,7 @@ class HtmlFormatter {
* @param string $type The type of selector (ID, CLASS, TAG_CLASS, or TAG)
* @param string $rawName The raw name of the selector
* @return bool Whether the selector was successfully recognised
* @throws MWException
*/
protected function parseSelector( $selector, &$type, &$rawName ) {
if ( strpos( $selector, '.' ) === 0 ) {

View file

@ -1626,6 +1626,7 @@ class OutputPage extends ContextSource {
* @param string $text
* @param bool $linestart Is this the start of a line?
* @param bool $interface Is this text in the user interface language?
* @throws MWException
*/
public function addWikiText( $text, $linestart = true, $interface = true ) {
$title = $this->getTitle(); // Work around E_STRICT

View file

@ -1045,6 +1045,7 @@ abstract class ApiBase extends ContextSource {
* @param string $token Supplied token
* @param array $params All supplied parameters for the module
* @return bool
* @throws MWException
*/
final public function validateToken( $token, array $params ) {
$tokenType = $this->needsToken();
@ -1294,6 +1295,7 @@ abstract class ApiBase extends ContextSource {
* @since 1.23
* @param Status $status
* @return array Array of code and error string
* @throws MWException
*/
public function getErrorFromStatus( $status ) {
if ( $status->isGood() ) {

View file

@ -458,6 +458,7 @@ class ApiMain extends ApiBase {
*
* @since 1.23
* @param Exception $e
* @throws Exception
*/
public static function handleApiBeforeMainException( Exception $e ) {
ob_start();
@ -778,6 +779,8 @@ class ApiMain extends ApiBase {
/**
* Set up the module for response
* @return ApiBase The module that will handle this action
* @throws MWException
* @throws UsageException
*/
protected function setupModule() {
// Instantiate the module requested by the user

View file

@ -340,6 +340,7 @@ class ApiOpenSearch extends ApiBase {
*
* @param string $type MIME type
* @return string
* @throws MWException
*/
public static function getOpenSearchTemplate( $type ) {
global $wgOpenSearchTemplate, $wgCanonicalServer;

View file

@ -518,6 +518,7 @@ class ApiResult extends ApiBase {
* @param ApiBase $module
* @param string $paramName
* @param string|array $paramValue
* @throws MWException
*/
public function setContinueParam( ApiBase $module, $paramName, $paramValue ) {
$name = $module->getModuleName();

View file

@ -654,6 +654,7 @@ class LocalisationCache {
* rules, and save the compiled rules in a process-local cache.
*
* @param string $fileName
* @throws MWException
*/
protected function loadPluralFile( $fileName ) {
// Use file_get_contents instead of DOMDocument::load (T58439)

View file

@ -60,6 +60,7 @@ abstract class BloomCache {
* It should only consist of alphanumberic, '-', and '_' characters.
* This ID is what avoids collisions if multiple logical caches
* use the same storage system, so this should be set carefully.
* @throws MWException
*/
public function __construct( array $config ) {
$this->cacheID = $config['cacheId'];

View file

@ -34,6 +34,7 @@ class EnhancedChangesList extends ChangesList {
/**
* @param IContextSource|Skin $obj
* @throws MWException
*/
public function __construct( $obj ) {
if ( $obj instanceof Skin ) {

View file

@ -58,6 +58,7 @@ abstract class CodeContentHandler extends TextContentHandler {
/**
* @return string
* @throws MWException
*/
protected function getContentClass() {
throw new MWException( 'Subclass must override' );

View file

@ -37,6 +37,7 @@ class TextContent extends AbstractContent {
/**
* @param string $text
* @param string $model_id
* @throws MWException
*/
public function __construct( $text, $model_id = CONTENT_MODEL_TEXT ) {
parent::__construct( $model_id );

View file

@ -297,8 +297,8 @@ class RequestContext implements IContextSource {
/**
* Get the Language object.
* Initialization of user or request objects can depend on this.
*
* @return Language
* @throws Exception
* @since 1.19
*/
public function getLanguage() {

View file

@ -3657,6 +3657,7 @@ abstract class DatabaseBase implements IDatabase {
* calling rollback when no transaction is in progress. This will silently
* break any ongoing explicit transaction. Only set the flush flag if you
* are sure that it is safe to ignore these warnings in your context.
* @throws DBUnexpectedError
* @since 1.23 Added $flush parameter
*/
final public function rollback( $fname = __METHOD__, $flush = '' ) {

View file

@ -380,6 +380,9 @@ class DatabaseMssql extends DatabaseBase {
* (optional) (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
* @return mixed Database result resource (feed to Database::fetchObject
* or whatever), or false on failure
* @throws DBQueryError
* @throws DBUnexpectedError
* @throws Exception
*/
public function select( $table, $vars, $conds = '', $fname = __METHOD__,
$options = array(), $join_conds = array()
@ -574,8 +577,8 @@ class DatabaseMssql extends DatabaseBase {
* @param array $arrToInsert
* @param string $fname
* @param array $options
* @throws DBQueryError
* @return bool
* @throws Exception
*/
public function insert( $table, $arrToInsert, $fname = __METHOD__, $options = array() ) {
# No rows to insert, easy just return now
@ -713,8 +716,8 @@ class DatabaseMssql extends DatabaseBase {
* @param string $fname
* @param array $insertOptions
* @param array $selectOptions
* @throws DBQueryError
* @return null|ResultWrapper
* @throws Exception
*/
public function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
$insertOptions = array(), $selectOptions = array()
@ -761,6 +764,9 @@ class DatabaseMssql extends DatabaseBase {
* - IGNORE: Ignore unique key conflicts
* - LOW_PRIORITY: MySQL-specific, see MySQL manual.
* @return bool
* @throws DBUnexpectedError
* @throws Exception
* @throws MWException
*/
function update( $table, $values, $conds, $fname = __METHOD__, $options = array() ) {
$table = $this->tableName( $table );
@ -893,6 +899,7 @@ class DatabaseMssql extends DatabaseBase {
* @param int $limit The SQL limit
* @param bool|int $offset The SQL offset (default false)
* @return array|string
* @throws DBUnexpectedError
*/
public function limitResult( $sql, $limit, $offset = false ) {
if ( $offset === false || $offset == 0 ) {

View file

@ -248,8 +248,8 @@ class ORMTable extends DBAccessBase implements IORMTable {
* @param array $options
* @param null|string $functionName
* @return ResultWrapper
* @throws DBQueryError If the query failed (even if the database was in
* ignoreErrors mode).
* @throws Exception
* @throws MWException
*/
public function rawSelect( $fields = null, array $conditions = array(),
array $options = array(), $functionName = null

View file

@ -126,6 +126,7 @@ abstract class HTMLFormField {
* @param array $alldata
* @param array $params
* @return bool
* @throws MWException
*/
protected function isHiddenRecurse( array $alldata, array $params ) {
$origParams = $params;

View file

@ -59,6 +59,7 @@ class MultiHttpClient {
* - reqTimeout : default request timeout
* - usePipelining : whether to use HTTP pipelining if possible (for all hosts)
* - maxConnsPerHost : maximum number of concurrent connections (per host)
* @throws Exception
*/
public function __construct( array $options ) {
if ( isset( $options['caBundlePath'] ) ) {
@ -103,14 +104,14 @@ class MultiHttpClient {
* Execute a set of HTTP(S) requests concurrently
*
* The maps are returned by this method with the 'response' field set to a map of:
* - code : HTTP response code or 0 if there was a serious cURL error
* - reason : HTTP response reason (empty if there was a serious cURL error)
* - headers : <header name/value associative array>
* - body : HTTP response body or resource (if "stream" was set)
* - code : HTTP response code or 0 if there was a serious cURL error
* - reason : HTTP response reason (empty if there was a serious cURL error)
* - headers : <header name/value associative array>
* - body : HTTP response body or resource (if "stream" was set)
* - error : Any cURL error string
* The map also stores integer-indexed copies of these values. This lets callers do:
* <code>
* list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $req['response'];
* The map also stores integer-indexed copies of these values. This lets callers do:
* <code>
* list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $req['response'];
* </code>
* All headers in the 'headers' field are normalized to use lower case names.
* This is true for the request headers and the response headers. Integer-indexed
@ -123,6 +124,7 @@ class MultiHttpClient {
* - usePipelining : whether to use HTTP pipelining if possible
* - maxConnsPerHost : maximum number of concurrent connections (per host)
* @return array $reqs With response array populated for each
* @throws Exception
*/
public function runMulti( array $reqs, array $opts = array() ) {
$chm = $this->getCurlMulti();
@ -244,6 +246,7 @@ class MultiHttpClient {
* - connTimeout : default connection timeout
* - reqTimeout : default request timeout
* @return resource
* @throws Exception
*/
protected function getCurlHandle( array &$req, array $opts = array() ) {
$ch = curl_init();

View file

@ -148,12 +148,13 @@ class VirtualRESTServiceClient {
* - body : HTTP response body or resource (if "stream" was set)
* - error : Any cURL error string
* The map also stores integer-indexed copies of these values. This lets callers do:
* <code>
* list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $responses[0];
* <code>
* list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $responses[0];
* </code>
*
* @param array $reqs Map of Virtual HTTP request maps
* @return array $reqs Map of corresponding response values with the same keys/order
* @throws Exception
*/
public function runMulti( array $reqs ) {
foreach ( $reqs as $index => &$req ) {

View file

@ -266,6 +266,7 @@ class DjVuHandler extends ImageHandler {
*
* @param File $file The DjVu file in question
* @return string XML metadata as a string.
* @throws MWException
*/
private function getUnserializedMetadata( File $file ) {
$metadata = $file->getMetadata();

View file

@ -70,6 +70,7 @@ class APCBagOStuff extends BagOStuff {
* @param mixed $value
* @param int $exptime
* @return bool
* @throws MWException
*/
public function cas( $casToken, $key, $value, $exptime = 0 ) {
// APC's CAS functions only work on integers

View file

@ -43,6 +43,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
* values, but serialization is much slower unless the php.ini option
* igbinary.compact_strings is off.
* @param array $params
* @throws MWException
*/
function __construct( $params ) {
$params = $this->applyDefaultParams( $params );

View file

@ -81,6 +81,7 @@ class MultiWriteBagOStuff extends BagOStuff {
* @param mixed $value
* @param mixed $exptime
* @return bool
* @throws MWException
*/
public function cas( $casToken, $key, $value, $exptime = 0 ) {
throw new MWException( "CAS is not implemented in " . __CLASS__ );

View file

@ -118,6 +118,7 @@ class SqlBagOStuff extends BagOStuff {
*
* @param int $serverIndex
* @return DatabaseBase
* @throws MWException
*/
protected function getDB( $serverIndex ) {
global $wgDebugDBTransactions;

View file

@ -74,6 +74,7 @@ class XCacheBagOStuff extends BagOStuff {
* @param mixed $value
* @param int $exptime
* @return bool
* @throws MWException
*/
public function cas( $casToken, $key, $value, $exptime = 0 ) {
// Can't find any documentation on xcache cas

View file

@ -164,7 +164,8 @@ class MWTidy {
* @param string $text HTML to check
* @param bool $stderr Whether to read result from STDERR rather than STDOUT
* @param int &$retval Exit code (-1 on internal error)
* @return string|null
* @return null|string
* @throws MWException
*/
private static function clean( $text, $stderr = false, &$retval = null ) {
global $wgTidyInternal;

View file

@ -68,6 +68,7 @@ class Preprocessor_DOM implements Preprocessor {
/**
* @param array $values
* @return PPNode_DOM
* @throws MWException
*/
public function newPartNodeArray( $values ) {
//NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)

View file

@ -277,6 +277,7 @@ class SectionProfiler {
/**
* Returns a tree of function calls with their real times
* @return string
* @throws Exception
*/
public function getCallTreeReport() {
if ( $this->collateOnly ) {

View file

@ -32,6 +32,7 @@ class ResourceLoaderEditToolbarModule extends ResourceLoaderFileModule {
*
* @param string $value
* @return string
* @throws Exception
*/
private static function cssSerializeString( $value ) {
if ( strstr( $value, "\0" ) ) {

View file

@ -483,8 +483,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
/**
* Get the skip function.
*
* @return string|null
* @return null|string
* @throws MWException
*/
public function getSkipFunction() {
if ( !$this->skipFunction ) {
@ -979,8 +979,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
/**
* Takes named templates by the module and returns an array mapping.
*
* @return array of templates mapping template alias to content
* @throws MWException
*/
public function getTemplates() {
$templates = array();

View file

@ -78,6 +78,7 @@ class RevisionDeleter {
* @param Title $title
* @param array $ids
* @return RevDelList
* @throws MWException
*/
public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) {
$typeName = self::getCanonicalTypeName( $typeName );

View file

@ -1046,6 +1046,7 @@ abstract class Skin extends ContextSource {
*
* @param string $name The name or path of a skin resource file
* @return string The fully resolved style path url including styleversion
* @throws MWException
*/
function getSkinStylePath( $name ) {
global $wgStylePath, $wgStyleVersion;

View file

@ -38,6 +38,9 @@ class EmailConfirmation extends UnlistedSpecialPage {
* Main execution point
*
* @param null|string $code Confirmation code passed to the page
* @throws PermissionsError
* @throws ReadOnlyError
* @throws UserNotLoggedIn
*/
function execute( $code ) {
$this->setHeaders();

View file

@ -52,6 +52,8 @@ class SpecialImport extends SpecialPage {
/**
* Execute
* @param string|null $par
* @throws PermissionsError
* @throws ReadOnlyError
*/
function execute( $par ) {
$this->setHeaders();

View file

@ -302,6 +302,7 @@ class ImageListPager extends TablePager {
* @param int $limit
* @param bool $asc
* @return array
* @throws MWException
*/
function reallyDoQuery( $offset, $limit, $asc ) {
$prevTableName = $this->mTableName;

View file

@ -306,6 +306,8 @@ class MediaStatisticsPage extends QueryPage {
*
* @param $skin Skin
* @param $result stdObject Result row
* @return bool|string|void
* @throws MWException
*/
public function formatResult( $skin, $result ) {
throw new MWException( "unimplemented" );

View file

@ -179,12 +179,12 @@ class SpecialRandomInCategory extends FormSpecialPage {
* @param float $rand Random number between 0 and 1
* @param int $offset Extra offset to fudge randomness
* @param bool $up True to get the result above the random number, false for below
*
* @return array Query information.
* @throws MWException
* @note The $up parameter is supposed to counteract what would happen if there
* was a large gap in the distribution of cl_timestamp values. This way instead
* of things to the right of the gap being favoured, both sides of the gap
* are favoured.
* @return array Query information.
*/
protected function getQueryInfo( $rand, $offset, $up ) {
$op = $up ? '>=' : '<=';

View file

@ -293,6 +293,8 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
* Show a deleted file version requested by the visitor.
* @todo Mostly copied from Special:Undelete. Refactor.
* @param string $archiveName
* @throws MWException
* @throws PermissionsError
*/
protected function tryShowFile( $archiveName ) {
$repo = RepoGroup::singleton()->getLocalRepo();

View file

@ -143,6 +143,13 @@ class SpecialUpload extends SpecialPage {
/**
* Special page entry point
* @param string $par
* @throws ErrorPageError
* @throws Exception
* @throws FatalError
* @throws MWException
* @throws PermissionsError
* @throws ReadOnlyError
* @throws UserBlockedError
*/
public function execute( $par ) {
$this->setHeaders();

View file

@ -1272,6 +1272,12 @@ class LoginForm extends SpecialPage {
/**
* @param string $msg
* @param string $msgtype
* @throws ErrorPageError
* @throws Exception
* @throws FatalError
* @throws MWException
* @throws PermissionsError
* @throws ReadOnlyError
* @private
*/
function mainLoginForm( $msg, $msgtype = 'error' ) {

View file

@ -63,6 +63,7 @@ class AutoloadGenerator {
*
* @param string $fqcn FQCN to force the location of
* @param string $inputPath Full path to the file containing the class
* @throws Exception
*/
public function forceClassPath( $fqcn, $inputPath ) {
$path = self::normalizePathSeparator( realpath( $inputPath ) );
@ -79,6 +80,7 @@ class AutoloadGenerator {
/**
* @param string $inputPath Path to a php file to find classes within
* @throws Exception
*/
public function readFile( $inputPath ) {
// NOTE: do NOT expand $inputPath using realpath(). It is perfectly

View file

@ -103,6 +103,7 @@ class MWCryptHKDF {
* @param string $algorithm Name of hashing algorithm
* @param BagOStuff $cache
* @param string|array $context Context to mix into HKDF context
* @throws MWException
*/
public function __construct( $secretKeyMaterial, $algorithm, $cache, $context ) {
if ( strlen( $secretKeyMaterial ) < 16 ) {
@ -157,6 +158,7 @@ class MWCryptHKDF {
/**
* Return a singleton instance, based on the global configs.
* @return HKDF
* @throws MWException
*/
protected static function singleton() {
global $wgHKDFAlgorithm, $wgHKDFSecret, $wgSecretKey;
@ -271,14 +273,15 @@ class MWCryptHKDF {
*
* @param string $hash Hashing Algorithm
* @param string $prk A pseudorandom key of at least HashLen octets
* (usually, the output from the extract step)
* (usually, the output from the extract step)
* @param string $info Optional context and application specific information
* (can be a zero-length string)
* (can be a zero-length string)
* @param int $bytes Length of output keying material in bytes
* (<= 255*HashLen)
* (<= 255*HashLen)
* @param string &$lastK Set by this function to the last block of the expansion.
* In MediaWiki, this is used to seed future Extractions.
* In MediaWiki, this is used to seed future Extractions.
* @return string Cryptographically secure random string $bytes long
* @throws MWException
*/
private static function HKDFExpand( $hash, $prk, $info, $bytes, &$lastK = '' ) {
$hashLen = MWCryptHKDF::$hashLength[$hash];

View file

@ -119,6 +119,7 @@ class UIDGenerator {
/**
* @param array $info (UIDGenerator::millitime(), counter, clock sequence)
* @return string 88 bits
* @throws MWException
*/
protected function getTimestampedID88( array $info ) {
list( $time, $counter ) = $info;
@ -163,6 +164,7 @@ class UIDGenerator {
/**
* @param array $info (UIDGenerator::millitime(), counter, clock sequence)
* @return string 128 bits
* @throws MWException
*/
protected function getTimestampedID128( array $info ) {
list( $time, $counter, $clkSeq ) = $info;
@ -260,6 +262,7 @@ class UIDGenerator {
* @param int $count Number of IDs to return (1 to 10000)
* @param int $flags (supports UIDGenerator::QUICK_VOLATILE)
* @return array Ordered list of float integer values
* @throws MWException
*/
protected function getSequentialPerNodeIDs( $bucket, $bits, $count, $flags ) {
if ( $count <= 0 ) {
@ -436,6 +439,7 @@ class UIDGenerator {
/**
* @param array $time Result of UIDGenerator::millitime()
* @return string 46 MSBs of "milliseconds since epoch" in binary (rolls over in 4201)
* @throws MWException
*/
protected function millisecondsSinceEpochBinary( array $time ) {
list( $sec, $msec ) = $time;

View file

@ -186,6 +186,7 @@ class ZipDirectoryReader {
* Throw an error, and log a debug message
* @param mixed $code
* @param string $debugMessage
* @throws ZipDirectoryReaderError
*/
function error( $code, $debugMessage ) {
wfDebug( __CLASS__ . ": Fatal error: $debugMessage\n" );

View file

@ -1493,8 +1493,10 @@ class ParserTest {
* Insert a temporary test article
* @param string $name The title, including any prefix
* @param string $text The article text
* @param int $line The input line number, for reporting errors
* @param bool $ignoreDuplicate Whether to silently ignore duplicate pages
* @param int|string $line The input line number, for reporting errors
* @param bool|string $ignoreDuplicate Whether to silently ignore duplicate pages
* @throws Exception
* @throws MWException
*/
public static function addArticle( $name, $text, $line = 'unknown', $ignoreDuplicate = '' ) {
global $wgCapitalLinks;

View file

@ -11,6 +11,7 @@ abstract class ApiFormatTestBase extends MediaWikiTestCase {
/**
* Return general data to be encoded for testing
* @return array See self::testGeneralEncoding
* @throws Exception
*/
public static function provideGeneralEncoding() {
throw new Exception( 'Subclass must implement ' . __METHOD__ );
@ -21,6 +22,8 @@ abstract class ApiFormatTestBase extends MediaWikiTestCase {
* @param array $params Query parameters
* @param array $data Data to encode
* @param string $class Printer class to use instead of the normal one
* @return string
* @throws Exception
*/
protected function encodeData( array $params, array $data, $class = null ) {
$context = new RequestContext;

View file

@ -49,8 +49,8 @@ abstract class PasswordTestCase extends MediaWikiTestCase {
* An array of tests in the form of (bool, string, string), where the first
* element is whether the second parameter (a password hash) and the third
* parameter (a password) should match.
*
* @return array
* @throws MWException
* @abstract
*/
public static function providePasswordTests() {

View file

@ -618,6 +618,7 @@ class TestFileIterator implements Iterator {
* @param bool $fatal True iff an exception should be thrown if
* the section is not found.
* @return bool|string
* @throws MWException
*/
private function checkSection( $tokens, $fatal = true ) {
if ( is_null( $this->section ) ) {
@ -691,6 +692,7 @@ class DelayedParserTest {
* Should be the case if we found the parserTest is not disabled
* @param ParserTest|NewParserTest $parserTest
* @return bool
* @throws MWException
*/
public function unleash( &$parserTest ) {
if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) {