Skip to content

Commit

Permalink
refactor: set data structure for getLevels method return
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Apr 30, 2024
1 parent 553ef04 commit 48ba42b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/FormBuilder/BlockModels/DonationAmountBlockModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public function getLabel(): string
*/
public function getLevels(): array
{
return $this->block->getAttribute('levels');
return array_map(static function($level) {
return [
'label' => (string)filter_var($level['label'], FILTER_SANITIZE_STRING),
'value' => (float)filter_var($level['value'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION),
'checked' => (bool)filter_var($level['checked'], FILTER_VALIDATE_BOOLEAN),
];
}, $this->block->getAttribute('levels'));
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/FormBuilder/BlockTypes/DonationAmountBlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,20 @@ public static function name(): string
];

/**
* @unreleased Update levels array schema.
* @since 3.8.0
*
* @return float[]
*/
public function getLevels(): array
{
return array_map(static function ($level) {
return (float)filter_var($level, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}, $this->levels);
return array_map(static function($level) {
return [
'label' => (string)filter_var($level['label'], FILTER_SANITIZE_STRING),
'value' => (float)filter_var($level['value'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION),
'checked' => (bool)filter_var($level['checked'], FILTER_VALIDATE_BOOLEAN),
];
}, $this->block->getAttribute('levels'));
}

/**
Expand Down

0 comments on commit 48ba42b

Please sign in to comment.