Skip to content

Commit be66793

Browse files
committed
Fix 2: Review comments
1 parent 836d43b commit be66793

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

application/controllers/EventRuleController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ public function indexAction(): void
134134
$buttonsWrapper->add([$eventRuleConfigSubmitButton, $discardChangesButton, $deleteButton]);
135135

136136
if ($ruleId > 0) {
137-
$incidents = Incident::on(Database::get())
137+
$incidentCount = Incident::on(Database::get())
138138
->with('rule')
139-
->filter(Filter::equal('rule.id', $ruleId));
139+
->filter(Filter::equal('rule.id', $ruleId))
140+
->count();
140141

141-
if ($incidents->count() > 0) {
142+
if ($incidentCount) {
142143
$deleteButton->addAttributes([
143144
'disabled' => true,
144145
'title' => t('There exist active incidents for this escalation and hence cannot be removed')

application/forms/EventRuleConfigElements/EscalationRecipient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ protected function assemble(): void
4646
$this->getElement('recipient-count')->setValue(++$recipientCount);
4747
}
4848

49+
$defaultOption = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
4950
$removePosition = null;
51+
5052
foreach (range(1, $recipientCount) as $i) {
5153
$this->addElement('hidden', 'id_' . $i);
5254

@@ -55,9 +57,7 @@ protected function assemble(): void
5557
'column_' . $i,
5658
[
5759
'class' => ['autosubmit', 'left-operand'],
58-
'options' => [
59-
'' => sprintf(' - %s - ', $this->translate('Please choose'))
60-
] + $this->fetchOptions(),
60+
'options' => $defaultOption + $this->fetchOptions(),
6161
'disabledOptions' => [''],
6262
'required' => true,
6363
'value' => $this->getPopulatedValue('column_' . $i)
@@ -66,8 +66,7 @@ protected function assemble(): void
6666

6767
$this->registerElement($col);
6868

69-
$options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
70-
$options += Channel::fetchChannelNames(Database::get());
69+
$options = $defaultOption + Channel::fetchChannelNames(Database::get());
7170

7271
$val = $this->createElement(
7372
'select',

application/forms/EventRuleConfigForm.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ public function populate($values): self
270270
foreach ($values['rule_escalation'] as $position => $escalation) {
271271
$conditions = explode('|', $escalation['condition'] ?? '');
272272
$conditionFormValues = [];
273-
$conditionCount = count($conditions);
274-
$conditionFormValues['condition-count'] = $conditionCount;
273+
$conditionFormValues['condition-count'] = count($conditions);
275274
$conditionFormValues['id'] = $escalation['id'] ?? bin2hex(random_bytes(4));
276275

277276
foreach ($conditions as $key => $condition) {
@@ -381,11 +380,12 @@ protected function createRemoveButton(string $prefix): SubmitButtonElement
381380
$escalationId = $escalations[$pos]['id'] ?? null;
382381

383382
if ($escalationId && ctype_digit($escalationId)) {
384-
$incident = Incident::on(Database::get())->with('rule_escalation');
385-
$incident->filter(Filter::equal('rule_escalation.id', $escalationId));
386-
if ($incident->count() > 0) {
387-
$disableRemoveButton = true;
388-
}
383+
$incidentCount = Incident::on(Database::get())
384+
->with('rule_escalation')
385+
->filter(Filter::equal('rule_escalation.id', $escalationId))
386+
->count();
387+
388+
$disableRemoveButton = $incidentCount > 0;
389389
}
390390

391391
$button = new SubmitButtonElement(
@@ -639,7 +639,7 @@ protected function getPrefixesMap(int $escalationCount): string
639639
{
640640
$prefixesMap = [];
641641
for ($i = 1; $i <= $escalationCount; $i++) {
642-
$prefixesMap[(string) $i] = bin2hex((string) $i);
642+
$prefixesMap[] = bin2hex((string) $i);
643643
}
644644

645645
return implode(',', $prefixesMap);

0 commit comments

Comments
 (0)