@@ -15,18 +15,18 @@ class Point
15
15
private $ tags ;
16
16
/** @var array */
17
17
private $ fields ;
18
- /** @var int */
18
+ /** @var int|null */
19
19
private $ time ;
20
- /** @var WritePrecision */
20
+ /** @var WritePrecision::* */
21
21
private $ precision ;
22
22
23
23
/** Create DataPoint instance for specified measurement name.
24
24
*
25
- * @param [String] name the measurement name for the point.
26
- * @param [Array] tags the tag set for the point
27
- * @param [Array] fields the fields for the point
28
- * @param [Integer] time the timestamp for the point
29
- * @param [ WritePrecision] precision the precision for the unix timestamps within the body line-protocol
25
+ * @param string $ name the measurement name for the point.
26
+ * @param array $ tags the tag set for the point
27
+ * @param array $ fields the fields for the point
28
+ * @param int $ time the timestamp for the point
29
+ * @param WritePrecision::* $ precision the precision for the unix timestamps within the body line-protocol
30
30
*/
31
31
public function __construct (
32
32
$ name ,
@@ -43,7 +43,7 @@ public function __construct(
43
43
}
44
44
45
45
/**
46
- * @return WritePrecision
46
+ * @return WritePrecision::*
47
47
*/
48
48
public function getPrecision (): ?string
49
49
{
@@ -55,12 +55,10 @@ public static function measurement($name): Point
55
55
return new Point ($ name );
56
56
}
57
57
58
- /** Create DataPoint instance from specified data.
59
- *
60
- * @param [Array] data
61
- * @return Point
58
+ /**
59
+ * Create DataPoint instance from specified data.
62
60
*/
63
- public static function fromArray ($ data ): ?Point
61
+ public static function fromArray (array $ data ): ?Point
64
62
{
65
63
if (!array_key_exists ('name ' , $ data )) {
66
64
return null ;
@@ -76,8 +74,8 @@ public static function fromArray($data): ?Point
76
74
77
75
/** Adds or replaces a tag value for a point.
78
76
*
79
- * @param [Object] key the tag name
80
- * @param [Object] value the tag value
77
+ * @param mixed $ key the tag name
78
+ * @param mixed $ value the tag value
81
79
* @return Point
82
80
*/
83
81
public function addTag ($ key , $ value ): Point
@@ -89,8 +87,8 @@ public function addTag($key, $value): Point
89
87
90
88
/** Adds or replaces a field value for a point.
91
89
*
92
- * @param [Object] key the tag name
93
- * @param [Object] value the tag value
90
+ * @param mixed $ key the tag name
91
+ * @param mixed $ value the tag value
94
92
* @return Point
95
93
*/
96
94
public function addField ($ key , $ value ): Point
@@ -102,8 +100,8 @@ public function addField($key, $value): Point
102
100
103
101
/** Updates the timestamp for the point.
104
102
*
105
- * @param [Object] time the timestamp
106
- * @param [ WritePrecision] precision the timestamp precision
103
+ * @param mixed $ time the timestamp
104
+ * @param WritePrecision::* $ precision the timestamp precision
107
105
* @return Point
108
106
*/
109
107
public function time ($ time , $ precision = null ): Point
@@ -116,9 +114,9 @@ public function time($time, $precision = null): Point
116
114
117
115
/** If there is no field then return null.
118
116
*
119
- * @return string representation of the point
117
+ * @return string|null representation of the point
120
118
*/
121
- public function toLineProtocol ()
119
+ public function toLineProtocol (): ? string
122
120
{
123
121
$ measurement = $ this ->escapeKey ($ this ->name , false );
124
122
@@ -149,7 +147,7 @@ public function toLineProtocol()
149
147
return $ lineProtocol ;
150
148
}
151
149
152
- private function appendTags ()
150
+ private function appendTags (): ? string
153
151
{
154
152
$ tags = '' ;
155
153
@@ -173,7 +171,7 @@ private function appendTags()
173
171
return $ tags ;
174
172
}
175
173
176
- private function appendFields ()
174
+ private function appendFields (): ? string
177
175
{
178
176
$ fields = '' ;
179
177
@@ -208,7 +206,7 @@ private function appendFields()
208
206
return rtrim ($ fields , ', ' );
209
207
}
210
208
211
- private function appendTime ()
209
+ private function appendTime (): ? string
212
210
{
213
211
if (!isset ($ this ->time )) {
214
212
return null ;
@@ -240,7 +238,7 @@ private function appendTime()
240
238
return ' ' . $ time ;
241
239
}
242
240
243
- private function escapeKey ($ key , $ escapeEqual = true )
241
+ private function escapeKey ($ key , $ escapeEqual = true ): string
244
242
{
245
243
$ escapeKeys = array (' ' => '\\ ' , ', ' => '\\, ' , "\\" => '\\\\' ,
246
244
"\n" => '\\n ' , "\r" => '\\r ' , "\t" => '\\t ' );
@@ -252,13 +250,13 @@ private function escapeKey($key, $escapeEqual = true)
252
250
return strtr ($ key , $ escapeKeys );
253
251
}
254
252
255
- private function escapeValue ($ value )
253
+ private function escapeValue ($ value ): string
256
254
{
257
255
$ escapeValues = array ('" ' => '\\" ' , "\\" => '\\\\' );
258
256
return strtr ($ value , $ escapeValues );
259
257
}
260
258
261
- private function isNullOrEmptyString ($ str )
259
+ private function isNullOrEmptyString ($ str ): bool
262
260
{
263
261
return (!is_string ($ str ) || trim ($ str ) === '' );
264
262
}
0 commit comments