@@ -245,20 +245,19 @@ public function addSSHKey(string $key, UnityUser $operator, bool $send_mail = tr
245245 }
246246
247247 /**
248- * @return array bools corresponding to each key
249- * true if key added, false if key not added because it was already there
248+ * @return int number of keys added -- a key might not be added because it was already there
250249 * @throws NoKeyLoadedException if any key is invalid
251250 */
252- public function addSSHKeys (array $ keys , UnityUser $ operator , bool $ send_mail = true ): array
251+ public function addSSHKeys (array $ keys , UnityUser $ operator , bool $ send_mail = true ): int
253252 {
254253 foreach ($ keys as $ key ) {
255254 PublicKeyLoader::load ($ key ); // throws NoKeyLoadedException
256255 }
257256 $ keysBefore = $ this ->getSSHKeys ();
258- $ output = array_map ( fn ( $ key ) => ! in_array ( $ key , $ keysBefore ), $ keys );
259- $ newKeys = array_filter ( $ keys , fn ( $ key ) => ! in_array ( $ key , $ keysBefore ));
260- $ this ->setSSHKeys (array_merge ( $ this -> getSSHKeys (), $ newKeys ) , $ operator , $ send_mail );
261- return $ output ;
257+ // merge, then remove duplicates, then re-index
258+ $ keysAfter = array_values ( array_unique ( array_merge ( $ keysBefore , $ keys ) ));
259+ $ this ->setSSHKeys ($ keysAfter , $ operator , $ send_mail );
260+ return count ( $ keysAfter ) - count ( $ keysBefore ) ;
262261 }
263262
264263 public function removeSSHKey (int $ index , UnityUser $ operator , bool $ send_mail = true )
0 commit comments