@@ -143,7 +143,23 @@ public function getAuthentication(): AuthenticateInterface
143143 */
144144 public function isOpen (): bool
145145 {
146- return !in_array ($ this ->protocol ()->serverState , [ServerState::DISCONNECTED , ServerState::DEFUNCT ], true );
146+ return !in_array (
147+ $ this ->protocol ()->serverState ,
148+ [ServerState::DISCONNECTED , ServerState::DEFUNCT ],
149+ true
150+ );
151+ }
152+
153+ /**
154+ * @psalm-mutation-free
155+ */
156+ public function isStreaming (): bool
157+ {
158+ return in_array (
159+ $ this ->protocol ()->serverState ,
160+ [ServerState::STREAMING , ServerState::TX_STREAMING ],
161+ true
162+ );
147163 }
148164
149165 public function setTimeout (float $ timeout ): void
@@ -154,7 +170,8 @@ public function setTimeout(float $timeout): void
154170 public function consumeResults (): void
155171 {
156172 $ this ->logger ?->log(LogLevel::DEBUG , 'Consuming results ' );
157- if ($ this ->protocol ()->serverState !== ServerState::STREAMING && $ this ->protocol ()->serverState !== ServerState::TX_STREAMING ) {
173+ if ($ this ->protocol ()->serverState !== ServerState::STREAMING && $ this ->protocol (
174+ )->serverState !== ServerState::TX_STREAMING ) {
158175 $ this ->subscribedResults = [];
159176
160177 return ;
@@ -225,8 +242,14 @@ public function discard(?int $qid): void
225242 *
226243 * @return BoltMeta
227244 */
228- public function run (string $ text , array $ parameters , ?string $ database , ?float $ timeout , BookmarkHolder $ holder , ?AccessMode $ mode ): array
229- {
245+ public function run (
246+ string $ text ,
247+ array $ parameters ,
248+ ?string $ database ,
249+ ?float $ timeout ,
250+ BookmarkHolder $ holder ,
251+ ?AccessMode $ mode
252+ ): array {
230253 $ extra = $ this ->buildRunExtra ($ database , $ timeout , $ holder , $ mode );
231254 $ this ->logger ?->log(LogLevel::DEBUG , 'RUN ' , $ extra );
232255 $ response = $ this ->protocol ()
@@ -298,10 +321,15 @@ public function pull(?int $qid, ?int $fetchSize): array
298321 }
299322
300323 public function __destruct ()
324+ {
325+ $ this ->close ();
326+ }
327+
328+ public function close (): void
301329 {
302330 try {
303331 if ($ this ->isOpen ()) {
304- if ($ this ->protocol ()-> serverState === ServerState:: STREAMING || $ this -> protocol ()-> serverState === ServerState:: TX_STREAMING ) {
332+ if ($ this ->isStreaming () ) {
305333 $ this ->consumeResults ();
306334 }
307335
0 commit comments