Skip to content

Commit

Permalink
Update Settings object
Browse files Browse the repository at this point in the history
  • Loading branch information
tfirdaus committed Sep 29, 2024
1 parent 57e64dc commit 3fb5b84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(string $settingGroup, string $prefix = '')
$this->prefix = $prefix;
}

public function addSettings(SettingItem ...$settings): void
public function addSettings(Setting ...$settings): void
{
foreach ($settings as $key => $setting) {
$this->settings[$this->getPrefixedName($setting)] = $setting;
Expand Down
8 changes: 6 additions & 2 deletions app/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Syntatis\Utils\Val;
use Traversable;

use function is_array;

/** @phpstan-implements IteratorAggregate<string,Registry> */
class Settings implements IteratorAggregate
{
Expand Down Expand Up @@ -48,11 +50,13 @@ public function getAll(): array
$settings = [];

foreach ($this->registries as $group => $registry) {
if (! ($registry instanceof Registry)) {
$registeredSettings = $registry->getRegisteredSettings();

if (! is_array($registeredSettings) || Val::isBlank($registeredSettings)) {
continue;
}

$settings[$group] = $registry->getRegisteredSettings();
$settings[$group] = $registeredSettings;
}

return $settings;
Expand Down
15 changes: 8 additions & 7 deletions tests/app/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ public function testGetAfterRegisteredWithPrefix(): void

public function testGetAllBeforeRegistered(): void
{
$group1 = new Registry('group1');
$group1->addSettings(new Setting('say'), new Setting('hello'));

$group2 = new Registry('group2');
$group2->addSettings(new Setting('world'));

$settings = new Settings([
'group1' => (new Registry('group1'))->addSettings(
new Setting('say'),
new Setting('hello'),
),
'group2' => (new Registry('group2'))->addSettings(
new Setting('world'),
),
'group1' => $group1,
'group2' => $group2,
]);

$this->assertSame([], $settings->getAll());
Expand Down

0 comments on commit 3fb5b84

Please sign in to comment.