Skip to content

Commit

Permalink
Refactor toArray method in Config class
Browse files Browse the repository at this point in the history
The method has been revised to first assign its output to a variable and checking if `settings` is not empty before merging its array output to the result. This ensures the data returned is correct even when `settings` is empty.
  • Loading branch information
Pavlusha311245 committed Apr 20, 2024
1 parent 51ac72a commit ed730bd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,19 @@ public function removeAccessLog(): bool
*/
#[Override] public function toArray(): array
{
return [
$data = [
'listeners' => $this->mapConfigObjectToArray($this->listeners),
'routes' => $this->mapConfigObjectToArray($this->routes),
'applications' => $this->mapConfigObjectToArray($this->applications),
'upstreams' => $this->mapConfigObjectToArray($this->upstreams),
'settings' => $this->settings->toArray()
'settings' => $this->settings?->toArray()
];

if (!empty($this->settings)) {
$data = array_merge($data, $this->settings->toArray());
}

return $data;
}

/**
Expand Down

0 comments on commit ed730bd

Please sign in to comment.