Skip to content

Commit

Permalink
Allow strings as value for MessageEntity objects. (#35)
Browse files Browse the repository at this point in the history
* Allow strings as value for MessageEntity objects.

---------

Co-authored-by: Oliver THEBAULT <[email protected]>
Co-authored-by: Oliboy50 <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2023
1 parent 0796007 commit 0f66620
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/M6Web/Component/Statsd/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function __construct(array $servers, MessageFormatterInterface $messageFo
*
* @param array $servers les serveurs
*
* @throws Exception
*
* @return void
*
* @throws Exception
*/
protected function init(array $servers)
{
Expand Down Expand Up @@ -147,18 +147,18 @@ public function getServerKey($stats)
/**
* addToSend
*
* @param string $stats grahite node
* @param string $value value
* @param float $sampleRate sampling rate
* @param string $unit unit
* @param array $tags Tags key => value for influxDb
* @param string $stats grahite node
* @param int|string $value value
* @param float $sampleRate sampling rate
* @param string $unit unit
* @param array $tags Tags key => value for influxDb
*
* @return Client
*/
protected function addToSend($stats, $value, $sampleRate, $unit, $tags)
{
$message = new MessageEntity(
(string) $stats, (int) $value, (string) $unit, (float) $sampleRate, $tags
(string) $stats, $value, (string) $unit, (float) $sampleRate, $tags
);

$queue = [
Expand Down Expand Up @@ -322,9 +322,9 @@ public function send()
* @param string $server server key
* @param array $datas array de data à env
*
* @throws Exception
*
* @return bool
*
* @throws Exception
*/
public function writeDatas($server, $datas)
{
Expand Down
14 changes: 7 additions & 7 deletions src/M6Web/Component/Statsd/MessageEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class MessageEntity
protected $tags = [];

/**
* @param string $node node
* @param int $value value of the node
* @param string $unit units (ms for timer, c for counting ...)
* @param float $sampleRate sampling rate
* @param array $tags Tags key => value for influxDb
* @param string $node node
* @param int|string $value value of the node
* @param string $unit units (ms for timer, c for counting ...)
* @param float $sampleRate sampling rate
* @param array $tags Tags key => value for influxDb
*
* @return MessageEntity
*/
Expand Down Expand Up @@ -60,8 +60,8 @@ protected function checkConstructor()
throw new Exception('node and unit have to be a string');
}

if (!is_int($this->value)) {
throw new Exception('value has to be an integer');
if (!is_int($this->value) && !is_string($this->value)) {
throw new Exception('value has to be an integer or a string');
}

if (!is_float($this->sampleRate) or ($this->sampleRate <= 0)) {
Expand Down

0 comments on commit 0f66620

Please sign in to comment.