Skip to content

Commit 0f0b586

Browse files
committed
fix: add phpdocs
Signed-off-by: Mateusz Cholewka <mateusz@cholewka.com.pl>
1 parent 299399d commit 0f0b586

File tree

5 files changed

+57
-16
lines changed

5 files changed

+57
-16
lines changed

src/Prometheus/Storage/AbstractRedis.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public function wipeStorage(): void
5656
$searchPattern = '';
5757

5858
$globalPrefix = $this->redis->getOption(RedisClient::OPT_PREFIX);
59-
// @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int
6059
if (is_string($globalPrefix)) {
6160
$searchPattern .= $globalPrefix;
6261
}
@@ -183,15 +182,15 @@ public function updateSummary(array $data): void
183182
if ($json === false) {
184183
throw new RuntimeException(json_last_error_msg());
185184
}
186-
$this->redis->setNx($metaKey, $json); /** @phpstan-ignore-line */
185+
$this->redis->setNx($metaKey, $json);
187186

188187
// store value key
189188
$valueKey = $summaryKey.':'.$this->valueKey($data);
190189
$json = json_encode($this->encodeLabelValues($data['labelValues']));
191190
if ($json === false) {
192191
throw new RuntimeException(json_last_error_msg());
193192
}
194-
$this->redis->setNx($valueKey, $json); /** @phpstan-ignore-line */
193+
$this->redis->setNx($valueKey, $json);
195194

196195
// trick to handle uniqid collision
197196
$done = false;
@@ -370,12 +369,10 @@ protected function collectHistograms(): array
370369

371370
protected function removePrefixFromKey(string $key): string
372371
{
373-
// @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int
374372
if ($this->redis->getOption(RedisClient::OPT_PREFIX) === null) {
375373
return $key;
376374
}
377375

378-
// @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int
379376
return substr($key, strlen($this->redis->getOption(RedisClient::OPT_PREFIX)));
380377
}
381378

src/Prometheus/Storage/Predis.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Predis extends AbstractRedis
4545
/**
4646
* Redis constructor.
4747
*
48+
* @param mixed[] $parameters
4849
* @param mixed[] $options
4950
*/
5051
public function __construct(array $parameters = [], array $options = [])
@@ -71,7 +72,7 @@ public static function fromExistingConnection(Client $client): self
7172
];
7273

7374
$self = new self;
74-
$self->redis = new PredisClient($client, self::$defaultParameters, $allOptions);
75+
$self->redis = new PredisClient($client, $allOptions);
7576

7677
return $self;
7778
}

src/Prometheus/Storage/RedisClients/PHPRedis.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@ class PHPRedis implements RedisClient
1313
*/
1414
private $redis;
1515

16+
/**
17+
* @var mixed[]
18+
*/
1619
private $options = [];
1720

1821
/**
1922
* @var bool
2023
*/
2124
private $connectionInitialized = false;
2225

26+
/**
27+
* @param mixed[] $options
28+
*/
2329
public function __construct(\Redis $redis, array $options)
2430
{
2531
$this->redis = $redis;
2632
$this->options = $options;
2733
}
2834

35+
/**
36+
* @param mixed[] $options
37+
*/
2938
public static function create(array $options): self
3039
{
3140
$redis = new \Redis;
@@ -43,22 +52,22 @@ public function eval(string $script, array $args = [], int $num_keys = 0): void
4352
$this->redis->eval($script, $args, $num_keys);
4453
}
4554

46-
public function set(string $key, mixed $value, mixed $options = null): void
55+
public function set(string $key, mixed $value, mixed $options = null): bool
4756
{
48-
$this->redis->set($key, $value, $options);
57+
return $this->redis->set($key, $value, $options);
4958
}
5059

5160
public function setNx(string $key, mixed $value): void
5261
{
53-
$this->redis->setNx($key, $value);
62+
$this->redis->setNx($key, $value); /** @phpstan-ignore-line */
5463
}
5564

5665
public function hSetNx(string $key, string $field, mixed $value): bool
5766
{
5867
return $this->redis->hSetNx($key, $field, $value);
5968
}
6069

61-
public function sMembers(string $key): array|false
70+
public function sMembers(string $key): array
6271
{
6372
return $this->redis->sMembers($key);
6473
}

src/Prometheus/Storage/RedisClients/Predis.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ class Predis implements RedisClient
1212
RedisClient::OPT_PREFIX => 'prefix',
1313
];
1414

15+
/**
16+
* @var Client
17+
*/
1518
private $client;
1619

20+
/**
21+
* @var mixed[]
22+
*/
1723
private $options = [];
1824

25+
/**
26+
* @param mixed[] $options
27+
*/
1928
public function __construct(Client $redis, array $options)
2029
{
2130
$this->client = $redis;
2231

2332
$this->options = $options;
2433
}
2534

35+
/**
36+
* @param mixed[] $parameters
37+
* @param mixed[] $options
38+
*/
2639
public static function create(array $parameters, array $options): self
2740
{
2841
$redisClient = new Client($parameters, $options);
@@ -46,11 +59,17 @@ public function eval(string $script, array $args = [], int $num_keys = 0): void
4659
$this->client->eval($script, $num_keys, ...$args);
4760
}
4861

49-
public function set(string $key, mixed $value, mixed $options = null): void
62+
public function set(string $key, mixed $value, mixed $options = null): bool
5063
{
51-
$this->client->set($key, $value, ...$this->flattenFlags($options));
64+
$result = $this->client->set($key, $value, ...$this->flattenFlags($options));
65+
66+
return (string) $result === 'OK';
5267
}
5368

69+
/**
70+
* @param array<int|string, mixed> $flags
71+
* @return mixed[]
72+
*/
5473
private function flattenFlags(array $flags): array
5574
{
5675
$result = [];
@@ -73,10 +92,10 @@ public function setNx(string $key, mixed $value): void
7392

7493
public function hSetNx(string $key, string $field, mixed $value): bool
7594
{
76-
return $this->hsetnx($key, $field, $value);
95+
return $this->hSetNx($key, $field, $value);
7796
}
7897

79-
public function sMembers(string $key): array|false
98+
public function sMembers(string $key): array
8099
{
81100
return $this->client->smembers($key);
82101
}

src/Prometheus/Storage/RedisClients/RedisClient.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@ interface RedisClient
1212

1313
public function getOption(int $option): mixed;
1414

15+
/**
16+
* @param mixed[] $args
17+
*/
1518
public function eval(string $script, array $args = [], int $num_keys = 0): void;
1619

17-
public function set(string $key, mixed $value, mixed $options = null): void;
20+
public function set(string $key, mixed $value, mixed $options = null): bool;
1821

1922
public function setNx(string $key, mixed $value): void;
2023

2124
public function hSetNx(string $key, string $field, mixed $value): bool;
2225

23-
public function sMembers(string $key): array|false;
26+
/**
27+
* @return string[]
28+
*/
29+
public function sMembers(string $key): array;
2430

31+
/**
32+
* @return array<string, string>|false
33+
*/
2534
public function hGetAll(string $key): array|false;
2635

36+
/**
37+
* @return string[]
38+
*/
2739
public function keys(string $pattern);
2840

2941
public function get(string $key): mixed;
3042

43+
/**
44+
* @param string|string[] $key
45+
*/
3146
public function del(array|string $key, string ...$other_keys): void;
3247

3348
public function ensureOpenConnection(): void;

0 commit comments

Comments
 (0)