Completed
Push — master ( 1490ea...0e9aa3 )
by
unknown
27:23
created
apps/user_ldap/lib/Controller/WizardController.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -31,134 +31,134 @@
 block discarded – undo
31 31
 use Psr\Log\LoggerInterface;
32 32
 
33 33
 class WizardController extends OCSController {
34
-	public function __construct(
35
-		string $appName,
36
-		IRequest $request,
37
-		private LoggerInterface $logger,
38
-		private ConnectionFactory $connectionFactory,
39
-		private IL10N $l,
40
-		private WizardFactory $wizardFactory,
41
-		private IEventDispatcher $eventDispatcher,
42
-	) {
43
-		parent::__construct($appName, $request);
44
-	}
34
+    public function __construct(
35
+        string $appName,
36
+        IRequest $request,
37
+        private LoggerInterface $logger,
38
+        private ConnectionFactory $connectionFactory,
39
+        private IL10N $l,
40
+        private WizardFactory $wizardFactory,
41
+        private IEventDispatcher $eventDispatcher,
42
+    ) {
43
+        parent::__construct($appName, $request);
44
+    }
45 45
 
46
-	/**
47
-	 * Run a wizard action and returns the result
48
-	 *
49
-	 * @param string $configID ID of the LDAP configuration
50
-	 * @param string $wizardAction Wizard action to run
51
-	 * @param ?string $loginName Login name to test for testLoginName action
52
-	 * @return DataResponse<Http::STATUS_OK, array{changes:array<string,int|string|list<int>|list<string>>,options?:array<string,list<string>>}, array{}>
53
-	 * @throws OCSException
54
-	 *
55
-	 * 200: Wizard action result
56
-	 */
57
-	#[AuthorizedAdminSetting(settings: Admin::class)]
58
-	#[ApiRoute(verb: 'POST', url: '/api/v1/wizard/{configID}/{wizardAction}')]
59
-	public function action(
60
-		string $configID, string $wizardAction,
61
-		?string $loginName = null,
62
-	) {
63
-		try {
64
-			$wizard = $this->wizardFactory->get($configID);
65
-			switch ($wizardAction) {
66
-				case 'guessPortAndTLS':
67
-				case 'guessBaseDN':
68
-				case 'detectEmailAttribute':
69
-				case 'detectUserDisplayNameAttribute':
70
-				case 'determineGroupMemberAssoc':
71
-				case 'determineUserObjectClasses':
72
-				case 'determineGroupObjectClasses':
73
-				case 'determineGroupsForUsers':
74
-				case 'determineGroupsForGroups':
75
-				case 'determineAttributes':
76
-				case 'getUserListFilter':
77
-				case 'getUserLoginFilter':
78
-				case 'getGroupFilter':
79
-				case 'countUsers':
80
-				case 'countGroups':
81
-				case 'countInBaseDN':
82
-					try {
83
-						$result = $wizard->$wizardAction();
84
-						if ($result !== false) {
85
-							return new DataResponse($result->getResultArray());
86
-						}
87
-					} catch (\Exception $e) {
88
-						throw new OCSException($e->getMessage());
89
-					}
90
-					throw new OCSException();
46
+    /**
47
+     * Run a wizard action and returns the result
48
+     *
49
+     * @param string $configID ID of the LDAP configuration
50
+     * @param string $wizardAction Wizard action to run
51
+     * @param ?string $loginName Login name to test for testLoginName action
52
+     * @return DataResponse<Http::STATUS_OK, array{changes:array<string,int|string|list<int>|list<string>>,options?:array<string,list<string>>}, array{}>
53
+     * @throws OCSException
54
+     *
55
+     * 200: Wizard action result
56
+     */
57
+    #[AuthorizedAdminSetting(settings: Admin::class)]
58
+    #[ApiRoute(verb: 'POST', url: '/api/v1/wizard/{configID}/{wizardAction}')]
59
+    public function action(
60
+        string $configID, string $wizardAction,
61
+        ?string $loginName = null,
62
+    ) {
63
+        try {
64
+            $wizard = $this->wizardFactory->get($configID);
65
+            switch ($wizardAction) {
66
+                case 'guessPortAndTLS':
67
+                case 'guessBaseDN':
68
+                case 'detectEmailAttribute':
69
+                case 'detectUserDisplayNameAttribute':
70
+                case 'determineGroupMemberAssoc':
71
+                case 'determineUserObjectClasses':
72
+                case 'determineGroupObjectClasses':
73
+                case 'determineGroupsForUsers':
74
+                case 'determineGroupsForGroups':
75
+                case 'determineAttributes':
76
+                case 'getUserListFilter':
77
+                case 'getUserLoginFilter':
78
+                case 'getGroupFilter':
79
+                case 'countUsers':
80
+                case 'countGroups':
81
+                case 'countInBaseDN':
82
+                    try {
83
+                        $result = $wizard->$wizardAction();
84
+                        if ($result !== false) {
85
+                            return new DataResponse($result->getResultArray());
86
+                        }
87
+                    } catch (\Exception $e) {
88
+                        throw new OCSException($e->getMessage());
89
+                    }
90
+                    throw new OCSException();
91 91
 
92
-				case 'testLoginName':
93
-					try {
94
-						if ($loginName === null || $loginName === '') {
95
-							throw new OCSException('No login name passed');
96
-						}
97
-						$result = $wizard->$wizardAction($loginName);
98
-						if ($result !== false) {
99
-							return new DataResponse($result->getResultArray());
100
-						}
101
-					} catch (\Exception $e) {
102
-						throw new OCSException($e->getMessage());
103
-					}
104
-					throw new OCSException();
92
+                case 'testLoginName':
93
+                    try {
94
+                        if ($loginName === null || $loginName === '') {
95
+                            throw new OCSException('No login name passed');
96
+                        }
97
+                        $result = $wizard->$wizardAction($loginName);
98
+                        if ($result !== false) {
99
+                            return new DataResponse($result->getResultArray());
100
+                        }
101
+                    } catch (\Exception $e) {
102
+                        throw new OCSException($e->getMessage());
103
+                    }
104
+                    throw new OCSException();
105 105
 
106
-				default:
107
-					throw new OCSException('Action ' . $wizardAction . 'does not exist');
108
-					break;
109
-			}
110
-		} catch (OCSException $e) {
111
-			throw $e;
112
-		} catch (\Exception $e) {
113
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
114
-			throw new OCSException('An issue occurred.');
115
-		}
116
-	}
106
+                default:
107
+                    throw new OCSException('Action ' . $wizardAction . 'does not exist');
108
+                    break;
109
+            }
110
+        } catch (OCSException $e) {
111
+            throw $e;
112
+        } catch (\Exception $e) {
113
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
114
+            throw new OCSException('An issue occurred.');
115
+        }
116
+    }
117 117
 
118
-	/**
119
-	 * Clear user or group mappings
120
-	 *
121
-	 * @param 'user'|'group' $subject Whether to clear group or user mappings
122
-	 * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
123
-	 * @throws OCSException
124
-	 *
125
-	 * 200: Clearing was done successfuly
126
-	 */
127
-	#[AuthorizedAdminSetting(settings: Admin::class)]
128
-	#[ApiRoute(verb: 'POST', url: '/api/v1/wizard/clearMappings')]
129
-	public function clearMappings(
130
-		string $subject,
131
-	) {
132
-		$mapping = null;
133
-		try {
134
-			if ($subject === 'user') {
135
-				$mapping = Server::get(UserMapping::class);
136
-				$result = $mapping->clearCb(
137
-					function (string $uid): void {
138
-						$this->eventDispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
139
-						/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
140
-						Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
141
-					},
142
-					function (string $uid): void {
143
-						$this->eventDispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
144
-						/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
145
-						Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
146
-					}
147
-				);
148
-			} elseif ($subject === 'group') {
149
-				$mapping = Server::get(GroupMapping::class);
150
-				$result = $mapping->clear();
151
-			} else {
152
-				throw new OCSException('Unsupported subject ' . $subject);
153
-			}
118
+    /**
119
+     * Clear user or group mappings
120
+     *
121
+     * @param 'user'|'group' $subject Whether to clear group or user mappings
122
+     * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
123
+     * @throws OCSException
124
+     *
125
+     * 200: Clearing was done successfuly
126
+     */
127
+    #[AuthorizedAdminSetting(settings: Admin::class)]
128
+    #[ApiRoute(verb: 'POST', url: '/api/v1/wizard/clearMappings')]
129
+    public function clearMappings(
130
+        string $subject,
131
+    ) {
132
+        $mapping = null;
133
+        try {
134
+            if ($subject === 'user') {
135
+                $mapping = Server::get(UserMapping::class);
136
+                $result = $mapping->clearCb(
137
+                    function (string $uid): void {
138
+                        $this->eventDispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
139
+                        /** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
140
+                        Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
141
+                    },
142
+                    function (string $uid): void {
143
+                        $this->eventDispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
144
+                        /** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
145
+                        Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
146
+                    }
147
+                );
148
+            } elseif ($subject === 'group') {
149
+                $mapping = Server::get(GroupMapping::class);
150
+                $result = $mapping->clear();
151
+            } else {
152
+                throw new OCSException('Unsupported subject ' . $subject);
153
+            }
154 154
 
155
-			if (!$result) {
156
-				throw new OCSException($this->l->t('Failed to clear the mappings.'));
157
-			}
158
-			return new DataResponse();
159
-		} catch (\Exception $e) {
160
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
161
-			throw new OCSException('An issue occurred.');
162
-		}
163
-	}
155
+            if (!$result) {
156
+                throw new OCSException($this->l->t('Failed to clear the mappings.'));
157
+            }
158
+            return new DataResponse();
159
+        } catch (\Exception $e) {
160
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
161
+            throw new OCSException('An issue occurred.');
162
+        }
163
+    }
164 164
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 					throw new OCSException();
105 105
 
106 106
 				default:
107
-					throw new OCSException('Action ' . $wizardAction . 'does not exist');
107
+					throw new OCSException('Action '.$wizardAction.'does not exist');
108 108
 					break;
109 109
 			}
110 110
 		} catch (OCSException $e) {
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 			if ($subject === 'user') {
135 135
 				$mapping = Server::get(UserMapping::class);
136 136
 				$result = $mapping->clearCb(
137
-					function (string $uid): void {
137
+					function(string $uid): void {
138 138
 						$this->eventDispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
139 139
 						/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
140 140
 						Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
141 141
 					},
142
-					function (string $uid): void {
142
+					function(string $uid): void {
143 143
 						$this->eventDispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
144 144
 						/** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
145 145
 						Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 				$mapping = Server::get(GroupMapping::class);
150 150
 				$result = $mapping->clear();
151 151
 			} else {
152
-				throw new OCSException('Unsupported subject ' . $subject);
152
+				throw new OCSException('Unsupported subject '.$subject);
153 153
 			}
154 154
 
155 155
 			if (!$result) {
Please login to merge, or discard this patch.