Skip to content

Commit 0f66620

Browse files
Allow strings as value for MessageEntity objects. (#35)
* Allow strings as value for MessageEntity objects. --------- Co-authored-by: Oliver THEBAULT <[email protected]> Co-authored-by: Oliboy50 <[email protected]>
1 parent 0796007 commit 0f66620

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/M6Web/Component/Statsd/Client.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public function __construct(array $servers, MessageFormatterInterface $messageFo
6363
*
6464
* @param array $servers les serveurs
6565
*
66-
* @throws Exception
67-
*
6866
* @return void
67+
*
68+
* @throws Exception
6969
*/
7070
protected function init(array $servers)
7171
{
@@ -147,18 +147,18 @@ public function getServerKey($stats)
147147
/**
148148
* addToSend
149149
*
150-
* @param string $stats grahite node
151-
* @param string $value value
152-
* @param float $sampleRate sampling rate
153-
* @param string $unit unit
154-
* @param array $tags Tags key => value for influxDb
150+
* @param string $stats grahite node
151+
* @param int|string $value value
152+
* @param float $sampleRate sampling rate
153+
* @param string $unit unit
154+
* @param array $tags Tags key => value for influxDb
155155
*
156156
* @return Client
157157
*/
158158
protected function addToSend($stats, $value, $sampleRate, $unit, $tags)
159159
{
160160
$message = new MessageEntity(
161-
(string) $stats, (int) $value, (string) $unit, (float) $sampleRate, $tags
161+
(string) $stats, $value, (string) $unit, (float) $sampleRate, $tags
162162
);
163163

164164
$queue = [
@@ -322,9 +322,9 @@ public function send()
322322
* @param string $server server key
323323
* @param array $datas array de data à env
324324
*
325-
* @throws Exception
326-
*
327325
* @return bool
326+
*
327+
* @throws Exception
328328
*/
329329
public function writeDatas($server, $datas)
330330
{

src/M6Web/Component/Statsd/MessageEntity.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class MessageEntity
2525
protected $tags = [];
2626

2727
/**
28-
* @param string $node node
29-
* @param int $value value of the node
30-
* @param string $unit units (ms for timer, c for counting ...)
31-
* @param float $sampleRate sampling rate
32-
* @param array $tags Tags key => value for influxDb
28+
* @param string $node node
29+
* @param int|string $value value of the node
30+
* @param string $unit units (ms for timer, c for counting ...)
31+
* @param float $sampleRate sampling rate
32+
* @param array $tags Tags key => value for influxDb
3333
*
3434
* @return MessageEntity
3535
*/
@@ -60,8 +60,8 @@ protected function checkConstructor()
6060
throw new Exception('node and unit have to be a string');
6161
}
6262

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

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

0 commit comments

Comments
 (0)