@@ -122,6 +122,7 @@ public function connect(string $host, ?int $port = null, array $options = []): v
122122
123123 /**
124124 * Get the default socket options for the given transport.
125+ * @param 'ssl'|'tls'|'starttls'|'tcp' $transport
125126 */
126127 protected function getDefaultSocketOptions (string $ transport , array $ proxy = [], bool $ validateCert = true ): array
127128 {
@@ -571,9 +572,7 @@ public function idle(int $timeout): Generator
571572 fn (ContinuationResponse $ response ) => ImapCommandException::make (new ImapCommand ('' , 'IDLE ' ), $ response ),
572573 );
573574
574- while ($ response = $ this ->nextReply ()) {
575- yield $ response ;
576- }
575+ yield $ this ->nextReply ();
577576 }
578577
579578 /**
@@ -595,6 +594,7 @@ public function done(): void
595594
596595 /**
597596 * Send an IMAP command.
597+ * @param-out string $tag
598598 */
599599 public function send (string $ name , array $ tokens = [], ?string &$ tag = null ): void
600600 {
@@ -727,15 +727,12 @@ protected function assertTaggedResponse(string $tag, ?callable $exception = null
727727 */
728728 protected function assertNextResponse (callable $ filter , callable $ assertion , callable $ exception ): Response
729729 {
730- while ($ response = $ this ->nextResponse ($ filter )) {
731- if ($ assertion ($ response )) {
732- return $ response ;
733- }
734-
735- throw $ exception ($ response );
730+ $ response = $ this ->nextResponse ($ filter );
731+ if ($ assertion ($ response )) {
732+ return $ response ;
736733 }
737734
738- throw new ImapResponseException ( ' No matching response found ' );
735+ throw $ exception ( $ response );
739736 }
740737
741738 /**
@@ -752,16 +749,15 @@ protected function nextResponse(callable $filter): Response
752749 throw new LogicException ('No parser instance set ' );
753750 }
754751
755- while ( $ response = $ this ->nextReply ()) {
756- if (! $ response instanceof Response) {
757- continue ;
758- }
752+ $ response = $ this ->nextReply ();
753+ if (! $ response instanceof Response) {
754+ throw new ImapResponseException ( ' Unknown response type: ' . $ response ::class) ;
755+ }
759756
760- $ this ->result ?->addResponse($ response );
757+ $ this ->result ?->addResponse($ response );
761758
762- if ($ filter ($ response )) {
763- return $ response ;
764- }
759+ if ($ filter ($ response )) {
760+ return $ response ;
765761 }
766762
767763 throw new ImapResponseException ('No matching response found ' );
@@ -770,7 +766,7 @@ protected function nextResponse(callable $filter): Response
770766 /**
771767 * Read the next reply from the stream.
772768 */
773- protected function nextReply (): Data |Token |Response | null
769+ protected function nextReply (): Data |Token |Response
774770 {
775771 if (! $ reply = $ this ->parser ->next ()) {
776772 $ meta = $ this ->stream ->meta ();
0 commit comments