2828use OC \Core \Command \Base ;
2929use OCA \LDAPContactsBackend \Service \Configuration ;
3030use OCA \LDAPContactsBackend \Service \ConnectionImporter ;
31+ use RuntimeException ;
3132use Symfony \Component \Console \Helper \QuestionHelper ;
3233use Symfony \Component \Console \Input \InputArgument ;
3334use Symfony \Component \Console \Input \InputInterface ;
3738use Symfony \Component \Console \Question \Question ;
3839
3940class Add extends Base {
40- /** @var Configuration */
41- private $ configurationService ;
42- /** @var ConnectionImporter|null */
43- private $ connectionImporter ;
41+ private Configuration $ configurationService ;
42+ private ?ConnectionImporter $ connectionImporter ;
4443
4544 public function __construct (Configuration $ configurationService , ?ConnectionImporter $ connectionImporter = null ) {
4645 parent ::__construct ();
@@ -147,7 +146,7 @@ protected function interact(InputInterface $input, OutputInterface $output) {
147146 $ helper = $ this ->getHelper ('question ' );
148147
149148 $ q = new Question ('Address book display name: ' );
150- $ q ->setNormalizer (function ($ input ) {
149+ $ q ->setNormalizer (function (string $ input ) {
151150 return $ this ->stringNormalizer ($ input );
152151 });
153152
@@ -173,16 +172,11 @@ protected function interact(InputInterface $input, OutputInterface $output) {
173172 $ q = new Question ('Transport encryption: ' );
174173 $ q ->setAutocompleterValues (['StartTLS ' , 'LDAPS ' , 'none ' ]);
175174
176- switch ($ helper ->ask ($ input , $ output , $ q )) {
177- case 'StartTLS ' :
178- $ v = 'tls ' ;
179- break ;
180- case 'LDAPS ' :
181- $ v = 'ssl ' ;
182- break ;
183- default :
184- $ v = 'none ' ;
185- }
175+ $ v = match ($ helper ->ask ($ input , $ output , $ q )) {
176+ 'StartTLS ' => 'tls ' ,
177+ 'LDAPS ' => 'ssl ' ,
178+ default => 'none ' ,
179+ };
186180
187181 $ input ->setOption ('trans_enc ' , $ v );
188182 }
@@ -306,18 +300,6 @@ protected function importConnection(InputInterface $input) {
306300 $ wasRun = true ;
307301 }
308302
309- protected function askArrayOfString (string $ subject , string $ label , InputInterface $ input , OutputInterface $ output ): void {
310- /** @var QuestionHelper $helper */
311- $ helper = $ this ->getHelper ('question ' );
312-
313- $ q = new Question ($ label );
314- $ q ->setNormalizer (function ($ input ) {
315- return $ this ->arrayOfStringNormalizer ($ input );
316- });
317-
318- $ input ->setOption ($ subject , $ helper ->ask ($ input , $ output , $ q ));
319- }
320-
321303 protected function askImport (InputInterface $ input , OutputInterface $ output ): void {
322304 $ availableConnections = $ this ->connectionImporter ? $ this ->connectionImporter ->getAvailableConnections () : [];
323305 if (count ($ availableConnections ) === 0 ) {
@@ -393,15 +375,8 @@ protected function askUnsignedInt(string $subject, string $label, InputInterface
393375 $ input ->setOption ($ subject , $ helper ->ask ($ input , $ output , $ q ));
394376 }
395377
396- protected function stringNormalizer ($ input ) {
397- return $ input ? trim ($ input ) : '' ;
398- }
399-
400- protected function arrayOfStringNormalizer (string $ input ) {
401- foreach ($ input as &$ item ) {
402- $ item = $ this ->stringNormalizer ($ item );
403- }
404- return $ input ;
378+ protected function stringNormalizer (?string $ input ): string {
379+ return ($ input !== null ) ? trim ($ input ) : '' ;
405380 }
406381
407382 protected function askStrings (string $ subject , string $ label , string $ followUpLabel , InputInterface $ input , OutputInterface $ output ): void {
@@ -435,7 +410,7 @@ protected function posNumberNormalizer(?string $input): ?int {
435410 $ input = (int )$ input ;
436411 }
437412 if (is_int ($ input ) && $ input < 0 ) {
438- throw new \ RuntimeException ('Port must not be negative ' );
413+ throw new RuntimeException ('Port must not be negative ' );
439414 }
440415 return $ input ;
441416 }
0 commit comments