Skip to content

Commit 57887d3

Browse files
committed
PHPStan 2.0
1 parent 41e8093 commit 57887d3

File tree

9 files changed

+100
-30
lines changed

9 files changed

+100
-30
lines changed

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
"ratchet/rfc6455": "^0.3.1",
1616
"react/event-loop": "^1.3",
1717
"react/socket": "^1.11",
18-
"symfony/http-foundation": "^6.4 || ^7.0",
19-
"symfony/routing": "^6.4 || ^7.0"
18+
"symfony/http-foundation": "^6.4 || ^7.1",
19+
"symfony/routing": "^6.4 || ^7.1"
2020
},
2121
"require-dev": {
2222
"ext-session": "*",
2323
"ext-sockets": "*",
24-
"phpstan/extension-installer": "^1.3.1",
25-
"phpstan/phpstan": "1.12.7",
26-
"phpstan/phpstan-phpunit": "1.4.0",
27-
"phpunit/phpunit": "11.4.3",
24+
"phpstan/extension-installer": "^1.4.3",
25+
"phpstan/phpstan": "2.0.3",
26+
"phpstan/phpstan-phpunit": "2.0.1",
27+
"phpunit/phpunit": "11.5.1",
2828
"psr/container": "^1.0 || ^2.0",
2929
"psr/event-dispatcher": "^1.0",
30-
"rector/rector": "1.2.8",
31-
"symfony/security-core": "^6.4 || ^7.0"
30+
"rector/rector": "2.0.3",
31+
"symfony/security-core": "^6.4 || ^7.1"
3232
},
3333
"conflict": {
3434
"psr/container": ">=3.0",

phpstan-baseline.neon

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,121 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Access to an undefined property React\\\\Socket\\\\ConnectionInterface\\:\\:\\$stream\\.$#"
4+
message: '#^Access to an undefined property React\\Socket\\ConnectionInterface\:\:\$stream\.$#'
5+
identifier: property.notFound
56
count: 1
67
path: src/ReactPhpServer.php
78

89
-
9-
message: "#^Property BabDev\\\\WebSocket\\\\Server\\\\ReactPhpServer\\:\\:\\$socket is never read, only written\\.$#"
10+
message: '#^Cannot cast mixed to int\.$#'
11+
identifier: cast.int
1012
count: 1
1113
path: src/ReactPhpServer.php
1214

1315
-
14-
message: "#^Offset 1 does not exist on array\\{0\\: string, 1\\?\\: numeric\\-string\\}\\.$#"
16+
message: '#^Property BabDev\\WebSocket\\Server\\ReactPhpServer\:\:\$socket is never read, only written\.$#'
17+
identifier: property.onlyWritten
18+
count: 1
19+
path: src/ReactPhpServer.php
20+
21+
-
22+
message: '#^Parameter \#1 \$id of method Symfony\\Component\\HttpFoundation\\Session\\SessionInterface\:\:setId\(\) expects string, mixed given\.$#'
23+
identifier: argument.type
24+
count: 1
25+
path: src/Session/Middleware/InitializeSession.php
26+
27+
-
28+
message: '#^Offset 1 might not exist on array\{0\: string, 1\?\: numeric\-string\}\.$#'
29+
identifier: offsetAccess.notFound
1530
count: 1
1631
path: src/Session/Reader/PhpReader.php
1732

1833
-
19-
message: "#^Method BabDev\\\\WebSocket\\\\Server\\\\Session\\\\Reader\\\\PhpSerializeReader\\:\\:read\\(\\) should return array but returns mixed\\.$#"
34+
message: '#^Method BabDev\\WebSocket\\Server\\Session\\Reader\\PhpSerializeReader\:\:read\(\) should return array but returns mixed\.$#'
35+
identifier: return.type
2036
count: 1
2137
path: src/Session/Reader/PhpSerializeReader.php
2238

2339
-
24-
message: "#^Property BabDev\\\\WebSocket\\\\Server\\\\Session\\\\Storage\\\\Proxy\\\\ReadOnlySessionHandlerProxy\\:\\:\\$sessionName \\(string\\) does not accept mixed\\.$#"
40+
message: '#^Property BabDev\\WebSocket\\Server\\Session\\Storage\\Proxy\\ReadOnlySessionHandlerProxy\:\:\$sessionName \(string\) does not accept mixed\.$#'
41+
identifier: assign.propertyType
2542
count: 1
2643
path: src/Session/Storage/Proxy/ReadOnlySessionHandlerProxy.php
2744

2845
-
29-
message: "#^Property Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:\\$saveHandlerName \\(string\\|null\\) does not accept mixed\\.$#"
46+
message: '#^Property Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:\$saveHandlerName \(string\|null\) does not accept mixed\.$#'
47+
identifier: assign.propertyType
3048
count: 1
3149
path: src/Session/Storage/Proxy/ReadOnlySessionHandlerProxy.php
3250

3351
-
34-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:getId\\(\\)\\.$#"
52+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:getId\(\)\.$#'
53+
identifier: method.notFound
3554
count: 2
3655
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
3756

3857
-
39-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:getName\\(\\)\\.$#"
58+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:getName\(\)\.$#'
59+
identifier: method.notFound
4060
count: 2
4161
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
4262

4363
-
44-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:isSessionHandlerInterface\\(\\)\\.$#"
64+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:isSessionHandlerInterface\(\)\.$#'
65+
identifier: method.notFound
4566
count: 2
4667
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
4768

4869
-
49-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:isWrapper\\(\\)\\.$#"
70+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:isWrapper\(\)\.$#'
71+
identifier: method.notFound
5072
count: 2
5173
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
5274

5375
-
54-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:open\\(\\)\\.$#"
76+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:open\(\)\.$#'
77+
identifier: method.notFound
5578
count: 1
5679
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
5780

5881
-
59-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:read\\(\\)\\.$#"
82+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:read\(\)\.$#'
83+
identifier: method.notFound
6084
count: 1
6185
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
6286

6387
-
64-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:setActive\\(\\)\\.$#"
88+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:setActive\(\)\.$#'
89+
identifier: method.notFound
6590
count: 2
6691
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
6792

6893
-
69-
message: "#^Call to an undefined method SessionHandlerInterface\\|Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\Proxy\\\\AbstractProxy\\:\\:setId\\(\\)\\.$#"
94+
message: '#^Call to an undefined method SessionHandlerInterface\|Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy\:\:setId\(\)\.$#'
95+
identifier: method.notFound
7096
count: 1
7197
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
7298

7399
-
74-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
100+
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
101+
identifier: argument.type
75102
count: 1
76103
path: src/Session/Storage/ReadOnlyNativeSessionStorage.php
77104

78105
-
79-
message: "#^Property BabDev\\\\WebSocket\\\\Server\\\\Tests\\\\ReactPhpServerTest\\:\\:\\$server is never read, only written\\.$#"
106+
message: '#^Parameter \#1 \$uri of method BabDev\\WebSocket\\Server\\WAMP\\WAMPConnection\:\:getUri\(\) expects string, array\<int\<0, max\>\|string, mixed\>\|bool\|string\|null given\.$#'
107+
identifier: argument.type
108+
count: 1
109+
path: src/WAMP/Middleware/ParseWAMPMessage.php
110+
111+
-
112+
message: '#^Parameter \#4 \$exclude of method BabDev\\WebSocket\\Server\\WAMPServerMiddleware\:\:onPublish\(\) expects list\<string\>, array\<int\<0, max\>\|string, mixed\> given\.$#'
113+
identifier: argument.type
114+
count: 1
115+
path: src/WAMP/Middleware/ParseWAMPMessage.php
116+
117+
-
118+
message: '#^Property BabDev\\WebSocket\\Server\\Tests\\ReactPhpServerTest\:\:\$server is never read, only written\.$#'
119+
identifier: property.onlyWritten
80120
count: 1
81121
path: tests/ReactPhpServerTest.php

src/Application.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ public function withSession(SessionFactoryInterface $sessionFactory, ?OptionsHan
172172
*/
173173
public function allowAddress(string $address): self
174174
{
175-
$this->blockedAddresses = array_filter($this->blockedAddresses, static fn (string $blockedAddress): bool => $blockedAddress !== $address);
175+
$this->blockedAddresses = array_values(
176+
array_filter(
177+
$this->blockedAddresses,
178+
/** @var non-empty-string $blockedAddress */
179+
static fn (string $blockedAddress): bool => $blockedAddress !== $address,
180+
),
181+
);
176182

177183
return $this;
178184
}
@@ -221,7 +227,13 @@ public function allowOrigin(string $origin): self
221227
*/
222228
public function removeAllowedOrigin(string $origin): self
223229
{
224-
$this->allowedOrigins = array_filter($this->allowedOrigins, static fn (string $allowedOrigin): bool => $allowedOrigin !== $origin);
230+
$this->allowedOrigins = array_values(
231+
array_filter(
232+
$this->allowedOrigins,
233+
/** @var non-empty-string $allowedOrigin */
234+
static fn (string $allowedOrigin): bool => $allowedOrigin !== $origin,
235+
),
236+
);
225237

226238
return $this;
227239
}

src/Http/GuzzleRequestParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
*/
3131
public function parse(Connection $connection, string $data): ?RequestInterface
3232
{
33+
/** @var string $buffer */
3334
$buffer = $connection->getAttributeStore()->get('http.buffer', '');
3435
$buffer .= $data;
3536

src/Http/Middleware/RejectBlockedIpAddress.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public function onError(Connection $connection, \Throwable $throwable): void
7474
*/
7575
public function allowAddress(string $address): void
7676
{
77-
$this->blockedAddresses = array_filter($this->blockedAddresses, static fn (string $blockedAddress): bool => $blockedAddress !== $address);
77+
$this->blockedAddresses = array_values(
78+
array_filter(
79+
$this->blockedAddresses,
80+
/** @var non-empty-string $blockedAddress */
81+
static fn (string $blockedAddress): bool => $blockedAddress !== $address,
82+
),
83+
);
7884
}
7985

8086
/**

src/Http/Middleware/RestrictToAllowedOrigins.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public function allowOrigin(string $origin): void
104104
*/
105105
public function removeAllowedOrigin(string $origin): void
106106
{
107-
$this->allowedOrigins = array_filter($this->allowedOrigins, static fn (string $allowedOrigin): bool => $allowedOrigin !== $origin);
107+
$this->allowedOrigins = array_values(
108+
array_filter(
109+
$this->allowedOrigins,
110+
/** @var non-empty-string $allowedOrigin */
111+
static fn (string $allowedOrigin): bool => $allowedOrigin !== $origin,
112+
),
113+
);
108114
}
109115
}

src/Session/Middleware/InitializeSession.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function parseCookieHeader(string $cookieHeader): array
131131
throw new InvalidRequestHeader('Cookie', $cookieHeader, 'Invalid Cookie header.');
132132
}
133133

134-
/** @var int $separatorPosition */
134+
/** @var int<0, max> $separatorPosition */
135135
$separatorPosition = strpos($cookie, '=');
136136

137137
$key = ltrim(substr($cookie, 0, $separatorPosition));

src/Session/Storage/Proxy/ReadOnlySessionHandlerProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function close(): bool
6262
return $this->handler->close();
6363
}
6464

65-
public function read(string $id): string|false
65+
public function read(string $id): string
6666
{
6767
return $this->handler->read($id);
6868
}

src/WAMP/Middleware/ParseWAMPMessage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function onMessage(Connection $connection, string $data): void
7979
$decoratedConnection = $this->connections[$connection];
8080

8181
try {
82+
/** @var array{0: MessageType::*, 1: string, 2?: array<string, mixed>|string, 3?: bool|list<string>|array<string, mixed>, 4?: list<string>} $message */
8283
$message = json_decode($data, true, 512, \JSON_THROW_ON_ERROR);
8384
} catch (\JsonException $exception) {
8485
throw new InvalidMessage('Invalid WAMP message.', $exception->getCode(), $exception);
@@ -94,6 +95,8 @@ public function onMessage(Connection $connection, string $data): void
9495

9596
switch ($message[0]) {
9697
case MessageType::PREFIX:
98+
\assert(isset($message[2]));
99+
97100
/** @var array<string, string> $prefixes */
98101
$prefixes = $decoratedConnection->getAttributeStore()->get('wamp.prefixes', []);
99102
$prefixes[$message[1]] = $message[2];
@@ -126,6 +129,8 @@ public function onMessage(Connection $connection, string $data): void
126129
break;
127130

128131
case MessageType::PUBLISH:
132+
\assert(isset($message[2]));
133+
129134
$exclude = $message[3] ?? null;
130135

131136
if (!\is_array($exclude)) {

0 commit comments

Comments
 (0)