Completed
Push — master ( 3a687e...f8fd11 )
by
unknown
18:01
created
apps/settings/lib/Command/AdminDelegation/Show.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -18,143 +18,143 @@
 block discarded – undo
18 18
 use Symfony\Component\Console\Style\SymfonyStyle;
19 19
 
20 20
 class Show extends Base {
21
-	public function __construct(
22
-		private IManager $settingManager,
23
-		private AuthorizedGroupService $authorizedGroupService,
24
-	) {
25
-		parent::__construct();
26
-	}
27
-
28
-	protected function configure(): void {
29
-		parent::configure();
30
-		$this
31
-			->setName('admin-delegation:show')
32
-			->setDescription('show delegated settings')
33
-		;
34
-	}
35
-
36
-	protected function execute(InputInterface $input, OutputInterface $output): int {
37
-		$io = new SymfonyStyle($input, $output);
38
-		$outputFormat = $input->getOption('output');
39
-
40
-		// Validate output format
41
-		if (!$this->validateOutputFormat($outputFormat)) {
42
-			$io->error("Invalid output format: {$outputFormat}. Valid formats are: plain, json, json_pretty");
43
-			return 1;
44
-		}
45
-
46
-		// Collect delegation data
47
-		$delegationData = $this->collectDelegationData();
48
-
49
-		// Handle empty results
50
-		if (empty($delegationData)) {
51
-			if ($outputFormat === self::OUTPUT_FORMAT_PLAIN) {
52
-				$io->info('No delegated settings found.');
53
-			} else {
54
-				$this->writeArrayInOutputFormat($input, $io, []);
55
-			}
56
-			return 0;
57
-		}
58
-
59
-		// Output based on format
60
-		switch ($outputFormat) {
61
-			case self::OUTPUT_FORMAT_JSON:
62
-			case self::OUTPUT_FORMAT_JSON_PRETTY:
63
-				$this->writeArrayInOutputFormat($input, $io, $delegationData);
64
-				break;
65
-			default:
66
-				$this->outputPlainFormat($io, $delegationData);
67
-				break;
68
-		}
69
-
70
-		return 0;
71
-	}
72
-
73
-	/**
74
-	 * Collect all delegation data in a structured format
75
-	 */
76
-	private function collectDelegationData(): array {
77
-		$result = [];
78
-		$sections = $this->settingManager->getAdminSections();
79
-
80
-		foreach ($sections as $sectionPriority) {
81
-			foreach ($sectionPriority as $section) {
82
-				$sectionSettings = $this->settingManager->getAdminSettings($section->getId());
83
-				$delegatedSettings = array_reduce($sectionSettings, [$this, 'getDelegatedSettings'], []);
84
-
85
-				if (empty($delegatedSettings)) {
86
-					continue;
87
-				}
88
-
89
-				$result[] = [
90
-					'id' => $section->getID(),
91
-					'name' => $section->getName() ?: $section->getID(),
92
-					'settings' => $this->formatSettingsData($delegatedSettings)
93
-				];
94
-			}
95
-		}
96
-
97
-		return $result;
98
-	}
99
-
100
-	/**
101
-	 * Format settings data for consistent output
102
-	 */
103
-	private function formatSettingsData(array $settings): array {
104
-		return array_map(function (IDelegatedSettings $setting) {
105
-			$className = get_class($setting);
106
-			$groups = array_map(
107
-				static fn (AuthorizedGroup $group) => $group->getGroupId(),
108
-				$this->authorizedGroupService->findExistingGroupsForClass($className)
109
-			);
110
-			natsort($groups);
111
-
112
-			return [
113
-				'name' => $setting->getName() ?: 'Global',
114
-				'className' => $className,
115
-				'delegatedGroups' => $groups,
116
-			];
117
-		}, $settings);
118
-	}
119
-
120
-	/**
121
-	 * Output data in plain table format
122
-	 */
123
-	private function outputPlainFormat(SymfonyStyle $io, array $data): void {
124
-		$io->title('Current delegations');
125
-		$headers = ['Name', 'SettingId', 'Delegated to groups'];
126
-
127
-		foreach ($data as $section) {
128
-			$io->section('Section: ' . $section['id']);
129
-
130
-			$tableData = array_map(static function (array $setting) {
131
-				return [
132
-					$setting['name'],
133
-					$setting['className'],
134
-					implode(', ', $setting['delegatedGroups']),
135
-				];
136
-			}, $section['settings']);
137
-
138
-			$io->table($headers, $tableData);
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Validate the output format parameter
144
-	 */
145
-	private function validateOutputFormat(string $format): bool {
146
-		return in_array($format, [
147
-			self::OUTPUT_FORMAT_PLAIN,
148
-			self::OUTPUT_FORMAT_JSON,
149
-			self::OUTPUT_FORMAT_JSON_PRETTY
150
-		], true);
151
-	}
152
-
153
-	/**
154
-	 * @param IDelegatedSettings[] $settings
155
-	 * @param array $innerSection
156
-	 */
157
-	private function getDelegatedSettings(array $settings, array $innerSection): array {
158
-		return $settings + array_filter($innerSection, fn (ISettings $setting) => $setting instanceof IDelegatedSettings);
159
-	}
21
+    public function __construct(
22
+        private IManager $settingManager,
23
+        private AuthorizedGroupService $authorizedGroupService,
24
+    ) {
25
+        parent::__construct();
26
+    }
27
+
28
+    protected function configure(): void {
29
+        parent::configure();
30
+        $this
31
+            ->setName('admin-delegation:show')
32
+            ->setDescription('show delegated settings')
33
+        ;
34
+    }
35
+
36
+    protected function execute(InputInterface $input, OutputInterface $output): int {
37
+        $io = new SymfonyStyle($input, $output);
38
+        $outputFormat = $input->getOption('output');
39
+
40
+        // Validate output format
41
+        if (!$this->validateOutputFormat($outputFormat)) {
42
+            $io->error("Invalid output format: {$outputFormat}. Valid formats are: plain, json, json_pretty");
43
+            return 1;
44
+        }
45
+
46
+        // Collect delegation data
47
+        $delegationData = $this->collectDelegationData();
48
+
49
+        // Handle empty results
50
+        if (empty($delegationData)) {
51
+            if ($outputFormat === self::OUTPUT_FORMAT_PLAIN) {
52
+                $io->info('No delegated settings found.');
53
+            } else {
54
+                $this->writeArrayInOutputFormat($input, $io, []);
55
+            }
56
+            return 0;
57
+        }
58
+
59
+        // Output based on format
60
+        switch ($outputFormat) {
61
+            case self::OUTPUT_FORMAT_JSON:
62
+            case self::OUTPUT_FORMAT_JSON_PRETTY:
63
+                $this->writeArrayInOutputFormat($input, $io, $delegationData);
64
+                break;
65
+            default:
66
+                $this->outputPlainFormat($io, $delegationData);
67
+                break;
68
+        }
69
+
70
+        return 0;
71
+    }
72
+
73
+    /**
74
+     * Collect all delegation data in a structured format
75
+     */
76
+    private function collectDelegationData(): array {
77
+        $result = [];
78
+        $sections = $this->settingManager->getAdminSections();
79
+
80
+        foreach ($sections as $sectionPriority) {
81
+            foreach ($sectionPriority as $section) {
82
+                $sectionSettings = $this->settingManager->getAdminSettings($section->getId());
83
+                $delegatedSettings = array_reduce($sectionSettings, [$this, 'getDelegatedSettings'], []);
84
+
85
+                if (empty($delegatedSettings)) {
86
+                    continue;
87
+                }
88
+
89
+                $result[] = [
90
+                    'id' => $section->getID(),
91
+                    'name' => $section->getName() ?: $section->getID(),
92
+                    'settings' => $this->formatSettingsData($delegatedSettings)
93
+                ];
94
+            }
95
+        }
96
+
97
+        return $result;
98
+    }
99
+
100
+    /**
101
+     * Format settings data for consistent output
102
+     */
103
+    private function formatSettingsData(array $settings): array {
104
+        return array_map(function (IDelegatedSettings $setting) {
105
+            $className = get_class($setting);
106
+            $groups = array_map(
107
+                static fn (AuthorizedGroup $group) => $group->getGroupId(),
108
+                $this->authorizedGroupService->findExistingGroupsForClass($className)
109
+            );
110
+            natsort($groups);
111
+
112
+            return [
113
+                'name' => $setting->getName() ?: 'Global',
114
+                'className' => $className,
115
+                'delegatedGroups' => $groups,
116
+            ];
117
+        }, $settings);
118
+    }
119
+
120
+    /**
121
+     * Output data in plain table format
122
+     */
123
+    private function outputPlainFormat(SymfonyStyle $io, array $data): void {
124
+        $io->title('Current delegations');
125
+        $headers = ['Name', 'SettingId', 'Delegated to groups'];
126
+
127
+        foreach ($data as $section) {
128
+            $io->section('Section: ' . $section['id']);
129
+
130
+            $tableData = array_map(static function (array $setting) {
131
+                return [
132
+                    $setting['name'],
133
+                    $setting['className'],
134
+                    implode(', ', $setting['delegatedGroups']),
135
+                ];
136
+            }, $section['settings']);
137
+
138
+            $io->table($headers, $tableData);
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Validate the output format parameter
144
+     */
145
+    private function validateOutputFormat(string $format): bool {
146
+        return in_array($format, [
147
+            self::OUTPUT_FORMAT_PLAIN,
148
+            self::OUTPUT_FORMAT_JSON,
149
+            self::OUTPUT_FORMAT_JSON_PRETTY
150
+        ], true);
151
+    }
152
+
153
+    /**
154
+     * @param IDelegatedSettings[] $settings
155
+     * @param array $innerSection
156
+     */
157
+    private function getDelegatedSettings(array $settings, array $innerSection): array {
158
+        return $settings + array_filter($innerSection, fn (ISettings $setting) => $setting instanceof IDelegatedSettings);
159
+    }
160 160
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 /**
5 5
  * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
6 6
  * SPDX-License-Identifier: AGPL-3.0-or-later
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * Format settings data for consistent output
102 102
 	 */
103 103
 	private function formatSettingsData(array $settings): array {
104
-		return array_map(function (IDelegatedSettings $setting) {
104
+		return array_map(function(IDelegatedSettings $setting) {
105 105
 			$className = get_class($setting);
106 106
 			$groups = array_map(
107 107
 				static fn (AuthorizedGroup $group) => $group->getGroupId(),
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 		$headers = ['Name', 'SettingId', 'Delegated to groups'];
126 126
 
127 127
 		foreach ($data as $section) {
128
-			$io->section('Section: ' . $section['id']);
128
+			$io->section('Section: '.$section['id']);
129 129
 
130
-			$tableData = array_map(static function (array $setting) {
130
+			$tableData = array_map(static function(array $setting) {
131 131
 				return [
132 132
 					$setting['name'],
133 133
 					$setting['className'],
Please login to merge, or discard this patch.