@@ -181,14 +181,16 @@ public static function clearflag_full(
181181 * @param false|resource $imap_stream
182182 *
183183 * @psalm-param value-of<self::CLOSE_FLAGS> $flag
184- * @psalm-param 0|32768 $flag
185184 *
186185 * @return true
187186 */
188187 public static function close ($ imap_stream , int $ flag = 0 ): bool
189188 {
190189 \imap_errors (); // flush errors
191190
191+ /** @var int */
192+ $ flag = $ flag ;
193+
192194 $ result = \imap_close (self ::EnsureConnection ($ imap_stream , __METHOD__ , 1 ), $ flag );
193195
194196 if (false === $ result ) {
@@ -699,12 +701,12 @@ public static function open(
699701
700702 \imap_errors (); // flush errors
701703
702- $ result = \imap_open ($ mailbox , $ username , $ password , $ options , $ n_retries , $ params );
704+ $ result = @ \imap_open ($ mailbox , $ username , $ password , $ options , $ n_retries , $ params );
703705
704706 if (!$ result ) {
705707 $ lastError = \imap_last_error ();
706708
707- if ('' !== \trim ($ lastError )) {
709+ if (( \is_string ( $ lastError )) && ( '' !== \trim ($ lastError) )) {
708710 throw new UnexpectedValueException ('IMAP error: ' .$ lastError );
709711 }
710712
@@ -890,7 +892,6 @@ public static function setflag_full(
890892 * @param false|resource $imap_stream
891893 *
892894 * @psalm-param value-of<self::SORT_CRITERIA> $criteria
893- * @psalm-param 1|5|0|2|6|3|4 $criteria
894895 *
895896 * @return int[]
896897 *
@@ -909,6 +910,9 @@ public static function sort(
909910 $ imap_stream = self ::EnsureConnection ($ imap_stream , __METHOD__ , 1 );
910911 $ reverse = (int ) $ reverse ;
911912
913+ /** @var int */
914+ $ criteria = $ criteria ;
915+
912916 if (null !== $ search_criteria && null !== $ charset ) {
913917 $ result = \imap_sort (
914918 $ imap_stream ,
@@ -935,7 +939,7 @@ public static function sort(
935939 );
936940 }
937941
938- if (! $ result ) {
942+ if (false === $ result ) {
939943 throw new UnexpectedValueException ('Could not sort messages! ' , 0 , self ::HandleErrors (\imap_errors (), 'imap_sort ' ));
940944 }
941945
@@ -990,7 +994,6 @@ public static function subscribe(
990994
991995 /**
992996 * @psalm-param value-of<self::TIMEOUT_TYPES> $timeout_type
993- * @psalm-param 4|1|2|3 $timeout_type
994997 *
995998 * @return true|int
996999 */
@@ -1000,6 +1003,9 @@ public static function timeout(
10001003 ) {
10011004 \imap_errors (); // flush errors
10021005
1006+ /** @var int */
1007+ $ timeout_type = $ timeout_type ;
1008+
10031009 $ result = \imap_timeout (
10041010 $ timeout_type ,
10051011 $ timeout
0 commit comments