Skip to content

Commit

Permalink
replaced the array_walk function with foreach to boost performance
Browse files Browse the repository at this point in the history
  • Loading branch information
buttflattery committed Feb 2, 2020
1 parent 0b14016 commit 8b9365c
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/traits/WizardTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,15 @@ private function _sortFields($fieldConfig, &$attributes, $step)
$orderedAttributes = [];
$unorderedAttributes = [];

array_walk(
$attributes,
function (&$item, $index, $fieldOrder) use (
&$orderedAttributes,
&$unorderedAttributes
) {
$moveToIndex = array_search($item, $fieldOrder);

if ($moveToIndex !== false) {
$orderedAttributes[$moveToIndex] = $item;
} else {
$unorderedAttributes[] = $item;
}
},
$fieldOrder
);
foreach ($attributes as $item) {
$moveToIndex = array_search($item, $fieldOrder);

if ($moveToIndex !== false) {
$orderedAttributes[$moveToIndex] = $item;
continue;
}
$unorderedAttributes[] = $item;
}

//sort new order according to keys
ksort($orderedAttributes);
Expand Down Expand Up @@ -325,8 +318,8 @@ private function _createStepHtml($attributes, $modelIndex, $index, $model, $isTa

//if custom config available for field
if ($customConfigDefinedForField) {
$customFieldConfig=(isset($fieldConfig[$attributesPrefixed[$attributeIndex]]))?$fieldConfig[$attributesPrefixed[$attributeIndex]]:$fieldConfig[$attribute];

$customFieldConfig = (isset($fieldConfig[$attributesPrefixed[$attributeIndex]])) ? $fieldConfig[$attributesPrefixed[$attributeIndex]] : $fieldConfig[$attribute];

//if filtered field
$isFilteredField = $customFieldConfig === false;
Expand All @@ -336,7 +329,6 @@ private function _createStepHtml($attributes, $modelIndex, $index, $model, $isTa
continue;
}


//custom field population
$htmlFields .= $this->createCustomInput(
$model,
Expand Down

0 comments on commit 8b9365c

Please sign in to comment.