Skip to content

Commit 763a2bc

Browse files
authored
ci: make CI pass (#109)
- rework phpstan - check multiple php versions - fix errors Signed-off-by: Simon Podlipsky <simon@podlipsky.net>
1 parent cc0ba6d commit 763a2bc

File tree

8 files changed

+76
-19
lines changed

8 files changed

+76
-19
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/examples/ export-ignore
55
/nginx/ export-ignore
66
/php-fpm/ export-ignore
7+
/phpstan/ export-ignore
78
/tests/ export-ignore
89
.gitattributes export-ignore
910
.gitignore export-ignore

.github/workflows/checks.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on: [ push, pull_request ]
55
jobs:
66
test:
77
runs-on: ubuntu-latest
8-
strategy:
9-
fail-fast: true
108

119
name: Code Checks
1210
steps:
@@ -29,5 +27,36 @@ jobs:
2927
run: composer install --prefer-dist --no-interaction --no-suggest
3028
- name: Run PHP Code Sniffer
3129
run: ./vendor/bin/phpcs
30+
31+
phpstan:
32+
runs-on: ubuntu-latest
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
php:
37+
- "7.4"
38+
- "8.0"
39+
- "8.1"
40+
- "8.2"
41+
name: PHPStan on PHP ${{ matrix.php }}
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v2
45+
46+
- name: Cache dependencies
47+
uses: actions/cache@v2
48+
with:
49+
path: ~/.composer/cache/files
50+
key: dependencies-code-checks
51+
52+
- name: Setup PHP
53+
uses: shivammathur/setup-php@v2
54+
with:
55+
php-version: ${{ matrix.php }}
56+
coverage: none
57+
tools: "cs2pr"
58+
59+
- name: Install dependencies
60+
run: composer install --prefer-dist --no-interaction --no-suggest
3261
- name: Run PHPStan
33-
run: php vendor/bin/phpstan analyse --autoload-file tests/bootstrap.php
62+
run: "vendor/bin/phpstan analyse --autoload-file tests/bootstrap.php --error-format=checkstyle | cs2pr"

phpstan.neon.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
includes:
2+
- phpstan/include-by-php-version.php
3+
14
parameters:
25
level: 8
36
paths:
47
- src
58
- tests
6-
reportUnmatchedIgnoredErrors: false
7-
ignoreErrors:
8-
-
9-
# REDIS stuff only runs with it available
10-
'#Constant REDIS_HOST not found\.#'

phpstan/include-by-php-version.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$includes = [];
6+
7+
if (PHP_VERSION_ID >= 70400) {
8+
$includes[] = __DIR__ . '/php-74.neon';
9+
}
10+
11+
if (PHP_VERSION_ID >= 80000) {
12+
$includes[] = __DIR__ . '/php-80.neon';
13+
}
14+
15+
$config = [];
16+
$config['includes'] = $includes;
17+
$config['parameters']['phpVersion'] = PHP_VERSION_ID;
18+
19+
return $config;

phpstan/php-74.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Strict comparison using === between non\\-empty\\-array\\<int, string\\> and false will always evaluate to false\\.$#"
5+
count: 1
6+
path: ../src/Prometheus/Storage/RedisNg.php

phpstan/php-80.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Strict comparison using === between array\\<string, mixed\\> and false will always evaluate to false\\.$#"
5+
count: 1
6+
path: ../src/Prometheus/RenderTextFormat.php

src/Prometheus/RenderTextFormat.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ private function escapeAllLabels(array $labelNames, Sample $sample): array
6767

6868
$labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());
6969

70-
/** @phpstan-ignore-next-line */
7170
if ($labels === false) {
7271
throw new RuntimeException('Unable to combine labels.');
7372
}

src/Prometheus/Storage/RedisNg.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ public function updateSummary(array $data): void
291291
if (false === $json) {
292292
throw new RuntimeException(json_last_error_msg());
293293
}
294-
$this->redis->setNx($metaKey, $json);
295-
/** @phpstan-ignore-line */
294+
$this->redis->setnx($metaKey, $json);
296295

297296
// store value key
298297
$valueKey = $summaryKey . ':' . $this->valueKey($data);
@@ -301,8 +300,7 @@ public function updateSummary(array $data): void
301300
if (false === $json) {
302301
throw new RuntimeException(json_last_error_msg());
303302
}
304-
$this->redis->setNx($valueKey, $json);
305-
/** @phpstan-ignore-line */
303+
$this->redis->setnx($valueKey, $json);
306304

307305
// trick to handle uniqid collision
308306
$done = false;
@@ -528,10 +526,15 @@ private function collectSummaries(): array
528526
}
529527
}
530528
if (count($samples) === 0) {
531-
$this->redis->del($valueKey);
529+
if (isset($valueKey)) {
530+
$this->redis->del($valueKey);
531+
}
532+
532533
continue;
533534
}
534535

536+
assert(isset($decodedLabelValues));
537+
535538
// Compute quantiles
536539
sort($samples);
537540
foreach ($data['quantiles'] as $quantile) {
@@ -560,11 +563,7 @@ private function collectSummaries(): array
560563
];
561564

562565

563-
if (count($data['samples']) > 0) {
564-
$summaries[] = $data;
565-
} else {
566-
$this->redis->del($metaKey);
567-
}
566+
$summaries[] = $data;
568567
}
569568
return $summaries;
570569
}

0 commit comments

Comments
 (0)