Simplify ApiCategoryTree::extractOptions

Change-Id: I98605b2580a995e37a8da1b88693b38bbd5b8013
This commit is contained in:
Umherirrender 2023-04-25 20:06:08 +02:00
parent 9be6563cfa
commit 3252ddc115

View file

@ -98,28 +98,16 @@ class ApiCategoryTree extends ApiBase {
$this->dieWithError( 'apierror-categorytree-invalidjson', 'invalidjson' );
}
$namespaces = $options->namespaces ?? null;
if ( $namespaces !== null ) {
if ( !is_scalar( $namespaces ) && !is_array( $namespaces ) ) {
$this->dieWithError(
[ 'apierror-categorytree-invalidjson-option', 'namespaces' ], 'invalidjson-option'
);
}
// Don't recheck this in the loop below
unset( $options->namespaces );
}
foreach ( $options as $option => $value ) {
if ( !is_scalar( $value ) && $value !== null ) {
$this->dieWithError(
[ 'apierror-categorytree-invalidjson-option', $option ], 'invalidjson-option'
);
if ( is_scalar( $value ) || $value === null ) {
continue;
}
}
if ( $namespaces ) {
$options->namespaces = $namespaces;
if ( $option === 'namespaces' && is_array( $value ) ) {
continue;
}
$this->dieWithError(
[ 'apierror-categorytree-invalidjson-option', $option ], 'invalidjson-option'
);
}
return get_object_vars( $options );