@@ -86,12 +86,19 @@ public function countUsers(): int {
8686 }
8787
8888 public function deleteUser ($ uid ): bool {
89+ if (!is_string ($ uid ) || $ uid === '' ) {
90+ return false ;
91+ }
92+
8993 try {
9094 $ user = $ this ->userMapper ->getUser ($ uid );
9195 $ this ->userMapper ->delete ($ user );
9296 return true ;
97+ } catch (DoesNotExistException $ e ) {
98+ $ this ->logger ->info ('Tried to delete non-existent user ' , ['uid ' => $ uid , 'exception ' => $ e ]);
99+ return false ;
93100 } catch (Exception $ e ) {
94- $ this ->logger ->error ('Failed to delete user ' , [ 'exception ' => $ e ]);
101+ $ this ->logger ->error ('Failed to delete user ' , [' uid ' => $ uid , 'exception ' => $ e ]);
95102 return false ;
96103 }
97104 }
@@ -103,29 +110,23 @@ public function getUsers($search = '', $limit = null, $offset = null): array {
103110 ) {
104111 return [];
105112 }
106- return array_map (function ($ user ) {
107- return $ user ->getUserId ();
108- }, $ this ->userMapper ->find ($ search , $ limit , $ offset ));
113+ return array_map (static fn ($ user ) => $ user ->getUserId (), $ this ->userMapper ->find ($ search , $ limit , $ offset ));
109114 }
110115
111116 public function userExists ($ uid ): bool {
112- if (!is_string ($ uid )) {
113- return false ;
114- }
115- return $ this ->userMapper ->userExists ($ uid );
117+ return is_string ($ uid ) && $ uid !== '' && $ this ->userMapper ->userExists ($ uid );
116118 }
117119
118120 public function getDisplayName ($ uid ): string {
119- if (!is_string ($ uid )) {
121+ if (!is_string ($ uid ) || $ uid === '' ) {
120122 return (string )$ uid ;
121123 }
122124 try {
123125 $ user = $ this ->userMapper ->getUser ($ uid );
124- } catch (DoesNotExistException $ e ) {
126+ return $ user ->getDisplayName ();
127+ } catch (DoesNotExistException ) {
125128 return $ uid ;
126129 }
127-
128- return $ user ->getDisplayName ();
129130 }
130131
131132 public function getDisplayNames ($ search = '' , $ limit = null , $ offset = null ): array {
@@ -135,6 +136,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null): ar
135136 ) {
136137 return [];
137138 }
139+
138140 return $ this ->userMapper ->findDisplayNames ($ search , $ limit , $ offset );
139141 }
140142
0 commit comments