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:
thiemowmde 2024-04-08 13:48:33 +02:00 committed by Thiemo Kreuz (WMDE)
parent 221efa374b
commit db9c989e10
2 changed files with 12 additions and 13 deletions

View file

@ -30,27 +30,26 @@ class TemplateDataNormalizer {
$data->sets ??= [];
$data->maps ??= (object)[];
$data->format ??= null;
$data->params ??= (object)[];
$this->normaliseInterfaceText( $data->description );
foreach ( $data->sets as $setObj ) {
$this->normaliseInterfaceText( $setObj->label );
}
if ( isset( $data->params ) ) {
foreach ( $data->params as $param ) {
if ( isset( $param->inherits ) && isset( $data->params->{ $param->inherits } ) ) {
$parent = $data->params->{ $param->inherits };
foreach ( $parent as $key => $value ) {
if ( !isset( $param->$key ) ) {
$param->$key = is_object( $parent->$key ) ?
clone $parent->$key :
$parent->$key;
}
foreach ( $data->params as $param ) {
if ( isset( $param->inherits ) && isset( $data->params->{ $param->inherits } ) ) {
$parent = $data->params->{ $param->inherits };
foreach ( $parent as $key => $value ) {
if ( !isset( $param->$key ) ) {
$param->$key = is_object( $parent->$key ) ?
clone $parent->$key :
$parent->$key;
}
unset( $param->inherits );
}
$this->normalizeParameter( $param );
unset( $param->inherits );
}
$this->normalizeParameter( $param );
}
}

View file

@ -341,7 +341,7 @@ class TemplateDataValidator {
'array' );
}
if ( !count( $setObj->params ) ) {
if ( !$setObj->params ) {
return Status::newFatal( 'templatedata-invalid-empty-array',
"sets.{$setNr}.params" );
}