Skip to content

Commit 9bb214a

Browse files
committed
Improve docblock and implementation of getIniKeyFromName
1 parent 3649bff commit 9bb214a

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

library/Icinga/Web/Form/ConfigForm.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ protected function populateFromConfig(): void
4949
{
5050
$populate = [];
5151
foreach ($this->getElements() as $element) {
52-
[$section, $key] = $this->getIniKeyFromName($element->getName());
53-
if ($section === null || $key === null) {
52+
if (($parts = $this->getIniKeyFromName($element->getName())) === null) {
5453
continue;
5554
}
55+
[$section, $key] = $parts;
5656
$value = $this->getPopulatedValue($element->getName()) ?? $this->config->get($section, $key);
5757
if ($value === null) {
5858
continue;
@@ -67,17 +67,13 @@ protected function populateFromConfig(): void
6767
*
6868
* @param string $name The element name
6969
*
70-
* @return string[]|null
70+
* @return array{string, string}|null
7171
*/
7272
protected function getIniKeyFromName(string $name): ?array
7373
{
7474
$parts = explode('__', $name, 2);
7575

76-
if (count($parts) !== 2) {
77-
return [null, null];
78-
}
79-
80-
return $parts;
76+
return count($parts) === 2 ? $parts : null;
8177
}
8278

8379
/**
@@ -90,10 +86,10 @@ protected function getIniKeyFromName(string $name): ?array
9086
*/
9187
public function getConfigValue(string $name, mixed $default = null): mixed
9288
{
93-
[$section, $key] = $this->getIniKeyFromName($name);
94-
if ($section === null || $key === null) {
89+
if (($parts = $this->getIniKeyFromName($name)) === null) {
9590
return $default;
9691
}
92+
[$section, $key] = $parts;
9793

9894
return $this->config->get($section, $key, $default);
9995
}
@@ -110,10 +106,10 @@ protected function save(): void
110106
if (in_array($element->getName(), $this->ignoredElements)) {
111107
continue;
112108
}
113-
[$section, $key] = $this->getIniKeyFromName($element->getName());
114-
if ($section === null || $key === null) {
109+
if (($parts = $this->getIniKeyFromName($element->getName())) === null) {
115110
continue;
116111
}
112+
[$section, $key] = $parts;
117113

118114
$value = $this->getPopulatedValue($element->getName());
119115
$configSection = $this->config->getSection($section);

library/Icinga/Web/Form/ConfigSectionForm.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ protected function addSectionNameElement(array $params = []): void
295295

296296
protected function getIniKeyFromName(string $name): ?array
297297
{
298+
if ($this->section === null) {
299+
return null;
300+
}
301+
298302
return [$this->section, $name];
299303
}
300304

0 commit comments

Comments
 (0)