Skip to content

Commit f8a8eec

Browse files
committed
Replace Psalm with PHPstan
1 parent 247f6c4 commit f8a8eec

File tree

14 files changed

+104
-127
lines changed

14 files changed

+104
-127
lines changed

.github/workflows/php.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ jobs:
5151
with:
5252
# Should be the higest supported version, so we can use the newest tools
5353
php-version: '8.3'
54-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
55-
# optional performance gain for psalm: opcache
56-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, opcache, openssl, pcre, posix, spl, xml
54+
tools: composer, composer-require-checker, composer-unused, phpcs
55+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, openssl, pcre, posix, spl, xml
5756

5857
- name: Setup problem matchers for PHP
5958
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
@@ -85,27 +84,13 @@ jobs:
8584
- name: PHP Code Sniffer
8685
run: phpcs
8786

88-
- name: Psalm
89-
continue-on-error: true
90-
run: |
91-
psalm -c psalm.xml \
92-
--show-info=true \
93-
--shepherd \
94-
--php-version=${{ steps.setup-php.outputs.php-version }}
95-
96-
- name: Psalm (testsuite)
87+
- name: PHPStan
9788
run: |
98-
psalm -c psalm-dev.xml \
99-
--show-info=true \
100-
--shepherd \
101-
--php-version=${{ steps.setup-php.outputs.php-version }}
89+
vendor/bin/phpstan analyze -c phpstan.neon --debug
10290
103-
- name: Psalter
91+
- name: PHPStan (testsuite)
10492
run: |
105-
psalm --alter \
106-
--issues=UnnecessaryVarAnnotation \
107-
--dry-run \
108-
--php-version=${{ steps.setup-php.outputs.php-version }}
93+
vendor/bin/phpstan analyze -c phpstan-dev.neon --debug
10994
11095
security:
11196
name: Security checks

phpstan-baseline.neon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Call to an undefined method SimpleSAML\\\\Module\\\\ldap\\\\ConnectorInterface\\:\\:escapeFilterValue\\(\\)\\.$#"
5+
count: 1
6+
path: src/Auth/Process/AttributeAddFromLDAP.php
7+
8+
-
9+
message: "#^Call to an undefined method SimpleSAML\\\\Module\\\\ldap\\\\ConnectorInterface\\:\\:escapeFilterValue\\(\\)\\.$#"
10+
count: 1
11+
path: src/Auth/Process/AttributeAddUsersGroups.php
12+
13+
-
14+
message: "#^Call to an undefined method Symfony\\\\Component\\\\Ldap\\\\Adapter\\\\ConnectionInterface\\:\\:getResource\\(\\)\\.$#"
15+
count: 1
16+
path: src/Connector/ActiveDirectory.php
17+
18+
-
19+
message: "#^Constructor of class SimpleSAML\\\\Module\\\\ldap\\\\Connector\\\\Ldap has an unused parameter \\$extension\\.$#"
20+
count: 1
21+
path: src/Connector/Ldap.php

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 3
3+
paths:
4+
- src
5+
includes:
6+
- phpstan-baseline.neon

psalm-dev.xml

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

psalm.xml

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

src/Auth/InvalidCredentialResult.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class InvalidCredentialResult
5757
/**
5858
* Map of keys to check the code against when using is* methods
5959
*
60-
* @var array
60+
* @var array<string, array<string>>
6161
*/
6262
protected array $codeMap = [
6363
self::KEY_INVALID_CREDENTIAL => [
@@ -155,7 +155,7 @@ public function getRawMessage(): string
155155

156156
/**
157157
* Allows the default code mappings to be updated
158-
* @param array $codes
158+
* @param array<mixed> $codes
159159
* @return void
160160
*/
161161
public function updateCodeMap(array $codes): void
@@ -167,7 +167,7 @@ public function updateCodeMap(array $codes): void
167167
/**
168168
* Allows the default code mappings to be replaced
169169
*
170-
* @param array $codes
170+
* @param array<mixed> $codes
171171
* @return void
172172
*/
173173
public function replaceCodeMap(array $codes): void

src/Auth/Process/AttributeAddFromLDAP.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class AttributeAddFromLDAP extends BaseFilter
2121
/**
2222
* LDAP attributes to add to the request attributes
2323
*
24-
* @var array
24+
* @var string[]
2525
*/
2626
protected array $searchAttributes;
2727

2828
/**
2929
* LDAP attributes to base64 encode
3030
*
31-
* @var array
31+
* @var string[]
3232
*/
3333
protected array $binaryAttributes;
3434

@@ -55,7 +55,7 @@ class AttributeAddFromLDAP extends BaseFilter
5555
/**
5656
* Initialize this filter.
5757
*
58-
* @param array $config Configuration information about this filter.
58+
* @param array<mixed> $config Configuration information about this filter.
5959
* @param mixed $reserved For future use.
6060
*/
6161
public function __construct(array $config, $reserved)
@@ -83,7 +83,7 @@ public function __construct(array $config, $reserved)
8383
/**
8484
* Add attributes from an LDAP server.
8585
*
86-
* @param array &$state The current request
86+
* @param array<mixed> &$state The current request
8787
*/
8888
public function process(array &$state): void
8989
{
@@ -148,7 +148,6 @@ public function process(array &$state): void
148148
$this->binaryAttributes,
149149
);
150150
foreach ($binaries as $binary) {
151-
/** @psalm-var array $attr */
152151
$attr = $entry->getAttribute($binary);
153152
$tmp[$binary] = array_map('base64_encode', $attr);
154153
}

src/Auth/Process/AttributeAddUsersGroups.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AttributeAddUsersGroups extends BaseFilter
3333
/**
3434
* Initialize this filter.
3535
*
36-
* @param array $config Configuration information about this filter.
36+
* @param array<mixed> $config Configuration information about this filter.
3737
* @param mixed $reserved For future use.
3838
*/
3939
public function __construct(array $config, $reserved)
@@ -51,7 +51,7 @@ public function __construct(array $config, $reserved)
5151
* LDAP search filters to be added to the base filters for this authproc-filter.
5252
* It's an array of key => value pairs that will be translated to (key=value) in the ldap query.
5353
*
54-
* @var array
54+
* @var array<mixed>
5555
*/
5656
protected array $additional_filters;
5757

@@ -63,7 +63,7 @@ public function __construct(array $config, $reserved)
6363
* are then added to the request attributes.
6464
*
6565
* @throws \SimpleSAML\Error\Exception
66-
* @param array &$state
66+
* @param array<mixed> &$state
6767
*/
6868
public function process(array &$state): void
6969
{
@@ -124,8 +124,8 @@ public function process(array &$state): void
124124
* get their group membership, recursively.
125125
*
126126
* @throws \SimpleSAML\Error\Exception
127-
* @param array $attributes
128-
* @return array
127+
* @param array<mixed> $attributes
128+
* @return array<mixed>
129129
*/
130130
protected function getGroups(array $attributes): array
131131
{
@@ -291,13 +291,11 @@ protected function getGroups(array $attributes): array
291291
$groups = [];
292292
foreach ($entries as $entry) {
293293
if ($entry->hasAttribute($return_attribute)) {
294-
/** @psalm-var array $values */
295294
$values = $entry->getAttribute($return_attribute);
296295
$groups[] = array_pop($values);
297296
continue;
298297
} elseif ($entry->hasAttribute(strtolower($return_attribute))) {
299298
// Some backends return lowercase attributes
300-
/** @psalm-var array $values */
301299
$values = $entry->getAttribute(strtolower($return_attribute));
302300
$groups[] = array_pop($values);
303301
continue;
@@ -330,9 +328,9 @@ protected function getGroups(array $attributes): array
330328
* Avoids loops by only searching a DN once. Returns
331329
* the list of groups found.
332330
*
333-
* @param array $memberOf
334-
* @param array $options
335-
* @return array
331+
* @param array<mixed> $memberOf
332+
* @param array<mixed> $options
333+
* @return array<mixed>
336334
*/
337335
protected function search(array $memberOf, array $options): array
338336
{

src/Auth/Process/BaseFilter.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@
1717

1818
abstract class BaseFilter extends Auth\ProcessingFilter
1919
{
20-
// TODO: Support ldap:LDAPMulti, if possible
20+
/**
21+
* TODO: Support ldap:LDAPMulti, if possible
22+
*
23+
* @var string[]
24+
*/
2125
protected static array $ldapsources = ['ldap:Ldap', 'authX509:X509userCert'];
2226

2327
/**
2428
* List of attribute "alias's" linked to the real attribute
2529
* name. Used for abstraction / configuration of the LDAP
2630
* attribute names, which may change between dir service.
2731
*
28-
* @var array
32+
* @var array<mixed>
2933
*/
3034
protected array $attribute_map;
3135

3236
/**
3337
* The base DN of the LDAP connection. Used when searching the LDAP server.
3438
*
35-
* @var array
39+
* @var array<mixed>
3640
*/
3741
protected array $searchBase;
3842

@@ -64,7 +68,7 @@ abstract class BaseFilter extends Auth\ProcessingFilter
6468
* List of LDAP object types, used to determine the type of
6569
* object that a DN references.
6670
*
67-
* @var array
71+
* @var array<mixed>
6872
*/
6973
protected array $type_map;
7074

@@ -75,7 +79,7 @@ abstract class BaseFilter extends Auth\ProcessingFilter
7579
* instance/object and stores everything in class members.
7680
*
7781
* @throws \SimpleSAML\Error\Exception
78-
* @param array &$config
82+
* @param array<mixed> &$config
7983
* @param mixed $reserved
8084
*/
8185
public function __construct(array &$config, $reserved)
@@ -164,6 +168,7 @@ public function __construct(array &$config, $reserved)
164168
* Parse authsource config
165169
*
166170
* @param string $as The name of the authsource
171+
* @return array<mixed>
167172
*/
168173
private function parseAuthSourceConfig(string $as): array
169174
{

0 commit comments

Comments
 (0)