Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Jan 16, 2025
1 parent 143c3c9 commit e6f9d86
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ parameters:
paths:
- tests/*
- src/Client.php
- src/BaseClient.php
- src/WebSocketClient.php
-
message: '#Property \S+ has no type specified.#'
paths:
Expand Down
57 changes: 57 additions & 0 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ abstract class BaseClient
/** @var string */
private $path = '/mqtt';

/**
* @param string $host
* @return $this
*/
public function setHost(string $host): self
{
$this->host = $host;
Expand All @@ -76,6 +80,10 @@ public function getPort(): int
return $this->port;
}

/**
* @param int $clientType
* @return $this
*/
public function setClientType(int $clientType): self
{
$this->clientType = $clientType;
Expand All @@ -88,6 +96,10 @@ public function getClientType(): int
return $this->clientType;
}

/**
* @param ClientConfig $config
* @return $this
*/
public function setConfig(ClientConfig $config): self
{
$this->config = $config;
Expand All @@ -100,6 +112,10 @@ public function getConfig(): ClientConfig
return $this->config;
}

/**
* @param Coroutine\Client|\Swoole\Client|WebSocketClient $client
* @return $this
*/
public function setClient($client): self
{
$this->client = $client;
Expand Down Expand Up @@ -134,6 +150,10 @@ public function setConnectData(array $connectData): self
return $this;
}

/**
* @param string|null $key
* @return array|string|null
*/
public function getConnectData(?string $key = null)
{
if ($key) {
Expand Down Expand Up @@ -207,6 +227,11 @@ protected function handleException(): void
throw new ConnectException($errMsg, $this->client->errCode);
}

/**
* @param bool $clean
* @param array $will
* @return mixed
*/
public function connect(bool $clean = true, array $will = [])
{
$data = [
Expand All @@ -232,6 +257,11 @@ public function connect(bool $clean = true, array $will = [])
return $this->send($data);
}

/**
* @param array $topics
* @param array $properties
* @return mixed
*/
public function subscribe(array $topics, array $properties = [])
{
return $this->send([
Expand All @@ -242,6 +272,11 @@ public function subscribe(array $topics, array $properties = [])
]);
}

/**
* @param array $topics
* @param array $properties
* @return mixed
*/
public function unSubscribe(array $topics, array $properties = [])
{
return $this->send([
Expand All @@ -252,6 +287,15 @@ public function unSubscribe(array $topics, array $properties = [])
]);
}

/**
* @param string $topic
* @param string $message
* @param int $qos
* @param int $dup
* @param int $retain
* @param array $properties
* @return mixed
*/
public function publish(
string $topic,
string $message,
Expand Down Expand Up @@ -293,18 +337,31 @@ public function publish(
);
}

/**
* @return mixed
*/
public function ping()
{
return $this->send(['type' => Protocol\Types::PINGREQ]);
}

/**
* @param int $code
* @param array $properties
* @return bool
*/
public function close(int $code = ReasonCode::NORMAL_DISCONNECTION, array $properties = []): bool
{
$this->send(['type' => Protocol\Types::DISCONNECT, 'code' => $code, 'properties' => $properties], false);

return $this->client->close();
}

/**
* @param int $code
* @param array $properties
* @return mixed
*/
public function auth(int $code = ReasonCode::SUCCESS, array $properties = [])
{
return $this->send(['type' => Protocol\Types::AUTH, 'code' => $code, 'properties' => $properties]);
Expand Down

0 comments on commit e6f9d86

Please sign in to comment.