Skip to content

Commit bf78812

Browse files
Cleanup json data generation
1 parent 5c837a1 commit bf78812

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/Config.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,27 +396,41 @@ public function getPlugins(): array
396396
*/
397397
public function getJsonData(): array
398398
{
399-
$data = [];
400-
if (!empty($this->settings)) {
401-
$data['config'] = $this->settings;
399+
$data = [];
400+
$config = $this->getConfigJsonData();
401+
402+
if (!empty($config)) {
403+
$data['config'] = $config;
402404
}
403405

406+
foreach (Hooks::getValidHooks() as $hook => $value) {
407+
if ($this->hooks[$hook]->isEnabled() || $this->hooks[$hook]->hasActions()) {
408+
$data[$hook] = $this->hooks[$hook]->getJsonData();
409+
}
410+
}
411+
return $data;
412+
}
413+
414+
/**
415+
* Build the "config" JSON section of the configuration file
416+
*
417+
* @return array<string, mixed>
418+
*/
419+
private function getConfigJsonData(): array
420+
{
421+
$config = !empty($this->settings) ? $this->settings : [];
422+
404423
$runConfigData = $this->runConfig->getJsonData();
405424
if (!empty($runConfigData)) {
406-
$data['config']['run'] = $runConfigData;
425+
$config['run'] = $runConfigData;
407426
}
408427
if (!empty($this->plugins)) {
409-
$data['config']['plugins'] = $this->getPluginsJsonData();
428+
$config['plugins'] = $this->getPluginsJsonData();
410429
}
411430
if (!empty($this->custom)) {
412-
$data['config']['custom'] = $this->custom;
431+
$config['custom'] = $this->custom;
413432
}
414-
foreach (Hooks::getValidHooks() as $hook => $value) {
415-
if ($this->hooks[$hook]->isEnabled() || $this->hooks[$hook]->hasActions()) {
416-
$data[$hook] = $this->hooks[$hook]->getJsonData();
417-
}
418-
}
419-
return $data;
433+
return $config;
420434
}
421435

422436
/**

0 commit comments

Comments
 (0)