Skip to content

Commit c3f78a8

Browse files
committed
Migrate psalm to phpstan
1 parent 001b4bc commit c3f78a8

8 files changed

Lines changed: 54 additions & 98 deletions

File tree

.github/workflows/php.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
with:
164164
# Should be the higest supported version, so we can use the newest tools
165165
php-version: '8.5'
166-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
166+
tools: composer, composer-require-checker, composer-unused
167167
# optional performance gain for psalm: opcache
168168
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, posix,\
169169
session, sodium, spl, xml
@@ -196,29 +196,15 @@ jobs:
196196
run: composer-unused
197197

198198
- name: PHP Code Sniffer
199-
run: phpcs
199+
run: vendor/bin/phpcs
200200

201-
- name: Psalm
202-
continue-on-error: true
201+
- name: PHPStan
203202
run: |
204-
psalm -c psalm.xml \
205-
--show-info=true \
206-
--shepherd \
207-
--php-version=${{ steps.setup-php.outputs.php-version }}
203+
vendor/bin/phpstan analyze -c phpstan.neon
208204
209-
- name: Psalm (testsuite)
205+
- name: PHPStan (testsuite)
210206
run: |
211-
psalm -c psalm-dev.xml \
212-
--show-info=true \
213-
--shepherd \
214-
--php-version=${{ steps.setup-php.outputs.php-version }}
215-
216-
- name: Psalter
217-
run: |
218-
psalm --alter \
219-
--issues=UnnecessaryVarAnnotation \
220-
--dry-run \
221-
--php-version=${{ steps.setup-php.outputs.php-version }}
207+
vendor/bin/phpstan analyze -c phpstan-dev.neon
222208
223209
security:
224210
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 & 30 deletions
This file was deleted.

src/Auth/Process/ExpiryDate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ExpiryDate extends Auth\ProcessingFilter
6565
/**
6666
* Initialize this filter.
6767
*
68-
* @param array &$config Configuration information about this filter.
68+
* @param array<mixed> &$config Configuration information about this filter.
6969
* @param mixed $reserved For future use.
7070
*/
7171
public function __construct(array &$config, $reserved)
@@ -123,7 +123,7 @@ public function __construct(array &$config, $reserved)
123123
/**
124124
* Show expirational warning if remaining days is equal or under defined $warndaysbefore
125125
*
126-
* @param array &$state
126+
* @param array<mixed> &$state
127127
* @param int $expireOnDate
128128
* @param int $warndaysbefore
129129
* @return bool
@@ -158,7 +158,7 @@ public function checkDate(int $expireOnDate): bool
158158
/**
159159
* Apply filter
160160
*
161-
* @param array &$state The current state.
161+
* @param array<mixed> &$state The current state.
162162
*/
163163
public function process(array &$state): void
164164
{

tests/src/Auth/Process/ExpiryDateTest.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
final class ExpiryDateTest extends TestCase
1313
{
14-
/** @var array valid configuration */
15-
private static $config = [
14+
/** @var array<mixed> $config valid configuration */
15+
private static array $config = [
1616
'class' => 'expirycheck:ExpiryDate',
1717
'netid_attr' => 'userPrincipalName',
1818
'expirydate_attr' => 'accountExpires',
@@ -21,8 +21,13 @@ final class ExpiryDateTest extends TestCase
2121
'date_format' => 'd.m.Y', # php date syntax
2222
];
2323

24-
/** @var array minimal request */
25-
private static $minRequest = [
24+
/**
25+
* The phpstan-ignore is necessary as long as we can't run testProcessNoExpiry
26+
*
27+
* @var array<mixed> $minRequest minimal request
28+
* @phpstan-ignore property.onlyWritten
29+
*/
30+
private static array $minRequest = [
2631
'Source' => [
2732
'entityid' => 'https://localhost/sp',
2833
],
@@ -40,8 +45,8 @@ public function testInvalidWarndaysbefore(): void
4045
$this->expectException(Error\Exception::class);
4146
$this->expectExceptionMessage("Invalid value for number of days given to expirycheck::ExpiryDate filter.");
4247
$filter = new ExpiryDate($config, null);
43-
self::fail();
4448
$filter->checkDate(1);
49+
self::fail();
4550
}
4651

4752
/**
@@ -53,8 +58,8 @@ public function testInvalidNetidAttr(): void
5358
$msg = "Invalid attribute name given as eduPersonPrincipalName to expirycheck::ExpiryDate filter.";
5459
$this->expectExceptionMessage($msg);
5560
$filter = new ExpiryDate($config, null);
56-
self::fail();
5761
$filter->checkDate(1);
62+
self::fail();
5863
}
5964

6065
/**
@@ -66,8 +71,8 @@ public function testInvalidExpirydateAttr(): void
6671
$msg = "Invalid attribute name given as schacExpiryDate to expirycheck::ExpiryDate filter.";
6772
$this->expectExceptionMessage($msg);
6873
$filter = new ExpiryDate($config, null);
69-
self::fail();
7074
$filter->checkDate(1);
75+
self::fail();
7176
}
7277

7378
/**
@@ -79,8 +84,8 @@ public function testInvalidDateFormat(): void
7984
$msg = "Invalid date format given to expirycheck::ExpiryDate filter.";
8085
$this->expectExceptionMessage($msg);
8186
$filter = new ExpiryDate($config, null);
82-
self::fail();
8387
$filter->checkDate(1);
88+
self::fail();
8489
}
8590

8691
/**
@@ -92,8 +97,8 @@ public function testInvalidConvertToUnixtime(): void
9297
$msg = "Invalid value for convert_expirydate_to_unixtime given to expirycheck::ExpiryDate filter.";
9398
$this->expectExceptionMessage($msg);
9499
$filter = new ExpiryDate($config, null);
95-
self::fail();
96100
$filter->checkDate(1);
101+
self::fail();
97102
}
98103

99104
/**
@@ -182,16 +187,16 @@ public function testProcessNoExpiry(): void
182187
{
183188
$skipReason = 'https://github.com/simplesamlphp/simplesamlphp-test-framework/issues/3#issuecomment-1836154792';
184189
$this->markTestSkipped($skipReason);
185-
$filter = new ExpiryDate(self::$config, null);
186-
$initialState = ["Attributes" =>
187-
[
188-
'userPrincipalName' => ['test'],
189-
'accountExpires' => ['20231228112510Z'],
190-
],
191-
];
192-
$request = array_merge(self::$minRequest, $initialState);
193-
$state = $initialState;
194-
$filter->process($request);
195-
self::assertEquals($initialState, $state);
190+
// $filter = new ExpiryDate(self::$config, null);
191+
// $initialState = ["Attributes" =>
192+
// [
193+
// 'userPrincipalName' => ['test'],
194+
// 'accountExpires' => ['20231228112510Z'],
195+
// ],
196+
// ];
197+
// $request = array_merge(self::$minRequest, $initialState);
198+
// $state = $initialState;
199+
// $filter->process($request);
200+
// self::assertEquals($initialState, $state);
196201
}
197202
}

tests/src/Controller/ExpiryCheckTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ public function testMissingSourceId(string $endpoint): void
6767
$c = new Controller\ExpiryCheck($this->config, $this->session);
6868

6969
$this->expectException(Error\BadRequest::class);
70-
$this->expectExceptionMessage("BADREQUEST('%REASON%' => 'Missing required StateId query parameter.')");
71-
call_user_func([$c, $endpoint], $request);
70+
$this->expectExceptionMessage('{"errorCode":"BADREQUEST","%REASON%":"Missing required StateId query parameter."}');
71+
72+
/** @var callable $callable */
73+
$callable = [$c, $endpoint];
74+
call_user_func($callable, $request);
7275
}
7376

7477

7578
/**
76-
* @return array
79+
* @return array<mixed>
7780
*/
7881
public static function endpoints(): array
7982
{
@@ -99,15 +102,15 @@ public function testExpired(): void
99102

100103
$c = new Controller\ExpiryCheck($this->config, $this->session);
101104
$c->setAuthState(new class () extends Auth\State {
102-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
105+
/** @return array<mixed> */
106+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
103107
{
104108
return ['expireOnDate' => 'someDate', 'netId' => 'someId'];
105109
}
106110
});
107111
$response = $c->expired($request);
108112

109113
self::assertTrue($response->isSuccessful());
110-
self::assertInstanceOf(Template::class, $response);
111114
}
112115

113116

@@ -126,7 +129,8 @@ public function testAboutToExpire(): void
126129

127130
$c = new Controller\ExpiryCheck($this->config, $this->session);
128131
$c->setAuthState(new class () extends Auth\State {
129-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
132+
/** @return array<mixed> */
133+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
130134
{
131135
return ['daysleft' => 10, 'expireOnDate' => 'someDate', 'netId' => 'someId'];
132136
}
@@ -153,7 +157,8 @@ public function testAboutToExpireYes(): void
153157

154158
$c = new Controller\ExpiryCheck($this->config, $this->session);
155159
$c->setAuthState(new class () extends Auth\State {
156-
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
160+
/** @return array<mixed> */
161+
public static function loadState(string $id, string $stage, bool $allowMissing = false): array
157162
{
158163
return [];
159164
}

0 commit comments

Comments
 (0)