Skip to content

Commit 600f6df

Browse files
authored
- Add PostgreSQL support in Storage/PDO.php (#162)
- Add PostgreSQL tests in github workflow - Fix type hints and types in doc blocks - Add phpstan ignoreErrors for Redis: phpstan/phpstan#11728 Signed-off-by: Alex <2646298@mail.ru>
1 parent 35d5a68 commit 600f6df

File tree

8 files changed

+250
-47
lines changed

8 files changed

+250
-47
lines changed

.github/workflows/tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ jobs:
1515

1616
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} - ${{ matrix.redis-version }}
1717

18+
# Service container with PostgreSQL
19+
services:
20+
postgres:
21+
image: postgres
22+
env:
23+
POSTGRES_PASSWORD: root
24+
POSTGRES_USER: root
25+
POSTGRES_DB: test
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
ports:
32+
- 5432:5432
33+
1834
env:
1935
# The hostname used to communicate with the Redis service container
2036
REDIS_HOST: redis
@@ -64,4 +80,11 @@ jobs:
6480
TEST_PDO_DSN: 'mysql:host=localhost;dbname=test'
6581
TEST_PDO_USERNAME: 'root'
6682
TEST_PDO_PASSWORD: 'root'
83+
run: vendor/bin/phpunit tests/Test/Prometheus/PDO
84+
85+
- name: Execute PDO tests with PostgreSQL
86+
env:
87+
TEST_PDO_DSN: 'pgsql:host=localhost;dbname=test'
88+
TEST_PDO_USERNAME: 'root'
89+
TEST_PDO_PASSWORD: 'root'
6790
run: vendor/bin/phpunit tests/Test/Prometheus/PDO

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ parameters:
66
paths:
77
- src
88
- tests
9+
ignoreErrors:
10+
- '#Call to method Redis::[a-zA-Z0-9_]+\(\) with incorrect case: [a-zA-Z0-9_]+#'

src/Prometheus/CollectorRegistry.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getMetricFamilySamples(bool $sortMetrics = true): array
9595
* @return Gauge
9696
* @throws MetricsRegistrationException
9797
*/
98-
public function registerGauge(string $namespace, string $name, string $help, $labels = []): Gauge
98+
public function registerGauge(string $namespace, string $name, string $help, array $labels = []): Gauge
9999
{
100100
$metricIdentifier = self::metricIdentifier($namespace, $name);
101101
if (isset($this->gauges[$metricIdentifier])) {
@@ -136,7 +136,7 @@ public function getGauge(string $namespace, string $name): Gauge
136136
* @return Gauge
137137
* @throws MetricsRegistrationException
138138
*/
139-
public function getOrRegisterGauge(string $namespace, string $name, string $help, $labels = []): Gauge
139+
public function getOrRegisterGauge(string $namespace, string $name, string $help, array $labels = []): Gauge
140140
{
141141
try {
142142
$gauge = $this->getGauge($namespace, $name);
@@ -155,7 +155,7 @@ public function getOrRegisterGauge(string $namespace, string $name, string $help
155155
* @return Counter
156156
* @throws MetricsRegistrationException
157157
*/
158-
public function registerCounter(string $namespace, string $name, string $help, $labels = []): Counter
158+
public function registerCounter(string $namespace, string $name, string $help, array $labels = []): Counter
159159
{
160160
$metricIdentifier = self::metricIdentifier($namespace, $name);
161161
if (isset($this->counters[$metricIdentifier])) {
@@ -196,7 +196,7 @@ public function getCounter(string $namespace, string $name): Counter
196196
* @return Counter
197197
* @throws MetricsRegistrationException
198198
*/
199-
public function getOrRegisterCounter(string $namespace, string $name, string $help, $labels = []): Counter
199+
public function getOrRegisterCounter(string $namespace, string $name, string $help, array $labels = []): Counter
200200
{
201201
try {
202202
$counter = $this->getCounter($namespace, $name);
@@ -211,7 +211,7 @@ public function getOrRegisterCounter(string $namespace, string $name, string $he
211211
* @param string $name e.g. duration_seconds
212212
* @param string $help e.g. A histogram of the duration in seconds.
213213
* @param string[] $labels e.g. ['controller', 'action']
214-
* @param mixed[]|null $buckets e.g. [100, 200, 300]
214+
* @param float[]|null $buckets e.g. [100.0, 200.0, 300.0]
215215
*
216216
* @return Histogram
217217
* @throws MetricsRegistrationException
@@ -221,7 +221,7 @@ public function registerHistogram(
221221
string $name,
222222
string $help,
223223
array $labels = [],
224-
array $buckets = null
224+
?array $buckets = null
225225
): Histogram {
226226
$metricIdentifier = self::metricIdentifier($namespace, $name);
227227
if (isset($this->histograms[$metricIdentifier])) {
@@ -259,7 +259,7 @@ public function getHistogram(string $namespace, string $name): Histogram
259259
* @param string $name e.g. duration_seconds
260260
* @param string $help e.g. A histogram of the duration in seconds.
261261
* @param string[] $labels e.g. ['controller', 'action']
262-
* @param float[]|null $buckets e.g. [100, 200, 300]
262+
* @param float[]|null $buckets e.g. [100.0, 200.0, 300.0]
263263
*
264264
* @return Histogram
265265
* @throws MetricsRegistrationException
@@ -269,7 +269,7 @@ public function getOrRegisterHistogram(
269269
string $name,
270270
string $help,
271271
array $labels = [],
272-
array $buckets = null
272+
?array $buckets = null
273273
): Histogram {
274274
try {
275275
$histogram = $this->getHistogram($namespace, $name);
@@ -297,7 +297,7 @@ public function registerSummary(
297297
string $help,
298298
array $labels = [],
299299
int $maxAgeSeconds = 600,
300-
array $quantiles = null
300+
?array $quantiles = null
301301
): Summary {
302302
$metricIdentifier = self::metricIdentifier($namespace, $name);
303303
if (isset($this->summaries[$metricIdentifier])) {
@@ -348,7 +348,7 @@ public function getOrRegisterSummary(
348348
string $help,
349349
array $labels = [],
350350
int $maxAgeSeconds = 600,
351-
array $quantiles = null
351+
?array $quantiles = null
352352
): Summary {
353353
try {
354354
$summary = $this->getSummary($namespace, $name);

src/Prometheus/Counter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function inc(array $labels = []): void
2828

2929
/**
3030
* @param int|float $count e.g. 2
31-
* @param mixed[] $labels e.g. ['status', 'opcode']
31+
* @param string[] $labels e.g. ['status', 'opcode']
3232
*/
3333
public function incBy($count, array $labels = []): void
3434
{

src/Prometheus/Gauge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Gauge extends Collector
1111
const TYPE = 'gauge';
1212

1313
/**
14-
* @param double $value e.g. 123
14+
* @param float $value e.g. 123.0
1515
* @param string[] $labels e.g. ['status', 'opcode']
1616
*/
1717
public function set(float $value, array $labels = []): void

src/Prometheus/Histogram.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
string $name,
3131
string $help,
3232
array $labels = [],
33-
array $buckets = null
33+
?array $buckets = null
3434
) {
3535
parent::__construct($adapter, $namespace, $name, $help, $labels);
3636

@@ -113,7 +113,7 @@ public static function exponentialBuckets(float $start, float $growthFactor, int
113113
}
114114

115115
/**
116-
* @param double $value e.g. 123
116+
* @param float $value e.g. 123.0
117117
* @param string[] $labels e.g. ['status', 'opcode']
118118
*/
119119
public function observe(float $value, array $labels = []): void

0 commit comments

Comments
 (0)