Skip to content

Commit 668b413

Browse files
Kingdutchklausi
andauthored
fix(ui): Fix PHP warning for non-variables passed by reference (#1080)
* Fix notice about variables passed by reference `reset` only takes variables so we can not pass the result of `array_keys` directly but have to use an intermediate variable. * Merge variable fallback expressions `array_key_exists('schema', $input) ? $input['schema'] : NULL` is equal to `$input['schema'] ?? NULL` on PHP versions that support the null-coalescing operator. Since we already use this elsewhere we already require such PHP versions. This allows us to substitute the simplified one-use variable leading to `$input['schema'] ?? NULL ?? $server->get('schema')`. The expression `?? NULL ??` can be safely transformed to `??` to result in the simplified expression in this commit. Co-authored-by: Klaus Purer <[email protected]>
1 parent b235e07 commit 668b413

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Form/ServerForm.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ public function form(array $form, FormStateInterface $formState) {
9090
$schemas = array_map(function ($definition) {
9191
return $definition['name'] ?? $definition['id'];
9292
}, $this->schemaManager->getDefinitions());
93+
$schema_keys = array_keys($schemas);
9394

9495
$input = $formState->getUserInput();
95-
$inputSchema = array_key_exists('schema', $input) ? $input['schema'] : NULL;
96-
$schema = ($inputSchema ?? $server->get('schema')) ?: reset(array_keys($schemas));
96+
// Use the schema selected by the user, the one configured, or fall back to
97+
// the first schema that is defined.
98+
$schema = ($input['schema'] ?? $server->get('schema')) ?: reset($schema_keys);
9799

98100
if ($this->operation == 'add') {
99101
$form['#title'] = $this->t('Add server');

0 commit comments

Comments
 (0)