Skip to content

Commit 0fab37a

Browse files
committed
Replace Psalm with PHPstan
1 parent b969760 commit 0fab37a

File tree

12 files changed

+78
-121
lines changed

12 files changed

+78
-121
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-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 & 27 deletions
This file was deleted.

psalm.xml

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

src/Auth/Process/AttributeAddFromLDAP.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ 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

3535
/**
3636
* LDAP search filter to use in the LDAP query
3737
*
38-
* @var string
38+
* @var string[]
3939
*/
4040
protected string $searchFilter;
4141

@@ -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
{

src/Auth/Process/AttributeAddUsersGroups.php

Lines changed: 7 additions & 7 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
{
@@ -330,8 +330,8 @@ protected function getGroups(array $attributes): array
330330
* Avoids loops by only searching a DN once. Returns
331331
* the list of groups found.
332332
*
333-
* @param array $memberOf
334-
* @param array $options
333+
* @param array<mixed> $memberOf
334+
* @param array<mixed> $options
335335
* @return array
336336
*/
337337
protected function search(array $memberOf, array $options): array

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
{

src/Auth/Source/Ldap.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Ldap extends UserPassBase
4949
/**
5050
* Constructor for this authentication source.
5151
*
52-
* @param array $info Information about this authentication source.
53-
* @param array $config Configuration.
52+
* @param array<mixed> $info Information about this authentication source.
53+
* @param array<mixed> $config Configuration.
5454
*/
5555
public function __construct(array $info, array $config)
5656
{
@@ -71,11 +71,15 @@ public function __construct(array $info, array $config)
7171
*
7272
* @param string $username The username the user wrote.
7373
* @param string $password The password the user wrote.
74-
* @param array|null $sasl_args SASL options
75-
* @return array Associative array with the users attributes.
74+
* @param array<mixed> $sasl_args SASL options
75+
* @return array<mixed> Associative array with the users attributes.
7676
*/
77-
protected function loginSasl(string $username, #[\SensitiveParameter]string $password, array $sasl_args = []): array
78-
{
77+
protected function loginSasl(
78+
string $username,
79+
#[\SensitiveParameter]
80+
string $password,
81+
array $sasl_args = [],
82+
): array {
7983
if (preg_match('/^\s*$/', $password)) {
8084
// The empty string is considered an anonymous bind to Symfony
8185
throw new Error\Error('WRONGUSERPASS');
@@ -110,7 +114,7 @@ protected function loginSasl(string $username, #[\SensitiveParameter]string $pas
110114
Assert::nullOrNotWhitespaceOnly($searchUsername);
111115

112116
$searchPassword = $this->ldapConfig->getOptionalString('search.password', null);
113-
Assert::nullOrnotWhitespaceOnly($searchPassword);
117+
Assert::nullOrNotWhitespaceOnly($searchPassword);
114118

115119
try {
116120
$this->connector->bind($searchUsername, $searchPassword);
@@ -164,7 +168,7 @@ protected function loginSasl(string $username, #[\SensitiveParameter]string $pas
164168
*
165169
* @param string $username The username the user wrote.
166170
* @param string $password The password the user wrote.
167-
* @return array Associative array with the users attributes.
171+
* @return array<mixed> Associative array with the users attributes.
168172
*/
169173
protected function login(string $username, #[\SensitiveParameter]string $password): array
170174
{
@@ -176,15 +180,15 @@ protected function login(string $username, #[\SensitiveParameter]string $passwor
176180
* Attempt to find a user's attributes given its username.
177181
*
178182
* @param string $username The username who's attributes we want.
179-
* @return array Associative array with the users attributes.
183+
* @return array<mixed> Associative array with the users attributes.
180184
*/
181185
public function getAttributes(string $username): array
182186
{
183187
$searchUsername = $this->ldapConfig->getOptionalString('search.username', null);
184188
Assert::nullOrNotWhitespaceOnly($searchUsername);
185189

186190
$searchPassword = $this->ldapConfig->getOptionalString('search.password', null);
187-
Assert::nullOrnotWhitespaceOnly($searchPassword);
191+
Assert::nullOrNotWhitespaceOnly($searchPassword);
188192

189193
try {
190194
$this->connector->bind($searchUsername, $searchPassword);
@@ -232,7 +236,7 @@ public function getAttributes(string $username): array
232236

233237
/**
234238
* @param \Symfony\Component\Ldap\Entry $entry
235-
* @return array
239+
* @return array<mixed>
236240
*/
237241
private function processAttributes(Entry $entry): array
238242
{

0 commit comments

Comments
 (0)