1010use React \Socket \ConnectionInterface ;
1111use React \Socket \Connector ;
1212use React \Socket \ConnectorInterface ;
13+ use function React \Promise \reject ;
14+ use function React \Promise \Timer \timeout ;
1315
1416class Factory
1517{
@@ -30,7 +32,7 @@ class Factory
3032 public function __construct (LoopInterface $ loop = null , ConnectorInterface $ connector = null , ProtocolFactory $ protocol = null )
3133 {
3234 $ this ->loop = $ loop ?: Loop::get ();
33- $ this ->connector = $ connector ?: new Connector (array () , $ this ->loop );
35+ $ this ->connector = $ connector ?: new Connector ([] , $ this ->loop );
3436 $ this ->protocol = $ protocol ?: new ProtocolFactory ();
3537 }
3638
@@ -54,18 +56,18 @@ public function createClient($uri)
5456 $ parts = parse_url ($ uri );
5557 }
5658
57- $ uri = preg_replace (array ( '/(:)[^:\/]*(@)/ ' , '/([?&]password=).*?($|&)/ ' ) , '$1***$2 ' , $ uri );
58- if ($ parts === false || !isset ($ parts ['scheme ' ], $ parts ['host ' ]) || !in_array ($ parts ['scheme ' ], array ( 'redis ' , 'rediss ' , 'redis+unix ' ) )) {
59- return \ React \ Promise \ reject (new \InvalidArgumentException (
59+ $ uri = preg_replace ([ '/(:)[^:\/]*(@)/ ' , '/([?&]password=).*?($|&)/ ' ] , '$1***$2 ' , $ uri );
60+ if ($ parts === false || !isset ($ parts ['scheme ' ], $ parts ['host ' ]) || !in_array ($ parts ['scheme ' ], [ 'redis ' , 'rediss ' , 'redis+unix ' ] )) {
61+ return reject (new \InvalidArgumentException (
6062 'Invalid Redis URI given (EINVAL) ' ,
6163 defined ('SOCKET_EINVAL ' ) ? SOCKET_EINVAL : 22
6264 ));
6365 }
6466
65- $ args = array () ;
66- parse_str (isset ( $ parts ['query ' ]) ? $ parts [ ' query ' ] : '' , $ args );
67+ $ args = [] ;
68+ parse_str ($ parts ['query ' ] ?? '' , $ args );
6769
68- $ authority = $ parts ['host ' ] . ': ' . (isset ( $ parts ['port ' ]) ? $ parts [ ' port ' ] : 6379 );
70+ $ authority = $ parts ['host ' ] . ': ' . ($ parts ['port ' ] ?? 6379 );
6971 if ($ parts ['scheme ' ] === 'rediss ' ) {
7072 $ authority = 'tls:// ' . $ authority ;
7173 } elseif ($ parts ['scheme ' ] === 'redis+unix ' ) {
@@ -88,9 +90,8 @@ public function createClient($uri)
8890 $ connecting ->cancel ();
8991 });
9092
91- $ protocol = $ this ->protocol ;
92- $ promise = $ connecting ->then (function (ConnectionInterface $ stream ) use ($ protocol ) {
93- return new StreamingClient ($ stream , $ protocol ->createResponseParser (), $ protocol ->createSerializer ());
93+ $ promise = $ connecting ->then (function (ConnectionInterface $ stream ) {
94+ return new StreamingClient ($ stream , $ this ->protocol ->createResponseParser (), $ this ->protocol ->createSerializer ());
9495 }, function (\Exception $ e ) use ($ uri ) {
9596 throw new \RuntimeException (
9697 'Connection to ' . $ uri . ' failed: ' . $ e ->getMessage (),
@@ -100,9 +101,8 @@ public function createClient($uri)
100101 });
101102
102103 // use `?password=secret` query or `user:secret@host` password form URL
103- $ pass = isset ($ args ['password ' ]) ? $ args ['password ' ] : (isset ($ parts ['pass ' ]) ? rawurldecode ($ parts ['pass ' ]) : null );
104104 if (isset ($ args ['password ' ]) || isset ($ parts ['pass ' ])) {
105- $ pass = isset ( $ args ['password ' ]) ? $ args [ ' password ' ] : rawurldecode ($ parts ['pass ' ]);
105+ $ pass = $ args ['password ' ] ?? rawurldecode ($ parts ['pass ' ]);
106106 $ promise = $ promise ->then (function (StreamingClient $ redis ) use ($ pass , $ uri ) {
107107 return $ redis ->auth ($ pass )->then (
108108 function () use ($ redis ) {
@@ -130,7 +130,7 @@ function (\Exception $e) use ($redis, $uri) {
130130
131131 // use `?db=1` query or `/1` path (skip first slash)
132132 if (isset ($ args ['db ' ]) || (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '/ ' )) {
133- $ db = isset ( $ args ['db ' ]) ? $ args [ ' db ' ] : substr ($ parts ['path ' ], 1 );
133+ $ db = $ args ['db ' ] ?? substr ($ parts ['path ' ], 1 );
134134 $ promise = $ promise ->then (function (StreamingClient $ redis ) use ($ db , $ uri ) {
135135 return $ redis ->select ($ db )->then (
136136 function () use ($ redis ) {
@@ -159,15 +159,15 @@ function (\Exception $e) use ($redis, $uri) {
159159 });
160160 }
161161
162- $ promise ->then (array ( $ deferred , 'resolve ' ), array ( $ deferred , 'reject ' ) );
162+ $ promise ->then ([ $ deferred , 'resolve ' ], [ $ deferred , 'reject ' ] );
163163
164164 // use timeout from explicit ?timeout=x parameter or default to PHP's default_socket_timeout (60)
165165 $ timeout = isset ($ args ['timeout ' ]) ? (float ) $ args ['timeout ' ] : (int ) ini_get ("default_socket_timeout " );
166166 if ($ timeout < 0 ) {
167167 return $ deferred ->promise ();
168168 }
169169
170- return \ React \ Promise \ Timer \ timeout ($ deferred ->promise (), $ timeout , $ this ->loop )->then (null , function ($ e ) use ($ uri ) {
170+ return timeout ($ deferred ->promise (), $ timeout , $ this ->loop )->then (null , function ($ e ) use ($ uri ) {
171171 if ($ e instanceof TimeoutException) {
172172 throw new \RuntimeException (
173173 'Connection to ' . $ uri . ' timed out after ' . $ e ->getTimeout () . ' seconds (ETIMEDOUT) ' ,
0 commit comments