Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow strings as value for MessageEntity objects. #35

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/M6Web/Component/Statsd/Client.php
Original file line number Diff line number Diff line change
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)
Oliboy50 marked this conversation as resolved.
Show resolved Hide resolved
{
$message = new MessageEntity(
(string) $stats, (int) $value, (string) $unit, (float) $sampleRate, $tags
(string) $stats, $value, (string) $unit, (float) $sampleRate, $tags
);

$queue = [
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)) {
mihai-amihailesei marked this conversation as resolved.
Show resolved Hide resolved
throw new Exception('value has to be an integer or a string');
}

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