mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Simplify normalization of "params" key
The isset() check was odd and confusing. I think I added it in Ie572809 to be able to run the normalizer independend from the validator. But the "params" element is required anyway. It makes much more sense to enforce it in the normalizer as well. Even if this currently doesn't make a difference in real-world scenarios, it makes the code easier to read. Change-Id: If4eb2f3985c56146d74e760996ad983be12b921a
This commit is contained in:
parent
221efa374b
commit
db9c989e10
|
@ -30,27 +30,26 @@ class TemplateDataNormalizer {
|
||||||
$data->sets ??= [];
|
$data->sets ??= [];
|
||||||
$data->maps ??= (object)[];
|
$data->maps ??= (object)[];
|
||||||
$data->format ??= null;
|
$data->format ??= null;
|
||||||
|
$data->params ??= (object)[];
|
||||||
|
|
||||||
$this->normaliseInterfaceText( $data->description );
|
$this->normaliseInterfaceText( $data->description );
|
||||||
foreach ( $data->sets as $setObj ) {
|
foreach ( $data->sets as $setObj ) {
|
||||||
$this->normaliseInterfaceText( $setObj->label );
|
$this->normaliseInterfaceText( $setObj->label );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $data->params ) ) {
|
foreach ( $data->params as $param ) {
|
||||||
foreach ( $data->params as $param ) {
|
if ( isset( $param->inherits ) && isset( $data->params->{ $param->inherits } ) ) {
|
||||||
if ( isset( $param->inherits ) && isset( $data->params->{ $param->inherits } ) ) {
|
$parent = $data->params->{ $param->inherits };
|
||||||
$parent = $data->params->{ $param->inherits };
|
foreach ( $parent as $key => $value ) {
|
||||||
foreach ( $parent as $key => $value ) {
|
if ( !isset( $param->$key ) ) {
|
||||||
if ( !isset( $param->$key ) ) {
|
$param->$key = is_object( $parent->$key ) ?
|
||||||
$param->$key = is_object( $parent->$key ) ?
|
clone $parent->$key :
|
||||||
clone $parent->$key :
|
$parent->$key;
|
||||||
$parent->$key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unset( $param->inherits );
|
|
||||||
}
|
}
|
||||||
$this->normalizeParameter( $param );
|
unset( $param->inherits );
|
||||||
}
|
}
|
||||||
|
$this->normalizeParameter( $param );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ class TemplateDataValidator {
|
||||||
'array' );
|
'array' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !count( $setObj->params ) ) {
|
if ( !$setObj->params ) {
|
||||||
return Status::newFatal( 'templatedata-invalid-empty-array',
|
return Status::newFatal( 'templatedata-invalid-empty-array',
|
||||||
"sets.{$setNr}.params" );
|
"sets.{$setNr}.params" );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue