Skip to content

Commit 0afe0b1

Browse files
committed
feat: add PHPStan extensions
- detect deprecated functions - check PHPUnit
1 parent bb8e894 commit 0afe0b1

4 files changed

Lines changed: 34 additions & 13 deletions

File tree

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
"ext-gmp": "Optional for performance."
4343
},
4444
"require-dev": {
45-
"phpunit/phpunit": "^11.5.46|^12.5.2",
46-
"phpstan/phpstan": "^2.1.33",
4745
"friendsofphp/php-cs-fixer": "^v3.92.2",
48-
"symfony/polyfill-iconv": "^1.33",
49-
"phpstan/phpstan-strict-rules": "^2.0"
46+
"phpstan/phpstan": "^2.1.33",
47+
"phpstan/phpstan-deprecation-rules": "^2.0",
48+
"phpstan/phpstan-phpunit": "^2.0",
49+
"phpstan/phpstan-strict-rules": "^2.0",
50+
"phpunit/phpunit": "^11.5.46|^12.5.2",
51+
"symfony/polyfill-iconv": "^1.33"
5052
},
5153
"autoload": {
5254
"psr-4": {

phpstan.neon

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@ parameters:
22
level: 7
33
paths:
44
- src
5+
- tests
56
reportUnmatchedIgnoredErrors: false
67
ignoreErrors:
78
- identifier: missingType.iterableValue
9+
paths:
10+
- src/Encryption.php
11+
- src/MessageSentReport.php
12+
- src/Notification.php
13+
- src/Subscription.php
14+
- src/Utils.php
15+
- src/VAPID.php
16+
- src/WebPush.php
17+
- path: tests/
18+
identifiers:
19+
- argument.type
20+
- closure.unusedUse
21+
- foreach.valueOverwrite
22+
- missingType.iterableValue
23+
- property.dynamicName
24+
- staticMethod.dynamicCall
825
strictRules:
926
booleansInConditions: false
1027
disallowedEmpty: false
1128

1229
includes:
30+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
31+
- vendor/phpstan/phpstan-phpunit/extension.neon
32+
- vendor/phpstan/phpstan-phpunit/rules.neon
1333
- vendor/phpstan/phpstan-strict-rules/rules.neon

tests/PushServiceTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function browserProvider(): array
5555
/**
5656
* Selenium tests are flakey so add retries.
5757
*/
58-
public function retryTest($retryCount, $test): void
58+
public function retryTest(int $retryCount, callable $test): void
5959
{
6060
// just like above without checking the annotation
6161
for ($i = 0; $i < $retryCount; $i++) {
@@ -76,12 +76,12 @@ public function retryTest($retryCount, $test): void
7676
* Run integration tests with browsers
7777
*/
7878
#[dataProvider('browserProvider')]
79-
public function testBrowsers($browserId, $options): void
79+
public function testBrowsers(string $browserId, array $options): void
8080
{
8181
$this->retryTest(2, $this->createClosureTest($browserId, $options));
8282
}
8383

84-
protected function createClosureTest($browserId, $options): callable
84+
protected function createClosureTest(string $browserId, array $options): callable
8585
{
8686
return function () use ($browserId, $options): void {
8787
$this->webPush = new WebPush($options);
@@ -128,7 +128,6 @@ protected function createClosureTest($browserId, $options): callable
128128

129129
$subscription = new Subscription($endpoint, $p256dh, $auth, $contentEncoding);
130130
$report = $this->webPush->sendOneNotification($subscription, $payload);
131-
$this->assertInstanceOf(MessageSentReport::class, $report);
132131
$this->assertTrue($report->isSuccess());
133132

134133
$dataString = json_encode([
@@ -160,7 +159,7 @@ protected function createClosureTest($browserId, $options): callable
160159
};
161160
}
162161

163-
private function getResponse($ch)
162+
private function getResponse(CurlHandle $ch): mixed
164163
{
165164
$resp = curl_exec($ch);
166165

tests/WebPushTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ private static function setCiEnvironment(): void
120120
self::$keys['standard'] = $keys->{'p256dh'};
121121
}
122122

123-
/**
124-
* @throws ErrorException
125-
*/
126123
public static function notificationProvider(): array
127124
{
128125
self::setUpBeforeClass(); // dirty hack of PHPUnit limitation
129126

130127
return [
131-
[new Subscription(self::$endpoints['standard'] ?: '', self::$keys['standard'] ?: '', self::$tokens['standard'] ?: ''), '{"message":"Comment ça va ?","tag":"general"}'],
128+
[
129+
new Subscription(self::$endpoints['standard'] ?? '', self::$keys['standard'] ?? '', self::$tokens['standard'] ?? ''),
130+
'{"message":"Comment ça va ?","tag":"general"}',
131+
],
132132
];
133133
}
134134

0 commit comments

Comments
 (0)