88
99namespace OCA \User_LDAP ;
1010
11+ use LDAP \Connection ;
1112use OCA \User_LDAP \User \DeletedUsersIndex ;
1213use OCP \GroupInterface ;
1314use OCP \IGroupManager ;
@@ -64,7 +65,7 @@ public function __construct(
6465 * @return string with the LDAP DN
6566 * @throws \Exception if translation was unsuccessful
6667 */
67- public function getUserDN ($ uid ) {
68+ public function getUserDN (string $ uid ): string {
6869 if (!$ this ->userBackend ->userExists ($ uid )) {
6970 throw new \Exception ('User id not found in LDAP ' );
7071 }
@@ -77,11 +78,9 @@ public function getUserDN($uid) {
7778
7879 /**
7980 * Translate a group id to LDAP DN.
80- * @param string $gid group id
81- * @return string
8281 * @throws \Exception
8382 */
84- public function getGroupDN ($ gid ) {
83+ public function getGroupDN (string $ gid ): string {
8584 if (!$ this ->groupBackend ->groupExists ($ gid )) {
8685 throw new \Exception ('Group id not found in LDAP ' );
8786 }
@@ -95,11 +94,10 @@ public function getGroupDN($gid) {
9594 /**
9695 * Translate a LDAP DN to an internal user name. If there is no mapping between
9796 * the DN and the user name, a new one will be created.
98- * @param string $dn LDAP DN
99- * @return string with the internal user name
97+ * @return string the internal user name
10098 * @throws \Exception if translation was unsuccessful
10199 */
102- public function getUserName ($ dn ) {
100+ public function getUserName (string $ dn ): string {
103101 $ result = $ this ->userBackend ->dn2UserName ($ dn );
104102 if (!$ result ) {
105103 throw new \Exception ('Translation to internal user name unsuccessful ' );
@@ -109,30 +107,24 @@ public function getUserName($dn) {
109107
110108 /**
111109 * Convert a stored DN so it can be used as base parameter for LDAP queries.
112- * @param string $dn the DN in question
113- * @return string
114110 */
115- public function DNasBaseParameter ($ dn ) {
111+ public function DNasBaseParameter (string $ dn ): string {
116112 return $ this ->helper ->DNasBaseParameter ($ dn );
117113 }
118114
119115 /**
120116 * Sanitize a DN received from the LDAP server.
121- * @param array|string $dn the DN in question
122- * @return array|string the sanitized DN
123117 */
124- public function sanitizeDN ($ dn ) {
118+ public function sanitizeDN (array | string $ dn ): array | string {
125119 return $ this ->helper ->sanitizeDN ($ dn );
126120 }
127121
128122 /**
129123 * Return a new LDAP connection resource for the specified user.
130124 * The connection must be closed manually.
131- * @param string $uid user id
132- * @return \LDAP\Connection The LDAP connection
133125 * @throws \Exception if user id was not found in LDAP
134126 */
135- public function getLDAPConnection ($ uid ) {
127+ public function getLDAPConnection (string $ uid ): Connection {
136128 if (!$ this ->userBackend ->userExists ($ uid )) {
137129 throw new \Exception ('User id not found in LDAP ' );
138130 }
@@ -142,11 +134,9 @@ public function getLDAPConnection($uid) {
142134 /**
143135 * Return a new LDAP connection resource for the specified user.
144136 * The connection must be closed manually.
145- * @param string $gid group id
146- * @return \LDAP\Connection The LDAP connection
147137 * @throws \Exception if group id was not found in LDAP
148138 */
149- public function getGroupLDAPConnection ($ gid ) {
139+ public function getGroupLDAPConnection (string $ gid ): Connection {
150140 if (!$ this ->groupBackend ->groupExists ($ gid )) {
151141 throw new \Exception ('Group id not found in LDAP ' );
152142 }
@@ -155,11 +145,9 @@ public function getGroupLDAPConnection($gid) {
155145
156146 /**
157147 * Get the LDAP base for users.
158- * @param string $uid user id
159- * @return string the base for users
160148 * @throws \Exception if user id was not found in LDAP
161149 */
162- public function getLDAPBaseUsers ($ uid ) {
150+ public function getLDAPBaseUsers (string $ uid ): string {
163151 if (!$ this ->userBackend ->userExists ($ uid )) {
164152 throw new \Exception ('User id not found in LDAP ' );
165153 }
@@ -185,11 +173,9 @@ public function getLDAPBaseUsers($uid) {
185173
186174 /**
187175 * Get the LDAP base for groups.
188- * @param string $uid user id
189- * @return string the base for groups
190176 * @throws \Exception if user id was not found in LDAP
191177 */
192- public function getLDAPBaseGroups ($ uid ) {
178+ public function getLDAPBaseGroups (string $ uid ): string {
193179 if (!$ this ->userBackend ->userExists ($ uid )) {
194180 throw new \Exception ('User id not found in LDAP ' );
195181 }
@@ -199,10 +185,9 @@ public function getLDAPBaseGroups($uid) {
199185
200186 /**
201187 * Clear the cache if a cache is used, otherwise do nothing.
202- * @param string $uid user id
203188 * @throws \Exception if user id was not found in LDAP
204189 */
205- public function clearCache ($ uid ) {
190+ public function clearCache (string $ uid ): void {
206191 if (!$ this ->userBackend ->userExists ($ uid )) {
207192 throw new \Exception ('User id not found in LDAP ' );
208193 }
@@ -212,10 +197,9 @@ public function clearCache($uid) {
212197 /**
213198 * Clear the cache if a cache is used, otherwise do nothing.
214199 * Acts on the LDAP connection of a group
215- * @param string $gid group id
216200 * @throws \Exception if user id was not found in LDAP
217201 */
218- public function clearGroupCache ($ gid ) {
202+ public function clearGroupCache (string $ gid ): void {
219203 if (!$ this ->groupBackend ->groupExists ($ gid )) {
220204 throw new \Exception ('Group id not found in LDAP ' );
221205 }
@@ -224,37 +208,31 @@ public function clearGroupCache($gid) {
224208
225209 /**
226210 * Check whether a LDAP DN exists
227- * @param string $dn LDAP DN
228- * @return bool whether the DN exists
229211 */
230- public function dnExists ($ dn ) {
212+ public function dnExists (string $ dn ): bool {
231213 $ result = $ this ->userBackend ->dn2UserName ($ dn );
232214 return !$ result ? false : true ;
233215 }
234216
235217 /**
236218 * Flag record for deletion.
237- * @param string $uid user id
238219 */
239- public function flagRecord ($ uid ) {
220+ public function flagRecord (string $ uid ): void {
240221 $ this ->deletedUsersIndex ->markUser ($ uid );
241222 }
242223
243224 /**
244225 * Unflag record for deletion.
245- * @param string $uid user id
246226 */
247- public function unflagRecord ($ uid ) {
227+ public function unflagRecord (string $ uid ): void {
248228 //do nothing
249229 }
250230
251231 /**
252232 * Get the LDAP attribute name for the user's display name
253- * @param string $uid user id
254- * @return string the display name field
255233 * @throws \Exception if user id was not found in LDAP
256234 */
257- public function getLDAPDisplayNameField ($ uid ) {
235+ public function getLDAPDisplayNameField (string $ uid ): string {
258236 if (!$ this ->userBackend ->userExists ($ uid )) {
259237 throw new \Exception ('User id not found in LDAP ' );
260238 }
@@ -263,11 +241,9 @@ public function getLDAPDisplayNameField($uid) {
263241
264242 /**
265243 * Get the LDAP attribute name for the email
266- * @param string $uid user id
267- * @return string the email field
268244 * @throws \Exception if user id was not found in LDAP
269245 */
270- public function getLDAPEmailField ($ uid ) {
246+ public function getLDAPEmailField (string $ uid ): string {
271247 if (!$ this ->userBackend ->userExists ($ uid )) {
272248 throw new \Exception ('User id not found in LDAP ' );
273249 }
@@ -276,11 +252,9 @@ public function getLDAPEmailField($uid) {
276252
277253 /**
278254 * Get the LDAP type of association between users and groups
279- * @param string $gid group id
280- * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
281255 * @throws \Exception if group id was not found in LDAP
282256 */
283- public function getLDAPGroupMemberAssoc ($ gid ) {
257+ public function getLDAPGroupMemberAssoc (string $ gid ): string {
284258 if (!$ this ->groupBackend ->groupExists ($ gid )) {
285259 throw new \Exception ('Group id not found in LDAP ' );
286260 }
0 commit comments