@@ -130,6 +130,7 @@ public function getDropdownValues(LdapDropdownQuery $query): array
130130 if (!$ attribute ) {
131131 throw new RuntimeException ();
132132 }
133+
133134 $ attribute = $ attribute ->fields ['value ' ];
134135 if (!is_string ($ attribute )) {
135136 throw new LogicException ();
@@ -142,7 +143,7 @@ public function getDropdownValues(LdapDropdownQuery $query): array
142143 }
143144
144145 // Insert search text into filter if specified
145- if ($ search_text != '' ) {
146+ if ($ search_text !== '' ) {
146147 $ ldap_filter = sprintf (
147148 "(& %s (%s)) " ,
148149 $ config ->getLdapFilter (),
@@ -154,7 +155,7 @@ public function getDropdownValues(LdapDropdownQuery $query): array
154155
155156 try {
156157 // Transform LDAP warnings into errors
157- set_error_handler ([ self ::class, ' ldapErrorHandler ' ] , E_WARNING );
158+ set_error_handler (self ::ldapErrorHandler (...) , E_WARNING );
158159
159160 // Execute search
160161 $ ldap_values = $ this ->executeLdapSearch (
@@ -164,16 +165,14 @@ public function getDropdownValues(LdapDropdownQuery $query): array
164165 $ page_size ,
165166 $ ldap_filter ,
166167 );
167- } catch (Throwable $ e ) {
168- throw new RuntimeException ("Failed LDAP query " , previous: $ e );
168+ } catch (Throwable $ throwable ) {
169+ throw new RuntimeException ("Failed LDAP query " , $ throwable -> getCode (), previous: $ throwable );
169170 } finally {
170171 restore_error_handler ();
171172 }
172173
173174 // Sort results
174- usort ($ ldap_values , function ($ a , $ b ) {
175- return strnatcmp ($ a ['text ' ], $ b ['text ' ]);
176- });
175+ usort ($ ldap_values , fn ($ a , $ b ) => strnatcmp ($ a ['text ' ], $ b ['text ' ]));
177176
178177 // Set expected select2 format
179178 return [
@@ -226,6 +225,7 @@ private function executeLdapSearch(
226225 if (!$ result instanceof Result) {
227226 throw new RuntimeException ();
228227 }
228+
229229 ldap_parse_result ($ ds , $ result , $ errcode , $ matcheddn , $ errmsg , $ referrals , $ controls );
230230
231231 // PHPstan doens't know that this is safe
@@ -260,11 +260,12 @@ private function executeLdapSearch(
260260 }
261261
262262 $ found_count ++;
263- if ($ found_count < (( int ) $ page - 1 ) * ( int ) $ page_size + 1 ) {
263+ if ($ found_count < ($ page - 1 ) * $ page_size + 1 ) {
264264 // before the requested page
265265 continue ;
266266 }
267- if ($ found_count > ((int ) $ page ) * (int ) $ page_size ) {
267+
268+ if ($ found_count > ($ page ) * $ page_size ) {
268269 // after the requested page
269270 break ;
270271 }
@@ -280,6 +281,7 @@ private function executeLdapSearch(
280281 break ;
281282 }
282283 }
284+
283285 // @phpstan-ignore notIdentical.alwaysTrue
284286 } while ($ cookie !== null && $ cookie != '' && $ count < $ page_size );
285287
0 commit comments