Make ApiCreateAccount return camelcase statuses
[lhc/web/wiklou.git] / includes / api / ApiResult.php
index 7ecfa8e..e922020 100644 (file)
@@ -26,9 +26,9 @@
 
 /**
  * This class represents the result of the API operations.
- * It simply wraps a nested array() structure, adding some functions to simplify array's modifications.
- * As various modules execute, they add different pieces of information to this result,
- * structuring it as it will be given to the client.
+ * It simply wraps a nested array() structure, adding some functions to simplify
+ * array's modifications. As various modules execute, they add different pieces
+ * of information to this result, structuring it as it will be given to the client.
  *
  * Each subarray may either be a dictionary - key-value pairs with unique keys,
  * or lists, where the items are added using $data[] = $value notation.
@@ -36,8 +36,8 @@
  * There are two special key values that change how XML output is generated:
  *   '_element' This key sets the tag name for the rest of the elements in the current array.
  *              It is only inserted if the formatter returned true for getNeedsRawData()
- *   '*'        This key has special meaning only to the XML formatter, and is outputed as is
- *                             for all others. In XML it becomes the content of the current element.
+ *   '*'        This key has special meaning only to the XML formatter, and is outputted as is
+ *              for all others. In XML it becomes the content of the current element.
  *
  * @ingroup API
  */
@@ -117,6 +117,7 @@ class ApiResult extends ApiBase {
                        // Objects can't always be cast to string
                        $s = strlen( $value );
                }
+
                return $s;
        }
 
@@ -147,17 +148,20 @@ class ApiResult extends ApiBase {
        /**
         * Add an output value to the array by name.
         * Verifies that value with the same name has not been added before.
-        * @param $arr array to add $value to
-        * @param $name string Index of $arr to add $value at
+        * @param array $arr to add $value to
+        * @param string $name Index of $arr to add $value at
         * @param $value mixed
-        * @param $flags int Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This parameter used to be
-        *        boolean, and the value of OVERRIDE=1 was specifically chosen so that it would be backwards
-        *        compatible with the new method signature.
+        * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.
+        *    This parameter used to be boolean, and the value of OVERRIDE=1 was
+        *    specifically chosen so that it would be backwards compatible with the
+        *    new method signature.
         *
         * @since 1.21 int $flags replaced boolean $override
         */
        public static function setElement( &$arr, $name, $value, $flags = 0 ) {
-               if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) {
+               if ( $arr === null || $name === null || $value === null
+                       || !is_array( $arr ) || is_array( $name )
+               ) {
                        ApiBase::dieDebug( __METHOD__, 'Bad parameter' );
                }
 
@@ -176,16 +180,19 @@ class ApiResult extends ApiBase {
                                ApiBase::dieDebug( __METHOD__, "Attempting to merge element $name" );
                        }
                } else {
-                       ApiBase::dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" );
+                       ApiBase::dieDebug(
+                               __METHOD__,
+                               "Attempting to add element $name=$value, existing value is {$arr[$name]}"
+                       );
                }
        }
 
        /**
         * Adds a content element to an array.
         * Use this function instead of hardcoding the '*' element.
-        * @param $arr array to add the content element to
+        * @param array $arr to add the content element to
         * @param $value Mixed
-        * @param $subElemName string when present, content element is created
+        * @param string $subElemName when present, content element is created
         *  as a sub item of $arr. Use this parameter to create elements in
         *  format "<elem>text</elem>" without attributes.
         */
@@ -208,7 +215,7 @@ class ApiResult extends ApiBase {
         * give all indexed values the given tag name. This function MUST be
         * called on every array that has numerical indexes.
         * @param $arr array
-        * @param $tag string Tag name
+        * @param string $tag Tag name
         */
        public function setIndexedTagName( &$arr, $tag ) {
                // In raw mode, add the '_element', otherwise just ignore
@@ -225,7 +232,7 @@ class ApiResult extends ApiBase {
        /**
         * Calls setIndexedTagName() on each sub-array of $arr
         * @param $arr array
-        * @param $tag string Tag name
+        * @param string $tag Tag name
         */
        public function setIndexedTagName_recursive( &$arr, $tag ) {
                if ( !is_array( $arr ) ) {
@@ -244,7 +251,7 @@ class ApiResult extends ApiBase {
         * Calls setIndexedTagName() on an array already in the result.
         * Don't specify a path to a value that's not in the result, or
         * you'll get nasty errors.
-        * @param $path array Path to the array, like addValue()'s $path
+        * @param array $path Path to the array, like addValue()'s $path
         * @param $tag string
         */
        public function setIndexedTagName_internal( $path, $tag ) {
@@ -271,9 +278,10 @@ class ApiResult extends ApiBase {
         * @param $path array|string|null
         * @param $name string
         * @param $value mixed
-        * @param $flags int Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This parameter used to be
-        *        boolean, and the value of OVERRIDE=1 was specifically chosen so that it would be backwards
-        *        compatible with the new method signature.
+        * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This
+        *    parameter used to be boolean, and the value of OVERRIDE=1 was specifically
+        *    chosen so that it would be backwards compatible with the new method
+        *    signature.
         * @return bool True if $value fits in the result, false if not
         *
         * @since 1.21 int $flags replaced boolean $override
@@ -287,7 +295,8 @@ class ApiResult extends ApiBase {
                        if ( $newsize > $wgAPIMaxResultSize ) {
                                $this->setWarning(
                                        "This result was truncated because it would otherwise be larger than the " .
-                                                       "limit of {$wgAPIMaxResultSize} bytes" );
+                                               "limit of {$wgAPIMaxResultSize} bytes" );
+
                                return false;
                        }
                        $this->mSize = $newsize;
@@ -295,7 +304,7 @@ class ApiResult extends ApiBase {
 
                $addOnTop = $flags & ApiResult::ADD_ON_TOP;
                if ( $path !== null ) {
-                       foreach ( (array) $path as $p ) {
+                       foreach ( (array)$path as $p ) {
                                if ( !isset( $data[$p] ) ) {
                                        if ( $addOnTop ) {
                                                $data = array( $p => array() ) + $data;
@@ -322,6 +331,7 @@ class ApiResult extends ApiBase {
                        // Add named element
                        self::setElement( $data, $name, $value, $flags );
                }
+
                return true;
        }
 
@@ -340,12 +350,12 @@ class ApiResult extends ApiBase {
         * Unset a value previously added to the result set.
         * Fails silently if the value isn't found.
         * For parameters, see addValue()
-        * @param $path array
+        * @param $path array|null
         * @param $name string
         */
        public function unsetValue( $path, $name ) {
                $data = &$this->mData;
-               if ( !is_null( $path ) ) {
+               if ( $path !== null ) {
                        foreach ( (array)$path as $p ) {
                                if ( !isset( $data[$p] ) ) {
                                        return;
@@ -394,6 +404,7 @@ class ApiResult extends ApiBase {
                        $result[] = $error;
                }
                $this->setIndexedTagName( $result, $errorType );
+
                return $result;
        }