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

docs: update wrong php types in \InfluxDB2\Point #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 3.5.0 [unreleased]
### Others
1. [#148](https://github.com/influxdata/influxdb-client-php/pull/148): Update wrong php types in \InfluxDB2\Point

## 3.4.0 [2023-07-28]

Expand Down
52 changes: 25 additions & 27 deletions src/InfluxDB2/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class Point
private $tags;
/** @var array */
private $fields;
/** @var int */
/** @var int|null */
private $time;
/** @var WritePrecision */
/** @var WritePrecision::* */
private $precision;

/** Create DataPoint instance for specified measurement name.
*
* @param [String] name the measurement name for the point.
* @param [Array] tags the tag set for the point
* @param [Array] fields the fields for the point
* @param [Integer] time the timestamp for the point
* @param [WritePrecision] precision the precision for the unix timestamps within the body line-protocol
* @param string $name the measurement name for the point.
* @param array $tags the tag set for the point
* @param array $fields the fields for the point
* @param int $time the timestamp for the point
* @param WritePrecision::* $precision the precision for the unix timestamps within the body line-protocol
*/
public function __construct(
$name,
Expand All @@ -43,7 +43,7 @@ public function __construct(
}

/**
* @return WritePrecision
* @return WritePrecision::*
*/
public function getPrecision(): ?string
{
Expand All @@ -55,12 +55,10 @@ public static function measurement($name): Point
return new Point($name);
}

/** Create DataPoint instance from specified data.
*
* @param [Array] data
* @return Point
/**
* Create DataPoint instance from specified data.
*/
public static function fromArray($data): ?Point
public static function fromArray(array $data): ?Point
{
if (!array_key_exists('name', $data)) {
return null;
Expand All @@ -76,8 +74,8 @@ public static function fromArray($data): ?Point

/** Adds or replaces a tag value for a point.
*
* @param [Object] key the tag name
* @param [Object] value the tag value
* @param mixed $key the tag name
* @param mixed $value the tag value
* @return Point
*/
public function addTag($key, $value): Point
Expand All @@ -89,8 +87,8 @@ public function addTag($key, $value): Point

/** Adds or replaces a field value for a point.
*
* @param [Object] key the tag name
* @param [Object] value the tag value
* @param mixed $key the tag name
* @param mixed $value the tag value
* @return Point
*/
public function addField($key, $value): Point
Expand All @@ -102,8 +100,8 @@ public function addField($key, $value): Point

/** Updates the timestamp for the point.
*
* @param [Object] time the timestamp
* @param [WritePrecision] precision the timestamp precision
* @param mixed $time the timestamp
* @param WritePrecision::* $precision the timestamp precision
* @return Point
*/
public function time($time, $precision = null): Point
Expand All @@ -116,9 +114,9 @@ public function time($time, $precision = null): Point

/** If there is no field then return null.
*
* @return string representation of the point
* @return string|null representation of the point
*/
public function toLineProtocol()
public function toLineProtocol(): ?string
{
$measurement = $this->escapeKey($this->name, false);

Expand Down Expand Up @@ -149,7 +147,7 @@ public function toLineProtocol()
return $lineProtocol;
}

private function appendTags()
private function appendTags(): ?string
{
$tags = '';

Expand All @@ -173,7 +171,7 @@ private function appendTags()
return $tags;
}

private function appendFields()
private function appendFields(): ?string
{
$fields = '';

Expand Down Expand Up @@ -208,7 +206,7 @@ private function appendFields()
return rtrim($fields, ',');
}

private function appendTime()
private function appendTime(): ?string
{
if (!isset($this->time)) {
return null;
Expand Down Expand Up @@ -240,7 +238,7 @@ private function appendTime()
return ' ' . $time;
}

private function escapeKey($key, $escapeEqual = true)
private function escapeKey($key, $escapeEqual = true): string
{
$escapeKeys = array(' ' => '\\ ', ',' => '\\,', "\\" => '\\\\',
"\n" => '\\n', "\r" => '\\r', "\t" => '\\t');
Expand All @@ -252,13 +250,13 @@ private function escapeKey($key, $escapeEqual = true)
return strtr($key, $escapeKeys);
}

private function escapeValue($value)
private function escapeValue($value): string
{
$escapeValues = array('"' => '\\"', "\\" => '\\\\');
return strtr($value, $escapeValues);
}

private function isNullOrEmptyString($str)
private function isNullOrEmptyString($str): bool
{
return (!is_string($str) || trim($str) === '');
}
Expand Down