Skip to content

Commit 10424a6

Browse files
author
Stanislav Idolov
authored
ENGCOM-2248: [Backport] Improve retrieval of first array element #16667
2 parents b5f47a1 + a62f333 commit 10424a6

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
@@ -46,13 +46,16 @@ public function __construct(
4646

4747
$this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
4848

49-
foreach (array_keys($this->getAttributeOption()) as $attr) {
50-
$this->setAttribute($attr);
51-
break;
49+
$attributes = $this->getAttributeOption();
50+
if ($attributes) {
51+
reset($attributes);
52+
$this->setAttribute(key($attributes));
5253
}
53-
foreach (array_keys($this->getOperatorOption()) as $operator) {
54-
$this->setOperator($operator);
55-
break;
54+
55+
$operators = $this->getOperatorOption();
56+
if ($operators) {
57+
reset($operators);
58+
$this->setOperator(key($operators));
5659
}
5760
}
5861

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public function __construct(Context $context, array $data = [])
4242
$this->loadAggregatorOptions();
4343
$options = $this->getAggregatorOptions();
4444
if ($options) {
45-
foreach (array_keys($options) as $aggregator) {
46-
$this->setAggregator($aggregator);
47-
break;
48-
}
45+
reset($options);
46+
$this->setAggregator(key($options));
4947
}
5048
}
5149

@@ -85,9 +83,10 @@ public function getAggregatorName()
8583
public function getAggregatorElement()
8684
{
8785
if ($this->getAggregator() === null) {
88-
foreach (array_keys($this->getAggregatorOption()) as $key) {
89-
$this->setAggregator($key);
90-
break;
86+
$options = $this->getAggregatorOption();
87+
if ($options) {
88+
reset($options);
89+
$this->setAggregator(key($options));
9190
}
9291
}
9392
return $this->getForm()->addField(

0 commit comments

Comments
 (0)