Skip to content

Commit a20b65e

Browse files
committed
Replace psalm with phpstan
1 parent a402d9c commit a20b65e

8 files changed

Lines changed: 53 additions & 105 deletions

File tree

.github/workflows/php.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ jobs:
162162
with:
163163
# Should be the higest supported version, so we can use the newest tools
164164
php-version: '8.4'
165-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
166-
# optional performance gain for psalm: opcache
167-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, posix, spl, xml
165+
tools: composer, composer-require-checker, composer-unused, phpcs, phpstan
166+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, posix, spl, xml
168167

169168
- name: Setup problem matchers for PHP
170169
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
@@ -196,27 +195,13 @@ jobs:
196195
- name: PHP Code Sniffer
197196
run: phpcs
198197

199-
- name: Psalm
200-
continue-on-error: true
201-
run: |
202-
psalm -c psalm.xml \
203-
--show-info=true \
204-
--shepherd \
205-
--php-version=${{ steps.setup-php.outputs.php-version }}
206-
207-
- name: Psalm (testsuite)
198+
- name: PHPStan
208199
run: |
209-
psalm -c psalm-dev.xml \
210-
--show-info=true \
211-
--shepherd \
212-
--php-version=${{ steps.setup-php.outputs.php-version }}
200+
vendor/bin/phpstan analyze -c phpstan.neon
213201
214-
- name: Psalter
202+
- name: PHPStan (testsuite)
215203
run: |
216-
psalm --alter \
217-
--issues=UnnecessaryVarAnnotation \
218-
--dry-run \
219-
--php-version=${{ steps.setup-php.outputs.php-version }}
204+
vendor/bin/phpstan analyze -c phpstan-dev.neon
220205
221206
security:
222207
name: Security checks

phpstan-dev.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- tests

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src

psalm-dev.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

psalm.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Client.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@
1212

1313
class Client
1414
{
15-
/**
16-
* Our CDC domain.
17-
*
18-
* @var string
19-
*/
20-
private string $domain;
21-
2215
/**
2316
* The CDC server we send requests to.
2417
*
25-
* @var Server
18+
* @var \SimpleSAML\Module\cdc\Server
2619
*/
2720
private Server $server;
2821

@@ -32,17 +25,17 @@ class Client
3225
*
3326
* @param string $domain The domain we should query the server for.
3427
*/
35-
public function __construct(string $domain)
36-
{
37-
$this->domain = $domain;
28+
public function __construct(
29+
protected string $domain,
30+
) {
3831
$this->server = new Server($domain);
3932
}
4033

4134

4235
/**
4336
* Receive a CDC response.
4437
*
45-
* @return array|null The response, or NULL if no response is received.
38+
* @return array<mixed>|null The response, or NULL if no response is received.
4639
*/
4740
public function getResponse(): ?array
4841
{
@@ -55,7 +48,7 @@ public function getResponse(): ?array
5548
*
5649
* @param string $returnTo The URL we should return to afterwards.
5750
* @param string $op The operation we are performing.
58-
* @param array $params Additional parameters.
51+
* @param array<mixed> $params Additional parameters.
5952
*/
6053
public function sendRequest(string $returnTo, string $op, array $params = []): void
6154
{

src/Controller/CDC.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public function resume(Request $request): RunnableResponse
8888
}
8989

9090
$state = Auth\State::loadState($response['id'], 'cdc:resume');
91-
if (is_null($state)) {
92-
throw new Error\NoState();
93-
}
94-
9591
return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]);
9692
}
9793
}

src/Server.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
1212
use SimpleSAML\Utils;
1313

14+
use function array_search;
15+
use function base64_decode;
16+
use function base64_encode;
17+
use function explode;
18+
use function implode;
19+
use function intval;
20+
use function is_string;
21+
use function json_decode;
22+
use function json_encode;
23+
use function sha1;
24+
use function strlen;
25+
use function strval;
26+
use function time;
27+
use function var_export;
28+
1429
/**
1530
* CDC server class.
1631
*
@@ -82,7 +97,7 @@ public function __construct(string $domain)
8297
/**
8398
* Send a request to this CDC server.
8499
*
85-
* @param array $request The CDC request.
100+
* @param array $request<mixed> The CDC request.
86101
*/
87102
public function sendRequest(array $request): void
88103
{
@@ -97,7 +112,7 @@ public function sendRequest(array $request): void
97112
/**
98113
* Parse and validate response received from a CDC server.
99114
*
100-
* @return array|null The response, or NULL if no response is received.
115+
* @return array<mixed>|null The response, or NULL if no response is received.
101116
* @throws \SimpleSAML\Error\Exception
102117
*/
103118
public function getResponse(): ?array
@@ -139,22 +154,22 @@ public static function processRequest(): void
139154
/**
140155
* Handle a parsed CDC requst.
141156
*
142-
* @param array $request
157+
* @param array<mixed> $request
143158
* @throws \SimpleSAML\Error\Exception
144159
*/
145160
private function handleRequest(array $request): void
146161
{
147162
if (!isset($request['op'])) {
148163
throw new Error\BadRequest('Missing "op" in CDC request.');
149164
}
150-
$op = (string) $request['op'];
165+
$op = strval($request['op']);
151166

152167
Logger::info('Received CDC request with "op": ' . var_export($op, true));
153168

154169
if (!isset($request['return'])) {
155170
throw new Error\BadRequest('Missing "return" in CDC request.');
156171
}
157-
$return = (string) $request['return'];
172+
$ret = strval($request['return']);
158173

159174
switch ($op) {
160175
case 'append':
@@ -178,18 +193,18 @@ private function handleRequest(array $request): void
178193

179194
$response['op'] = $op;
180195
if (isset($request['id'])) {
181-
$response['id'] = (string) $request['id'];
196+
$response['id'] = strval($request['id']);
182197
}
183198
$response['domain'] = $this->domain;
184199

185-
$this->send($return, 'CDCResponse', $response);
200+
$this->send($ret, 'CDCResponse', $response);
186201
}
187202

188203

189204
/**
190205
* Handle an append request.
191206
*
192-
* @param array $request The request.
207+
* @param array<mixed> $request The request.
193208
* @throws \SimpleSAML\Error\BadRequest
194209
* @return string The response.
195210
*/
@@ -217,7 +232,7 @@ private function handleAppend(array $request): string
217232
/**
218233
* Handle a delete request.
219234
*
220-
* @param array $request The request.
235+
* @param array<mixed> $request The request.
221236
* @return string The response.
222237
*/
223238
private function handleDelete(array $request): string
@@ -238,8 +253,8 @@ private function handleDelete(array $request): string
238253
/**
239254
* Handle a read request.
240255
*
241-
* @param array $request The request.
242-
* @return array The response.
256+
* @param array<mixed> $request The request.
257+
* @return array<mixed> The response.
243258
*/
244259
private function handleRead(array $request): array
245260
{
@@ -257,7 +272,7 @@ private function handleRead(array $request): array
257272
*
258273
* @param string $parameter The name of the query parameter.
259274
* @throws \SimpleSAML\Error\BadRequest
260-
* @return array|null The response, or NULL if no response is received.
275+
* @return array<mixed>|null The response, or NULL if no response is received.
261276
*/
262277
private static function get(string $parameter): ?array
263278
{
@@ -267,7 +282,7 @@ private static function get(string $parameter): ?array
267282
$message = (string) $_REQUEST[$parameter];
268283
Assert::validBase64($message, ProtocolViolationException::class);
269284

270-
$message = @base64_decode($message);
285+
$message = @base64_decode($message, true);
271286
if ($message === false) {
272287
throw new Error\BadRequest('Error base64-decoding CDC message.');
273288
}
@@ -280,7 +295,7 @@ private static function get(string $parameter): ?array
280295
if (!isset($message['timestamp'])) {
281296
throw new Error\BadRequest('Missing timestamp in CDC message.');
282297
}
283-
$timestamp = (int) $message['timestamp'];
298+
$timestamp = intval($message['timestamp']);
284299

285300
if ($timestamp + 60 < time()) {
286301
throw new Error\BadRequest('CDC signature has expired.');
@@ -328,7 +343,7 @@ private function validate(string $parameter): void
328343
*
329344
* @param string $to The URL the message should be delivered to.
330345
* @param string $parameter The query parameter the message should be sent in.
331-
* @param array $message The CDC message.
346+
* @param array<mixed> $message The CDC message.
332347
*/
333348
private function send(string $to, string $parameter, array $message): void
334349
{
@@ -368,20 +383,20 @@ private function calcSignature(string $rawMessage): string
368383
/**
369384
* Get the IdP entities saved in the common domain cookie.
370385
*
371-
* @return array List of IdP entities.
386+
* @return string[] List of IdP entities.
372387
*/
373388
private function getCDC(): array
374389
{
375390
if (!isset($_COOKIE['_saml_idp'])) {
376391
return [];
377392
}
378393

379-
$ret = (string) $_COOKIE['_saml_idp'];
394+
$ret = strval($_COOKIE['_saml_idp']);
380395

381396
$ret = explode(' ', $ret);
382397
foreach ($ret as &$idp) {
383398
Assert::validBase64($idp, ProtocolViolationException::class);
384-
$idp = base64_decode($idp);
399+
$idp = base64_decode($idp, true);
385400
if ($idp === false) {
386401
// Not properly base64 encoded
387402
Logger::warning('CDC - Invalid base64-encoding of CDC entry.');

0 commit comments

Comments
 (0)