Skip to content

Commit 70893cd

Browse files
committed
Replace Psalm with PHPStan
1 parent 510067e commit 70893cd

File tree

8 files changed

+46
-123
lines changed

8 files changed

+46
-123
lines changed

.gitattributes

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ codecov.yml export-ignore
55
.editorconfig export-ignore
66
.gitattributes export-ignore
77
.gitignore export-ignore
8-
psalm.xml export-ignore
9-
psalm-dev.xml export-ignore
8+
phpstan.neon export-ignore
9+
phpstan-dev.neon export-ignore
10+
phpstan-baseline.neon export-ignore
11+
phpstan-baseline-dev.neon export-ignore
1012
phpcs.xml export-ignore
1113
phpunit.xml export-ignore
1214
.php_cs.dist export-ignore

.github/workflows/php.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ jobs:
170170
with:
171171
# Should be the higest supported version, so we can use the newest tools
172172
php-version: '8.5'
173-
tools: composer, composer-require-checker, composer-unused, psalm
174-
# optional performance gain for psalm: opcache
175-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, opcache, openssl, pcre, spl, xml \
173+
tools: composer, composer-require-checker, composer-unused
174+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, openssl, pcre, spl, xml \
176175
krb5-php/pecl-authentication-krb5@master
177176

178177
- name: Setup problem matchers for PHP
@@ -205,27 +204,13 @@ jobs:
205204
- name: PHP Code Sniffer
206205
run: vendor/bin/phpcs
207206

208-
- name: Psalm
209-
continue-on-error: true
210-
run: |
211-
psalm -c psalm.xml \
212-
--show-info=true \
213-
--shepherd \
214-
--php-version=${{ steps.setup-php.outputs.php-version }}
215-
216-
- name: Psalm (testsuite)
207+
- name: PHPStan
217208
run: |
218-
psalm -c psalm-dev.xml \
219-
--show-info=true \
220-
--shepherd \
221-
--php-version=${{ steps.setup-php.outputs.php-version }}
209+
vendor/bin/phpstan analyze -c phpstan.neon --debug
222210
223-
- name: Psalter
211+
- name: PHPStan (testsuite)
224212
run: |
225-
psalm --alter \
226-
--issues=UnnecessaryVarAnnotation \
227-
--dry-run \
228-
--php-version=${{ steps.setup-php.outputs.php-version }}
213+
vendor/bin/phpstan analyze -c phpstan-dev.neon --debug
229214
230215
security:
231216
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: 8
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 & 27 deletions
This file was deleted.

psalm.xml

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

src/Auth/Source/Negotiate.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class Negotiate extends Auth\Source
5050
/** @var string|integer|null */
5151
protected $spn = null;
5252

53-
/** @var array|null */
53+
/** @var string[]|null */
5454
protected ?array $subnet = null;
5555

56-
/** @var array */
56+
/** @var string[] */
5757
private array $realms;
5858

5959
/** @var string[] */
@@ -66,8 +66,8 @@ class Negotiate extends Auth\Source
6666
/**
6767
* Constructor for this authentication source.
6868
*
69-
* @param array $info Information about this authentication source.
70-
* @param array $config The configuration of the module
69+
* @param array<mixed> $info Information about this authentication source.
70+
* @param array<mixed> $config The configuration of the module
7171
*
7272
* @throws \Exception If the KRB5 extension is not installed or active.
7373
*/
@@ -101,7 +101,7 @@ public function __construct(array $info, array $config)
101101
*
102102
* LDAP is used as a user metadata source.
103103
*
104-
* @param array &$state Information about the current authentication.
104+
* @param array<mixed> &$state Information about the current authentication.
105105
*/
106106
public function authenticate(array &$state): void
107107
{
@@ -151,7 +151,7 @@ public function authenticate(array &$state): void
151151
Logger::debug('Negotiate - authenticate(): No "Negotiate" found. Skipping.');
152152
} else {
153153
// attempt Kerberos authentication
154-
$reply = null;
154+
$reply = $auth = null;
155155

156156
try {
157157
if (version_compare(phpversion('krb5'), '1.1.6', '<')) {
@@ -178,7 +178,7 @@ public function authenticate(array &$state): void
178178
}
179179
}
180180

181-
if (!$auth->isChannelBound()) {
181+
if ($auth === null || !$auth->isChannelBound()) {
182182
throw new Error\Exception(
183183
'Negotiate - authenticate(): Failed to perform channel binding using '
184184
. 'any of the configured certificate hashes.',
@@ -189,15 +189,13 @@ public function authenticate(array &$state): void
189189
Logger::error('Negotiate - authenticate(): doAuthentication() exception: ' . $e->getMessage());
190190
}
191191

192-
if ($reply) {
192+
if ($reply && $auth !== null) {
193193
// success! krb TGS received
194-
/** @psalm-var \KRB5NegotiateAuth $auth */
195194
$userPrincipalName = $auth->getAuthenticatedUser();
196195
Logger::info('Negotiate - authenticate(): ' . $userPrincipalName . ' authenticated.');
197196

198197
// Search for the corresponding realm and set current variables
199198
@list($uid, $realmName) = preg_split('/@/', $userPrincipalName, 2);
200-
/** @psalm-var string $realmName */
201199
Assert::notNull($realmName);
202200

203201
// Use the correct realm
@@ -279,7 +277,7 @@ private function doAuthentication(KRB5NegotiateAuth $auth, ?string $hash = null)
279277

280278

281279
/**
282-
* @param array $spMetadata
280+
* @param array<mixed> $spMetadata
283281
* @return bool
284282
*/
285283
public function spDisabledInMetadata(array $spMetadata): bool
@@ -330,7 +328,7 @@ public function checkMask(): bool
330328
* Send the actual headers and body of the 401. Embedded in the body is a post that is triggered by JS if the client
331329
* wants to show the 401 message.
332330
*
333-
* @param array $params additional parameters to the URL in the URL in the body.
331+
* @param array<mixed> $params additional parameters to the URL in the URL in the body.
334332
*/
335333
protected function sendNegotiate(array $params): void
336334
{
@@ -351,7 +349,7 @@ protected function sendNegotiate(array $params): void
351349
/**
352350
* Passes control of the login process to a different module.
353351
*
354-
* @param array $state Information about the current authentication.
352+
* @param array<mixed> $state Information about the current authentication.
355353
*
356354
* @throws \SimpleSAML\Error\Error If couldn't determine the auth source.
357355
* @throws \SimpleSAML\Error\Exception
@@ -364,7 +362,6 @@ public static function fallBack(array &$state): void // never
364362
throw new Error\Error([500, "Unable to determine auth source."]);
365363
}
366364

367-
/** @psalm-var \SimpleSAML\Auth\Source|null $source */
368365
$source = Auth\Source::getById($authId);
369366
if ($source === null) {
370367
throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
@@ -390,13 +387,12 @@ public static function fallBack(array &$state): void // never
390387
*
391388
* @param string $uid The user identifier.
392389
*
393-
* @return array|null The attributes for the user or NULL if not found.
390+
* @return array<mixed>|null The attributes for the user or NULL if not found.
394391
*/
395392
protected function lookupUserData(string $uid): ?array
396393
{
397394
/**
398395
* @var \SimpleSAML\Module\ldap\Auth\Source\Ldap|null $source
399-
* @psalm-var string $this->backend - We only reach this method when $this->backend is set
400396
*/
401397
$source = Auth\Source::getById($this->backend);
402398
if ($source === null) {
@@ -418,7 +414,7 @@ protected function lookupUserData(string $uid): ?array
418414
* This method either logs the user out from Negotiate or passes the
419415
* logout call to the fallback module.
420416
*
421-
* @param array &$state Information about the current logout operation.
417+
* @param array<mixed> &$state Information about the current logout operation.
422418
*/
423419
public function logout(array &$state): void
424420
{
@@ -431,7 +427,6 @@ public function logout(array &$state): void
431427
$session->setData('negotiate:disable', 'session', true, 24 * 60 * 60);
432428
parent::logout($state);
433429
} else {
434-
/** @psalm-var \SimpleSAML\Module\negotiate\Auth\Source\Negotiate|null $source */
435430
$source = Auth\Source::getById($authId);
436431
if ($source === null) {
437432
throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);

tests/src/Controller/NegotiateControllerTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testEnable(): void
8181
$this->assertTrue($response->isSuccessful());
8282

8383
// Validate cookie
84-
/** @var non-empty-array $cookies */
84+
/** @var non-empty-array<mixed> $cookies */
8585
$cookies = $response->headers->getCookies();
8686
foreach ($cookies as $cookie) {
8787
if ($cookie->getName() === 'NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT') {
@@ -118,7 +118,7 @@ public function testDisable(): void
118118
$this->assertTrue($response->isSuccessful());
119119

120120
// Validate cookie
121-
/** @var non-empty-array $cookies */
121+
/** @var non-empty-array<mixed> $cookies */
122122
$cookies = $response->headers->getCookies();
123123
foreach ($cookies as $cookie) {
124124
if ($cookie->getName() === 'NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT') {
@@ -151,7 +151,8 @@ public function testRetry(): void
151151
$c = new Controller\NegotiateController($this->config, $this->session);
152152
$c->setLogger($this->logger);
153153
$c->setAuthState(new class () extends State {
154-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
154+
/** @return array<mixed> */
155+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
155156
{
156157
return [
157158
'LogoutState' => [
@@ -174,11 +175,14 @@ final public function __construct()
174175
// stub
175176
}
176177

178+
179+
/** @param array<mixed> $state */
177180
public function authenticate(array &$state): void
178181
{
179182
// stub
180183
}
181184

185+
182186
public static function getById(string $authId, ?string $type = null): ?Source
183187
{
184188
return new static();
@@ -205,7 +209,8 @@ public function testRetryInvalidMetadataThrowsException(): void
205209
$c = new Controller\NegotiateController($this->config, $this->session);
206210
$c->setLogger($this->logger);
207211
$c->setAuthState(new class () extends State {
208-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
212+
/** @return array<mixed> */
213+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
209214
{
210215
return [
211216
'LogoutState' => [
@@ -243,7 +248,8 @@ public function testRetryInvalidAuthSourceThrowsException(): void
243248
$c = new Controller\NegotiateController($this->config, $this->session);
244249
$c->setLogger($this->logger);
245250
$c->setAuthState(new class () extends State {
246-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
251+
/** @return array<mixed> */
252+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
247253
{
248254
return [
249255
'LogoutState' => [
@@ -266,6 +272,8 @@ public function __construct()
266272
// stub
267273
}
268274

275+
276+
/** @param array<mixed> $state */
269277
public function authenticate(array &$state): void
270278
{
271279
// stub
@@ -322,7 +330,8 @@ public function testBackend(): void
322330
$c = new Controller\NegotiateController($this->config, $this->session);
323331
$c->setLogger($this->logger);
324332
$c->setAuthState(new class () extends State {
325-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
333+
/** @return array<mixed> */
334+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
326335
{
327336
return [
328337
'LogoutState' => [

0 commit comments

Comments
 (0)