Skip to content

Commit 08acc5f

Browse files
committed
Replace Psalm with PHPStan
1 parent 6eeb986 commit 08acc5f

10 files changed

Lines changed: 48 additions & 107 deletions

File tree

.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
@@ -163,9 +163,8 @@ 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, psalm
167-
# optional performance gain for psalm: opcache
168-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, spl, xml
166+
tools: composer, composer-require-checker, composer-unused
167+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, spl, xml
169168

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

200-
- name: Psalm
201-
continue-on-error: true
202-
run: |
203-
psalm -c psalm.xml \
204-
--show-info=true \
205-
--shepherd \
206-
--php-version=${{ steps.setup-php.outputs.php-version }}
207-
208-
- name: Psalm (testsuite)
199+
- name: PHPStan
209200
run: |
210-
psalm -c psalm-dev.xml \
211-
--show-info=true \
212-
--shepherd \
213-
--php-version=${{ steps.setup-php.outputs.php-version }}
201+
vendor/bin/phpstan analyze -c phpstan.neon --debug
214202
215-
- name: Psalter
203+
- name: PHPStan (testsuite)
216204
run: |
217-
psalm --alter \
218-
--issues=UnnecessaryVarAnnotation \
219-
--dry-run \
220-
--php-version=${{ steps.setup-php.outputs.php-version }}
205+
vendor/bin/phpstan analyze -c phpstan-dev.neon --debug
221206
222207
security:
223208
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: 5
3+
paths:
4+
- src

psalm-dev.xml

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

psalm.xml

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

src/ARP.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ class ARP
2626
* Constructor
2727
*
2828
* @param array $metadata
29-
* @param string $attributemap_filename
29+
* @param string|null $attributemap_filename
3030
* @param string $prefix
3131
* @param string $suffix
3232
*/
33-
public function __construct(array $metadata, string $attributemap_filename, string $prefix, string $suffix)
34-
{
33+
public function __construct(
34+
array $metadata,
35+
?string $attributemap_filename = null,
36+
?string $prefix = '',
37+
?string $suffix = '',
38+
) {
3539
$this->metadata = $metadata;
3640
$this->prefix = $prefix;
3741
$this->suffix = $suffix;
@@ -50,11 +54,10 @@ private function loadAttributeMap(string $attributemap_filename): void
5054
{
5155
$config = \SimpleSAML\Configuration::getInstance();
5256

53-
/** @psalm-suppress PossiblyNullOperand */
5457
include($config->getPathValue('attributemap', 'attributemap/') . $attributemap_filename . '.php');
5558

5659
// Note that $attributemap is defined in the included attributemap-file!
57-
/** @psalm-var array $attributemap */
60+
// @phpstan-ignore variable.undefined
5861
$this->attributes = $attributemap;
5962
}
6063

src/MetaLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function loadSource(array $source): void
107107
$context = $this->createContext($source);
108108

109109
$httpUtils = new Utils\HTTP();
110+
$data = null;
110111
// GET!
111112
try {
112113
/** @var array $response We know this because we set the third parameter to `true` */
@@ -198,7 +199,7 @@ public function loadSource(array $source): void
198199
if (count($attributeAuthorities) && !empty($attributeAuthorities[0])) {
199200
$this->addMetadata(
200201
$source['src'],
201-
$attributeAuthorities[0],
202+
$attributeAuthorities,
202203
'attributeauthority-remote',
203204
$template,
204205
);

tests/src/Controller/MetaRefreshTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function requireAdmin(): void
8686

8787
/**
8888
*/
89-
public function testMetaRefresh()
89+
public function testMetaRefresh(): void
9090
{
9191
$_SERVER['REQUEST_URI'] = '/module.php/metarefresh/';
9292
$_SERVER['REQUEST_METHOD'] = 'GET';

tests/src/MetaLoaderTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
use Exception;
88
use PHPUnit\Framework\TestCase;
99
use SimpleSAML\Configuration;
10+
use SimpleSAML\Module\metarefresh\MetaLoader;
1011

1112
final class MetaLoaderTest extends TestCase
1213
{
1314
/** \SimpleSAML\Module\metarefresh\MetaLoader */
14-
private $metaloader;
15+
private MetaLoader $metaloader;
1516

1617
/** @var \SimpleSAML\Configuration */
17-
private $config;
18+
private Configuration $config;
1819

1920
/** @var string */
2021
private $tmpdir;
2122

22-
/** @var array */
23+
/** @var array<mixed> */
2324
private $source = [
2425
'outputFormat' => 'flatfile',
2526
'conditionalGET' => false,
@@ -30,7 +31,7 @@ final class MetaLoaderTest extends TestCase
3031
],
3132
];
3233

33-
/** @var array */
34+
/** @var array<mixed> */
3435
private $expected = [
3536
'entityid' => 'https://idp.example.com/idp/shibboleth',
3637
'description' => ['en' => 'OrganizationName',],
@@ -110,9 +111,12 @@ public function testMetaLoader(): void
110111
} catch (Exception $e) {
111112
$this->fail('Metarefresh does not produce syntactially valid code');
112113
}
114+
115+
// @phpstan-ignore variable.undefined
113116
$this->assertArrayHasKey('https://idp.example.com/idp/shibboleth', $metadata);
114117

115118
$this->assertTrue(
119+
// @phpstan-ignore variable.undefined
116120
empty(array_diff_key($this->expected, $metadata['https://idp.example.com/idp/shibboleth'])),
117121
);
118122
}
@@ -135,12 +139,12 @@ public function testWriteMetadataFiles(): void
135139
$this->metaloader->writeMetadataFiles($this->tmpdir);
136140
$this->assertFileExists($this->tmpdir . '/saml20-idp-remote.php');
137141

138-
/** @psalm-suppress UnresolvableInclude */
139142
@include_once($this->tmpdir . '/saml20-idp-remote.php');
140-
/** @psalm-suppress UndefinedVariable */
143+
144+
// @phpstan-ignore variable.undefined
141145
$this->assertArrayHasKey('https://idp.example.com/idp/shibboleth', $metadata);
142146
$this->assertTrue(
143-
/** @psalm-suppress UndefinedVariable */
147+
// @phpstan-ignore variable.undefined
144148
empty(array_diff_key($this->expected, $metadata['https://idp.example.com/idp/shibboleth'])),
145149
);
146150
}
@@ -162,8 +166,12 @@ public function testMetaLoaderSetExpiryWhenNotPresent(): void
162166
} catch (Exception $e) {
163167
$this->fail('Metarefresh does not produce syntactially valid code');
164168
}
169+
170+
// @phpstan-ignore variable.undefined
165171
$this->assertArrayHasKey('https://idp.example.com/idp/shibboleth', $metadata);
172+
// @phpstan-ignore variable.undefined
166173
$this->assertArrayHasKey('expire', $metadata['https://idp.example.com/idp/shibboleth']);
174+
// @phpstan-ignore variable.undefined
167175
$this->assertEquals(1000, $metadata['https://idp.example.com/idp/shibboleth']['expire']);
168176
}
169177

@@ -194,9 +202,11 @@ public function testAttributewhitelist1(): void
194202
$this->fail('Metarefresh does not produce syntactially valid code');
195203
}
196204
/* Check we matched the IdP */
205+
// @phpstan-ignore variable.undefined
197206
$this->assertArrayHasKey('https://idp.example.com/idp/shibboleth', $metadata);
198207

199208
$this->assertTrue(
209+
// @phpstan-ignore variable.undefined
200210
empty(array_diff_key($this->expected, $metadata['https://idp.example.com/idp/shibboleth'])),
201211
);
202212
}
@@ -263,9 +273,11 @@ public function testAttributewhitelist3(): void
263273
}
264274

265275
/* Check we matched the IdP */
276+
// @phpstan-ignore variable.undefined
266277
$this->assertArrayHasKey('https://idp.example.com/idp/shibboleth', $metadata);
267278

268279
$this->assertTrue(
280+
// @phpstan-ignore variable.undefined
269281
empty(array_diff_key($this->expected, $metadata['https://idp.example.com/idp/shibboleth'])),
270282
);
271283
}

0 commit comments

Comments
 (0)