for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace NotificationChannels\RocketChat;
use GuzzleHttp\Client as HttpClient;
final class RocketChat
{
/** @var \GuzzleHttp\Client */
private $http;
/** @var string */
private $url;
private $token;
/** @var string|null */
private $defaultChannel;
/**
* @param \GuzzleHttp\Client $http
* @param string $url
* @param string $token
* @param string|null $defaultChannel
* @return void
@return
Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.
Please refer to the PHP core documentation on constructors.
*/
public function __construct(HttpClient $http, string $url, string $token, ?string $defaultChannel = null)
$this->http = $http;
$this->url = rtrim($url, '/');
$this->token = $token;
$this->defaultChannel = $defaultChannel;
}
* Returns RocketChat token.
*
* @return string
public function getToken(): string
return $this->token;
* Returns default channel id or name.
* @return string|null
public function getDefaultChannel(): ?string
return $this->defaultChannel;
* Send a message.
* @param string $to
* @param array $message
public function sendMessage(string $to, array $message): void
$url = sprintf('%s/hooks/%s', $this->url, $this->token);
$this->post($url, [
'json' => array_merge($message, [
'channel' => $to,
]),
]);
* Perform a simple post request.
* @param array $options
private function post(string $url, array $options): void
$this->http->post($url, $options);
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.