Skip to content

Commit

Permalink
Rename didPeerInitiateClose() to isClosedByPeer()
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jun 24, 2020
1 parent a6860f6 commit 35d9a31
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Client.php
Expand Up @@ -68,7 +68,7 @@ public function getCloseReason(): string;
*
* @throws \Error Thrown if the client has not closed.
*/
public function didPeerInitiateClose(): bool;
public function isClosedByPeer(): bool;

/**
* Sends a text message to the endpoint. All data sent with this method must be valid UTF-8. Use `sendBinary()` if
Expand Down
2 changes: 1 addition & 1 deletion src/ClientMetadata.php
Expand Up @@ -15,7 +15,7 @@ final class ClientMetadata
public $id;

/** @var bool */
public $peerInitiatedClose = false;
public $closedByPeer = false;

/** @var int|null */
public $closeCode;
Expand Down
8 changes: 4 additions & 4 deletions src/Rfc6455Client.php
Expand Up @@ -226,13 +226,13 @@ public function getCloseReason(): string
return $this->metadata->closeReason;
}

public function didPeerInitiateClose(): bool
public function isClosedByPeer(): bool
{
if (!$this->metadata->closedAt) {
throw new \Error('The client has not closed');
}

return $this->metadata->peerInitiatedClose;
return $this->metadata->closedByPeer;
}

public function getOptions(): Options
Expand Down Expand Up @@ -294,7 +294,7 @@ private function read(): \Generator
}

if (!$this->metadata->closedAt) {
$this->metadata->peerInitiatedClose = true;
$this->metadata->closedByPeer = true;
$this->close(Code::ABNORMAL_CLOSE, $message ?? 'TCP connection closed unexpectedly');
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ private function onControlFrame(int $opcode, string $data): void
break;
}

$this->metadata->peerInitiatedClose = true;
$this->metadata->closedByPeer = true;

$length = \strlen($data);
if ($length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions test/ClientTest.php
Expand Up @@ -66,7 +66,7 @@ public function testClose(): \Generator
[$reportedCode, $reportedReason] = yield $client->close($code, $reason);

$this->assertFalse($client->isConnected());
$this->assertFalse($client->didPeerInitiateClose());
$this->assertFalse($client->isClosedByPeer());
$this->assertSame($code, $client->getCloseCode());
$this->assertSame($reason, $client->getCloseReason());
$this->assertSame($code, $reportedCode);
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testCloseWithoutResponse(): \Generator
yield $client->close($code, $reason);

$this->assertFalse($client->isConnected());
$this->assertFalse($client->didPeerInitiateClose());
$this->assertFalse($client->isClosedByPeer());
$this->assertSame($code, $client->getCloseCode());
$this->assertSame($reason, $client->getCloseReason());

Expand Down

0 comments on commit 35d9a31

Please sign in to comment.