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{
15- private $ target ;
16- /** @var Factory */
17- private $ factory ;
18- private $ closed = false ;
19- private $ promise ;
20-
21- private $ loop ;
22- private $ idlePeriod = 60.0 ;
23- private $ idleTimer ;
24- private $ pending = 0 ;
25-
26- private $ subscribed = [];
27- private $ psubscribed = [];
28-
29- /**
30- * @param $target
31- */
32- public function __construct ($ target , Factory $ factory , LoopInterface $ loop )
17+ private string $ target ;
18+ private Factory $ factory ;
19+ private bool $ closed = false ;
20+ private ?PromiseInterface $ promise = null ;
21+
22+ private LoopInterface $ loop ;
23+ private float $ idlePeriod = 60.0 ;
24+ private ?TimerInterface $ idleTimer = null ;
25+ private int $ pending = 0 ;
26+
27+ private array $ subscribed = [];
28+ private array $ psubscribed = [];
29+
30+ public function __construct (string $ target , Factory $ factory , LoopInterface $ loop )
3331 {
3432 $ args = [];
3533 \parse_str ((string ) \parse_url ($ target , \PHP_URL_QUERY ), $ args );
@@ -42,7 +40,7 @@ public function __construct($target, Factory $factory, LoopInterface $loop)
4240 $ this ->loop = $ loop ;
4341 }
4442
45- private function client ()
43+ private function client (): PromiseInterface
4644 {
4745 if ($ this ->promise !== null ) {
4846 return $ this ->promise ;
@@ -71,16 +69,16 @@ private function client()
7169 });
7270
7371 // keep track of all channels and patterns this connection is subscribed to
74- $ redis ->on ('subscribe ' , function ($ channel ) {
72+ $ redis ->on ('subscribe ' , function (string $ channel ) {
7573 $ this ->subscribed [$ channel ] = true ;
7674 });
77- $ redis ->on ('psubscribe ' , function ($ pattern ) {
75+ $ redis ->on ('psubscribe ' , function (string $ pattern ) {
7876 $ this ->psubscribed [$ pattern ] = true ;
7977 });
80- $ redis ->on ('unsubscribe ' , function ($ channel ) {
78+ $ redis ->on ('unsubscribe ' , function (string $ channel ) {
8179 unset($ this ->subscribed [$ channel ]);
8280 });
83- $ redis ->on ('punsubscribe ' , function ($ pattern ) {
81+ $ redis ->on ('punsubscribe ' , function (string $ pattern ) {
8482 unset($ this ->psubscribed [$ pattern ]);
8583 });
8684
@@ -106,7 +104,7 @@ private function client()
106104 });
107105 }
108106
109- public function __call ($ name , $ args )
107+ public function __call (string $ name , array $ args ): PromiseInterface
110108 {
111109 if ($ this ->closed ) {
112110 return reject (new \RuntimeException (
@@ -122,15 +120,15 @@ function ($result) {
122120 $ this ->idle ();
123121 return $ result ;
124122 },
125- function ($ error ) {
123+ function (\ Exception $ error ) {
126124 $ this ->idle ();
127125 throw $ error ;
128126 }
129127 );
130128 });
131129 }
132130
133- public function end ()
131+ public function end (): void
134132 {
135133 if ($ this ->promise === null ) {
136134 $ this ->close ();
@@ -140,15 +138,15 @@ public function end()
140138 return ;
141139 }
142140
143- return $ this ->client ()->then (function (Client $ redis ) {
141+ $ this ->client ()->then (function (Client $ redis ) {
144142 $ redis ->on ('close ' , function () {
145143 $ this ->close ();
146144 });
147145 $ redis ->end ();
148146 });
149147 }
150148
151- public function close ()
149+ public function close (): void
152150 {
153151 if ($ this ->closed ) {
154152 return ;
@@ -176,10 +174,7 @@ public function close()
176174 $ this ->removeAllListeners ();
177175 }
178176
179- /**
180- * @internal
181- */
182- public function awake ()
177+ private function awake (): void
183178 {
184179 ++$ this ->pending ;
185180
@@ -189,10 +184,7 @@ public function awake()
189184 }
190185 }
191186
192- /**
193- * @internal
194- */
195- public function idle ()
187+ private function idle (): void
196188 {
197189 --$ this ->pending ;
198190
0 commit comments