Skip to content

Commit 59bf243

Browse files
committed
improve retrieval of first elem
1 parent 38d7977 commit 59bf243

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

app/code/Magento/Rule/Model/Action/AbstractAction.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ public function __construct(
4949

5050
$this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
5151

52-
foreach (array_keys($this->getAttributeOption()) as $attr) {
53-
$this->setAttribute($attr);
54-
break;
52+
$attributes = $this->getAttributeOption();
53+
if ($attributes) {
54+
reset($attributes);
55+
$this->setAttribute(key($attributes));
5556
}
56-
foreach (array_keys($this->getOperatorOption()) as $operator) {
57-
$this->setOperator($operator);
58-
break;
57+
58+
$operators = $this->getOperatorOption();
59+
if ($operators) {
60+
reset($operators);
61+
$this->setOperator(key($operators));
5962
}
6063
}
6164

app/code/Magento/Rule/Model/Condition/Combine.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function __construct(Context $context, array $data = [])
4646
$this->loadAggregatorOptions();
4747
$options = $this->getAggregatorOptions();
4848
if ($options) {
49-
foreach (array_keys($options) as $aggregator) {
50-
$this->setAggregator($aggregator);
51-
break;
52-
}
49+
reset($options);
50+
$this->setAggregator(key($options));
5351
}
5452
}
5553

@@ -90,9 +88,10 @@ public function getAggregatorName()
9088
public function getAggregatorElement()
9189
{
9290
if ($this->getAggregator() === null) {
93-
foreach (array_keys($this->getAggregatorOption()) as $key) {
94-
$this->setAggregator($key);
95-
break;
91+
$options = $this->getAggregatorOption();
92+
if ($options) {
93+
reset($options);
94+
$this->setAggregator(key($options));
9695
}
9796
}
9897
return $this->getForm()->addField(

0 commit comments

Comments
 (0)