1111 */
1212namespace Hyperf \GoTask \IPC ;
1313
14+ use Hyperf \Context \ApplicationContext ;
1415use Hyperf \ExceptionHandler \Formatter \FormatterInterface ;
1516use Hyperf \GoTask \GoTask ;
1617use Hyperf \GoTask \Relay \ConnectionRelay ;
1718use Hyperf \GoTask \Wrapper \ByteWrapper ;
18- use Hyperf \Utils \ApplicationContext ;
1919use Spiral \Goridge \Exceptions \PrefixException ;
2020use Spiral \Goridge \Exceptions \ServiceException ;
2121use Spiral \Goridge \Exceptions \TransportException ;
2222use Spiral \Goridge \RelayInterface as Relay ;
23+ use Swoole \Coroutine \Server ;
2324use Swoole \Coroutine \Server \Connection ;
2425use Throwable ;
2526
2627class SocketIPCReceiver
2728{
28- /**
29- * @var string
30- */
31- private $ address ;
29+ private string $ address ;
3230
33- /**
34- * @var \Swoole\Coroutine\Server
35- */
36- private $ server ;
31+ private ?Server $ server = null ;
3732
38- /**
39- * @var int
40- */
41- private $ port ;
33+ private int $ port ;
4234
43- /**
44- * @var bool
45- */
46- private $ quit ;
35+ private bool $ quit ;
4736
4837 public function __construct (string $ address = '127.0.0.1:6001 ' )
4938 {
@@ -114,7 +103,7 @@ public function start(): bool
114103 return true ;
115104 }
116105
117- public function close ()
106+ public function close (): void
118107 {
119108 if ($ this ->server !== null ) {
120109 $ this ->quit = true ;
@@ -123,7 +112,7 @@ public function close()
123112 $ this ->server = null ;
124113 }
125114
126- protected function dispatch ($ method , $ payload )
115+ protected function dispatch (string $ method , mixed $ payload ): mixed
127116 {
128117 [$ class , $ handler ] = explode (':: ' , $ method );
129118 if (ApplicationContext::hasContainer ()) {
@@ -135,20 +124,17 @@ protected function dispatch($method, $payload)
135124 return $ instance ->{$ handler }($ payload );
136125 }
137126
138- protected function isStarted ()
127+ protected function isStarted (): bool
139128 {
140129 return $ this ->server !== null ;
141130 }
142131
143132 /**
144133 * Handle response body.
145134 *
146- * @param string $body
147- *
148- * @return mixed
149135 * @throws ServiceException
150136 */
151- protected function handleBody ($ body , int $ flags )
137+ protected function handleBody (string $ body , int $ flags ): mixed
152138 {
153139 if ($ flags & GoTask::PAYLOAD_ERROR && $ flags & GoTask::PAYLOAD_RAW ) {
154140 throw new ServiceException ("error ' {$ body }' on ' {$ this ->server }' " );
@@ -161,7 +147,7 @@ protected function handleBody($body, int $flags)
161147 return json_decode ($ body , true );
162148 }
163149
164- private function formatError (Throwable $ error )
150+ private function formatError (Throwable $ error ): string
165151 {
166152 $ simpleFormat = $ error ->getMessage () . ': ' . $ error ->getTraceAsString ();
167153 if (! ApplicationContext::hasContainer ()) {
0 commit comments