From db9c989e10e9c4e836129946b9df69705ffa7d7e Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Mon, 8 Apr 2024 13:48:33 +0200 Subject: [PATCH] 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 --- includes/TemplateDataNormalizer.php | 23 +++++++++++------------ includes/TemplateDataValidator.php | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/includes/TemplateDataNormalizer.php b/includes/TemplateDataNormalizer.php index 00fb912c..8627ea3b 100644 --- a/includes/TemplateDataNormalizer.php +++ b/includes/TemplateDataNormalizer.php @@ -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 ); } } diff --git a/includes/TemplateDataValidator.php b/includes/TemplateDataValidator.php index b1dec1a9..569b2b8a 100644 --- a/includes/TemplateDataValidator.php +++ b/includes/TemplateDataValidator.php @@ -341,7 +341,7 @@ class TemplateDataValidator { 'array' ); } - if ( !count( $setObj->params ) ) { + if ( !$setObj->params ) { return Status::newFatal( 'templatedata-invalid-empty-array', "sets.{$setNr}.params" ); }