33namespace Clue \React \Redis ;
44
55use Evenement \EventEmitter ;
6- use React \Stream \Util ;
76use React \EventLoop \LoopInterface ;
7+ use React \EventLoop \TimerInterface ;
8+ use React \Promise \PromiseInterface ;
9+ use React \Stream \Util ;
810use function React \Promise \reject ;
911
1012/**
1113 * @internal
1214 */
1315class LazyClient extends EventEmitter implements Client
1416{
17+ /** @var string */
1518 private $ target ;
19+
1620 /** @var Factory */
1721 private $ factory ;
22+
23+ /** @var bool */
1824 private $ closed = false ;
19- private $ promise ;
2025
26+ /** @var ?PromiseInterface */
27+ private $ promise = null ;
28+
29+ /** @var LoopInterface */
2130 private $ loop ;
31+
32+ /** @var float */
2233 private $ idlePeriod = 60.0 ;
23- private $ idleTimer ;
34+
35+ /** @var ?TimerInterface */
36+ private $ idleTimer = null ;
37+
38+ /** @var int */
2439 private $ pending = 0 ;
2540
41+ /** @var array<string,bool> */
2642 private $ subscribed = [];
43+
44+ /** @var array<string,bool> */
2745 private $ psubscribed = [];
2846
29- /**
30- * @param $target
31- */
32- public function __construct ($ target , Factory $ factory , LoopInterface $ loop )
47+ public function __construct (string $ target , Factory $ factory , LoopInterface $ loop )
3348 {
3449 $ args = [];
3550 \parse_str ((string ) \parse_url ($ target , \PHP_URL_QUERY ), $ args );
@@ -42,7 +57,7 @@ public function __construct($target, Factory $factory, LoopInterface $loop)
4257 $ this ->loop = $ loop ;
4358 }
4459
45- private function client ()
60+ private function client (): PromiseInterface
4661 {
4762 if ($ this ->promise !== null ) {
4863 return $ this ->promise ;
@@ -71,16 +86,16 @@ private function client()
7186 });
7287
7388 // keep track of all channels and patterns this connection is subscribed to
74- $ redis ->on ('subscribe ' , function ($ channel ) {
89+ $ redis ->on ('subscribe ' , function (string $ channel ) {
7590 $ this ->subscribed [$ channel ] = true ;
7691 });
77- $ redis ->on ('psubscribe ' , function ($ pattern ) {
92+ $ redis ->on ('psubscribe ' , function (string $ pattern ) {
7893 $ this ->psubscribed [$ pattern ] = true ;
7994 });
80- $ redis ->on ('unsubscribe ' , function ($ channel ) {
95+ $ redis ->on ('unsubscribe ' , function (string $ channel ) {
8196 unset($ this ->subscribed [$ channel ]);
8297 });
83- $ redis ->on ('punsubscribe ' , function ($ pattern ) {
98+ $ redis ->on ('punsubscribe ' , function (string $ pattern ) {
8499 unset($ this ->psubscribed [$ pattern ]);
85100 });
86101
@@ -106,7 +121,7 @@ private function client()
106121 });
107122 }
108123
109- public function __call ($ name , $ args )
124+ public function __call (string $ name , array $ args ): PromiseInterface
110125 {
111126 if ($ this ->closed ) {
112127 return reject (new \RuntimeException (
@@ -122,15 +137,15 @@ function ($result) {
122137 $ this ->idle ();
123138 return $ result ;
124139 },
125- function ($ error ) {
140+ function (\ Exception $ error ) {
126141 $ this ->idle ();
127142 throw $ error ;
128143 }
129144 );
130145 });
131146 }
132147
133- public function end ()
148+ public function end (): void
134149 {
135150 if ($ this ->promise === null ) {
136151 $ this ->close ();
@@ -140,15 +155,15 @@ public function end()
140155 return ;
141156 }
142157
143- return $ this ->client ()->then (function (Client $ redis ) {
158+ $ this ->client ()->then (function (Client $ redis ) {
144159 $ redis ->on ('close ' , function () {
145160 $ this ->close ();
146161 });
147162 $ redis ->end ();
148163 });
149164 }
150165
151- public function close ()
166+ public function close (): void
152167 {
153168 if ($ this ->closed ) {
154169 return ;
@@ -176,10 +191,7 @@ public function close()
176191 $ this ->removeAllListeners ();
177192 }
178193
179- /**
180- * @internal
181- */
182- public function awake ()
194+ private function awake (): void
183195 {
184196 ++$ this ->pending ;
185197
@@ -189,10 +201,7 @@ public function awake()
189201 }
190202 }
191203
192- /**
193- * @internal
194- */
195- public function idle ()
204+ private function idle (): void
196205 {
197206 --$ this ->pending ;
198207
0 commit comments